Spaces:
Sleeping
Sleeping
Commit ·
ae20115
1
Parent(s): 47429ca
Fix: Update Gradio 6.x API endpoint configuration
Browse files
app.py
CHANGED
|
@@ -27,38 +27,50 @@ 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 avec
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 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 |
-
|
| 57 |
-
|
| 58 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
|
| 60 |
if __name__ == "__main__":
|
| 61 |
-
|
| 62 |
server_name="0.0.0.0",
|
| 63 |
server_port=7860,
|
| 64 |
share=False
|
|
|
|
| 27 |
except Exception as e:
|
| 28 |
return json.dumps({"success": False, "error": str(e)})
|
| 29 |
|
| 30 |
+
# ✅ Interface Gradio avec Blocks pour meilleur contrôle de l'API
|
| 31 |
+
with gr.Blocks(title="🎽 Labasni Outfit Recommender") as demo:
|
| 32 |
+
gr.Markdown("# 🎽 Labasni Outfit Recommender")
|
| 33 |
+
gr.Markdown("Recommandations d'outfits basées sur ML (TensorFlow + PyTorch)")
|
| 34 |
+
|
| 35 |
+
with gr.Row():
|
| 36 |
+
with gr.Column():
|
| 37 |
+
clothes_input = gr.Textbox(
|
| 38 |
+
label="Clothes Data (JSON)",
|
| 39 |
+
placeholder='[{"id":"top1","category":"top","style":"casual",...}]',
|
| 40 |
+
lines=10
|
| 41 |
+
)
|
| 42 |
+
preference_input = gr.Dropdown(
|
| 43 |
+
choices=["casual", "formal", "sport", "chic"],
|
| 44 |
+
label="Preference",
|
| 45 |
+
value="casual"
|
| 46 |
+
)
|
| 47 |
+
city_input = gr.Textbox(label="City", value="Tunis")
|
| 48 |
+
|
| 49 |
+
submit_btn = gr.Button("Recommend", variant="primary")
|
| 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 |
+
inputs=[clothes_input, preference_input, city_input]
|
| 62 |
+
)
|
| 63 |
+
|
| 64 |
+
# ✅ Exposer l'API avec api_name explicite
|
| 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 __name__ == "__main__":
|
| 73 |
+
demo.launch(
|
| 74 |
server_name="0.0.0.0",
|
| 75 |
server_port=7860,
|
| 76 |
share=False
|