File size: 1,579 Bytes
aeeed0b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import gradio as gr
import requests
from transformers import pipeline

# Load NLP model (lighter model for efficiency)
zero_shot = pipeline("zero-shot-classification", model="facebook/bart-large-mnli")

# 🎁 Web search for gift suggestions
def search_gifts(query):
    amazon_url = f"[Amazon](https://www.amazon.in/s?k={query.replace(' ', '+')})"
    igp_url = f"[IGP](https://www.igp.com/search?q={query.replace(' ', '+')})"
    indiamart_url = f"[IndiaMart](https://dir.indiamart.com/search.mp?ss={query.replace(' ', '+')})"

    return f"πŸ”— **Amazon**: {amazon_url}\nπŸ”— **IGP**: {igp_url}\nπŸ”— **IndiaMart**: {indiamart_url}"

# 🎯 Main function for gift recommendation
def recommend_gifts(text):
    if not text:
        return "Please enter a description."

    # NLP Processing
    categories = ["art", "music", "tech", "travel", "books", "fashion", "fitness", "gaming"]
    results = zero_shot(text, categories)

    # Get top interest
    top_interest = results["labels"][0]

    # Get gift links
    links = search_gifts(top_interest)

    return f"🎯 **Predicted Interest**: `{top_interest}`\n\nπŸ›’ **Gift Suggestions:**\n{links}"

# 🎨 Gradio UI for better display
demo = gr.Interface(
    fn=recommend_gifts, 
    inputs="text", 
    outputs="markdown",  # πŸ”Ή Changes output format to Markdown for better UI
    title="🎁 AI Gift Recommender",
    description="Enter details about the person you are buying a gift for, and get personalized suggestions with shopping links!",
)

# πŸš€ Launch Gradio App
if __name__ == "__main__":
    demo.launch()