noddysnots commited on
Commit
aeeed0b
Β·
verified Β·
1 Parent(s): 14be50e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -47
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 {"Amazon": amazon_url, "IGP": igp_url, "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
- # Search for gifts based on interest
29
- links = search_gifts(top_interest)
30
-
31
- return {
32
- "Predicted Interest": top_interest,
33
- "Gift Suggestions": links
34
- }
35
-
36
- # 🎨 Gradio UI for easy interaction
37
- demo = gr.Interface(
38
- fn=recommend_gifts,
39
- inputs="text",
40
- outputs="json",
41
- title="🎁 AI Gift Recommender",
42
- description="Enter details about the person you are buying a gift for, and get personalized suggestions with shopping links!",
43
- )
44
-
45
- # πŸš€ Launch Gradio App
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
+