|
import gradio as gr |
|
import requests |
|
from transformers import pipeline |
|
|
|
|
|
zero_shot = pipeline("zero-shot-classification", model="facebook/bart-large-mnli") |
|
|
|
|
|
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}" |
|
|
|
|
|
def recommend_gifts(text): |
|
if not text: |
|
return "Please enter a description." |
|
|
|
|
|
categories = ["art", "music", "tech", "travel", "books", "fashion", "fitness", "gaming"] |
|
results = zero_shot(text, categories) |
|
|
|
|
|
top_interest = results["labels"][0] |
|
|
|
|
|
links = search_gifts(top_interest) |
|
|
|
return f"π― **Predicted Interest**: `{top_interest}`\n\nπ **Gift Suggestions:**\n{links}" |
|
|
|
|
|
demo = gr.Interface( |
|
fn=recommend_gifts, |
|
inputs="text", |
|
outputs="markdown", |
|
title="π AI Gift Recommender", |
|
description="Enter details about the person you are buying a gift for, and get personalized suggestions with shopping links!", |
|
) |
|
|
|
|
|
if __name__ == "__main__": |
|
demo.launch() |
|
|
|
|