Spaces:
Sleeping
Sleeping
Commit ·
dad1ac8
1
Parent(s): ae20115
Fix: Update Gradio 6.x API endpoint configuration
Browse files- app.py +28 -40
- requirements.txt +2 -1
app.py
CHANGED
|
@@ -27,50 +27,38 @@ def recommend_outfit_api(clothes_json: str, preference: str, city: str = "Tunis"
|
|
| 27 |
except Exception as e:
|
| 28 |
return json.dumps({"success": False, "error": str(e)})
|
| 29 |
|
| 30 |
-
# ✅ Interface Gradio
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
with gr.Column():
|
| 52 |
-
output = gr.Textbox(label="Recommended Outfit (JSON)", lines=15)
|
| 53 |
-
|
| 54 |
-
# ✅ Exemples
|
| 55 |
-
gr.Examples(
|
| 56 |
-
examples=[[
|
| 57 |
'[{"id":"top1","category":"top","style":"casual","color":"white","season":"summer","score":0.8,"imageURL":"https://example.com/top.jpg"},{"id":"bot1","category":"bottom","style":"casual","color":"blue","season":"summer","score":0.7,"imageURL":"https://example.com/bottom.jpg"},{"id":"shoe1","category":"footwear","style":"casual","color":"black","season":"summer","score":0.9,"imageURL":"https://example.com/shoes.jpg"}]',
|
| 58 |
"casual",
|
| 59 |
"Tunis"
|
| 60 |
-
]
|
| 61 |
-
|
| 62 |
-
)
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
submit_btn.click(
|
| 66 |
-
fn=recommend_outfit_api,
|
| 67 |
-
inputs=[clothes_input, preference_input, city_input],
|
| 68 |
-
outputs=output,
|
| 69 |
-
api_name="predict" # ✅ CRUCIAL : Expose l'endpoint /api/predict
|
| 70 |
-
)
|
| 71 |
|
| 72 |
-
if
|
| 73 |
-
|
| 74 |
server_name="0.0.0.0",
|
| 75 |
server_port=7860,
|
| 76 |
share=False
|
|
|
|
| 27 |
except Exception as e:
|
| 28 |
return json.dumps({"success": False, "error": str(e)})
|
| 29 |
|
| 30 |
+
# ✅ Interface Gradio - gr.Interface est plus fiable pour l'API
|
| 31 |
+
iface = gr.Interface(
|
| 32 |
+
fn=recommend_outfit_api,
|
| 33 |
+
inputs=[
|
| 34 |
+
gr.Textbox(
|
| 35 |
+
label="Clothes Data (JSON)",
|
| 36 |
+
placeholder='[{"id":"top1","category":"top","style":"casual",...}]',
|
| 37 |
+
lines=10
|
| 38 |
+
),
|
| 39 |
+
gr.Dropdown(
|
| 40 |
+
choices=["casual", "formal", "sport", "chic"],
|
| 41 |
+
label="Preference",
|
| 42 |
+
value="casual"
|
| 43 |
+
),
|
| 44 |
+
gr.Textbox(label="City", value="Tunis")
|
| 45 |
+
],
|
| 46 |
+
outputs=gr.Textbox(label="Recommended Outfit (JSON)", lines=15),
|
| 47 |
+
title="🎽 Labasni Outfit Recommender",
|
| 48 |
+
description="Recommandations d'outfits basées sur ML (TensorFlow + PyTorch)",
|
| 49 |
+
examples=[
|
| 50 |
+
[
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
'[{"id":"top1","category":"top","style":"casual","color":"white","season":"summer","score":0.8,"imageURL":"https://example.com/top.jpg"},{"id":"bot1","category":"bottom","style":"casual","color":"blue","season":"summer","score":0.7,"imageURL":"https://example.com/bottom.jpg"},{"id":"shoe1","category":"footwear","style":"casual","color":"black","season":"summer","score":0.9,"imageURL":"https://example.com/shoes.jpg"}]',
|
| 52 |
"casual",
|
| 53 |
"Tunis"
|
| 54 |
+
]
|
| 55 |
+
],
|
| 56 |
+
# ✅ Pour Gradio 6.x, l'endpoint standard est /run/predict (pas besoin d'api_name)
|
| 57 |
+
# L'API est automatiquement exposée via /run/predict
|
| 58 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
|
| 60 |
+
if _name_ == "_main_":
|
| 61 |
+
iface.launch(
|
| 62 |
server_name="0.0.0.0",
|
| 63 |
server_port=7860,
|
| 64 |
share=False
|
requirements.txt
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
gradio==6.1.0
|
| 2 |
numpy==1.24.3
|
| 3 |
scikit-learn==1.3.0
|
| 4 |
-
requests==2.31.0
|
|
|
|
|
|
| 1 |
gradio==6.1.0
|
| 2 |
numpy==1.24.3
|
| 3 |
scikit-learn==1.3.0
|
| 4 |
+
requests==2.31.0
|
| 5 |
+
pydantic==2.10.6
|