Spaces:
Running
Running
File size: 1,044 Bytes
d47196a 34e5294 1e69485 34e5294 d47196a 34e5294 ad1f2d9 34e5294 d47196a e7b9fde d47196a 34e5294 d47196a 34e5294 d47196a a205c3f d47196a |
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 |
import gradio as gr
from product_recommender import ProductRecommender
import urllib.parse
def get_recommendations(text: str) -> dict:
try:
recommender = ProductRecommender()
recs = recommender.get_recommendations(text, [])
# Add shopping links
for rec in recs:
query = urllib.parse.quote(rec['name'])
rec['links'] = {
"Amazon": f"https://www.amazon.in/s?k={query}",
"Flipkart": f"https://www.flipkart.com/search?q={query}",
"IGP": f"https://www.igp.com/search?q={query}"
}
return {"recommendations": recs}
except Exception as e:
return {"error": str(e)}
demo = gr.Interface(
fn=get_recommendations,
inputs=gr.Textbox(lines=3),
outputs=gr.JSON(),
title="π Smart Gift Recommender",
description="Get personalized gift suggestions with shopping links!"
)
if __name__ == "__main__":
demo.launch(server_name="0.0.0.0", server_port=7860)
else:
app = demo.app |