Spaces:
Sleeping
Sleeping
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 |