Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,31 +1,24 @@
|
|
1 |
import gradio as gr
|
2 |
-
from product_recommender import
|
3 |
-
import
|
4 |
|
5 |
-
def get_recommendations(text: str) -> dict:
|
6 |
try:
|
7 |
-
recommender =
|
8 |
-
|
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(
|
|
|
|
|
|
|
26 |
outputs=gr.JSON(),
|
27 |
title="π Smart Gift Recommender",
|
28 |
-
description="Get personalized gift suggestions with
|
29 |
)
|
30 |
|
31 |
if __name__ == "__main__":
|
|
|
1 |
import gradio as gr
|
2 |
+
from product_recommender import DynamicRecommender
|
3 |
+
import asyncio
|
4 |
|
5 |
+
async def get_recommendations(text: str) -> dict:
|
6 |
try:
|
7 |
+
recommender = DynamicRecommender()
|
8 |
+
recommendations = await recommender.get_recommendations(text)
|
9 |
+
return {"recommendations": recommendations}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
except Exception as e:
|
11 |
return {"error": str(e)}
|
12 |
|
13 |
demo = gr.Interface(
|
14 |
+
fn=lambda x: asyncio.run(get_recommendations(x)),
|
15 |
+
inputs=gr.Textbox(
|
16 |
+
lines=3,
|
17 |
+
placeholder="Describe who you're buying a gift for (age, interests, etc.)"
|
18 |
+
),
|
19 |
outputs=gr.JSON(),
|
20 |
title="π Smart Gift Recommender",
|
21 |
+
description="Get personalized gift suggestions with real-time price comparison!"
|
22 |
)
|
23 |
|
24 |
if __name__ == "__main__":
|