Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,25 +1,31 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from product_recommender import ProductRecommender
|
|
|
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
def get_gift_recommendations(text: str) -> dict:
|
| 7 |
try:
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
-
return {
|
| 11 |
-
"recommendations": recommendations,
|
| 12 |
-
"status": "success"
|
| 13 |
-
}
|
| 14 |
except Exception as e:
|
| 15 |
return {"error": str(e)}
|
| 16 |
|
| 17 |
demo = gr.Interface(
|
| 18 |
-
fn=
|
| 19 |
inputs=gr.Textbox(lines=3),
|
| 20 |
outputs=gr.JSON(),
|
| 21 |
title="π Smart Gift Recommender",
|
| 22 |
-
description="Get personalized gift suggestions!"
|
| 23 |
)
|
| 24 |
|
| 25 |
if __name__ == "__main__":
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from product_recommender import ProductRecommender
|
| 3 |
+
import urllib.parse
|
| 4 |
|
| 5 |
+
def get_recommendations(text: str) -> dict:
|
|
|
|
|
|
|
| 6 |
try:
|
| 7 |
+
recommender = ProductRecommender()
|
| 8 |
+
recs = recommender.get_recommendations(text, [])
|
| 9 |
+
|
| 10 |
+
# Add shopping links
|
| 11 |
+
for rec in recs:
|
| 12 |
+
query = urllib.parse.quote(rec['name'])
|
| 13 |
+
rec['links'] = {
|
| 14 |
+
"Amazon": f"https://www.amazon.in/s?k={query}",
|
| 15 |
+
"Flipkart": f"https://www.flipkart.com/search?q={query}",
|
| 16 |
+
"IGP": f"https://www.igp.com/search?q={query}"
|
| 17 |
+
}
|
| 18 |
|
| 19 |
+
return {"recommendations": recs}
|
|
|
|
|
|
|
|
|
|
| 20 |
except Exception as e:
|
| 21 |
return {"error": str(e)}
|
| 22 |
|
| 23 |
demo = gr.Interface(
|
| 24 |
+
fn=get_recommendations,
|
| 25 |
inputs=gr.Textbox(lines=3),
|
| 26 |
outputs=gr.JSON(),
|
| 27 |
title="π Smart Gift Recommender",
|
| 28 |
+
description="Get personalized gift suggestions with shopping links!"
|
| 29 |
)
|
| 30 |
|
| 31 |
if __name__ == "__main__":
|