Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,47 +1,45 @@
|
|
1 |
-
import gradio as gr
|
2 |
-
import requests
|
3 |
-
from transformers import pipeline
|
4 |
-
|
5 |
-
# Load NLP model
|
6 |
-
zero_shot = pipeline("zero-shot-classification", model="facebook/bart-large-mnli")
|
7 |
-
|
8 |
-
# π Web search for gift suggestions
|
9 |
-
def search_gifts(query):
|
10 |
-
amazon_url = f"https://www.amazon.in/s?k={query.replace(' ', '+')}"
|
11 |
-
igp_url = f"https://www.igp.com/search?q={query.replace(' ', '+')}"
|
12 |
-
indiamart_url = f"https://dir.indiamart.com/search.mp?ss={query.replace(' ', '+')}"
|
13 |
-
|
14 |
-
return
|
15 |
-
|
16 |
-
# π― Main function for gift recommendation
|
17 |
-
def recommend_gifts(text):
|
18 |
-
if not text:
|
19 |
-
return "Please enter a description."
|
20 |
-
|
21 |
-
# NLP Processing
|
22 |
-
categories = ["art", "music", "tech", "travel", "books", "fashion", "fitness", "gaming"]
|
23 |
-
results = zero_shot(text, categories)
|
24 |
-
|
25 |
-
# Get top interest
|
26 |
-
top_interest = results["labels"][0]
|
27 |
-
|
28 |
-
#
|
29 |
-
links = search_gifts(top_interest)
|
30 |
-
|
31 |
-
return {
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
if __name__ == "__main__":
|
47 |
-
demo.launch()
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import requests
|
3 |
+
from transformers import pipeline
|
4 |
+
|
5 |
+
# Load NLP model (lighter model for efficiency)
|
6 |
+
zero_shot = pipeline("zero-shot-classification", model="facebook/bart-large-mnli")
|
7 |
+
|
8 |
+
# π Web search for gift suggestions
|
9 |
+
def search_gifts(query):
|
10 |
+
amazon_url = f"[Amazon](https://www.amazon.in/s?k={query.replace(' ', '+')})"
|
11 |
+
igp_url = f"[IGP](https://www.igp.com/search?q={query.replace(' ', '+')})"
|
12 |
+
indiamart_url = f"[IndiaMart](https://dir.indiamart.com/search.mp?ss={query.replace(' ', '+')})"
|
13 |
+
|
14 |
+
return f"π **Amazon**: {amazon_url}\nπ **IGP**: {igp_url}\nπ **IndiaMart**: {indiamart_url}"
|
15 |
+
|
16 |
+
# π― Main function for gift recommendation
|
17 |
+
def recommend_gifts(text):
|
18 |
+
if not text:
|
19 |
+
return "Please enter a description."
|
20 |
+
|
21 |
+
# NLP Processing
|
22 |
+
categories = ["art", "music", "tech", "travel", "books", "fashion", "fitness", "gaming"]
|
23 |
+
results = zero_shot(text, categories)
|
24 |
+
|
25 |
+
# Get top interest
|
26 |
+
top_interest = results["labels"][0]
|
27 |
+
|
28 |
+
# Get gift links
|
29 |
+
links = search_gifts(top_interest)
|
30 |
+
|
31 |
+
return f"π― **Predicted Interest**: `{top_interest}`\n\nπ **Gift Suggestions:**\n{links}"
|
32 |
+
|
33 |
+
# π¨ Gradio UI for better display
|
34 |
+
demo = gr.Interface(
|
35 |
+
fn=recommend_gifts,
|
36 |
+
inputs="text",
|
37 |
+
outputs="markdown", # πΉ Changes output format to Markdown for better UI
|
38 |
+
title="π AI Gift Recommender",
|
39 |
+
description="Enter details about the person you are buying a gift for, and get personalized suggestions with shopping links!",
|
40 |
+
)
|
41 |
+
|
42 |
+
# π Launch Gradio App
|
43 |
+
if __name__ == "__main__":
|
44 |
+
demo.launch()
|
45 |
+
|
|
|
|