Spaces:
Sleeping
Sleeping
Commit ·
47429ca
1
Parent(s): dd09d95
Fix: Update Gradio 6.x API endpoint configuration
Browse files
app.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
"""
|
| 2 |
Labasni Recommender Service - Hugging Face Space
|
| 3 |
Interface Gradio pour les recommandations d'outfits
|
| 4 |
-
|
| 5 |
"""
|
| 6 |
|
| 7 |
import gradio as gr
|
|
@@ -27,63 +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 |
-
# ✅
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
output = gr.Textbox(
|
| 60 |
-
label="Recommended Outfit (JSON)",
|
| 61 |
-
lines=15,
|
| 62 |
-
show_copy_button=True
|
| 63 |
-
)
|
| 64 |
-
|
| 65 |
-
# Event handler
|
| 66 |
-
submit_btn.click(
|
| 67 |
-
fn=recommend_outfit_api,
|
| 68 |
-
inputs=[clothes_input, preference_input, city_input],
|
| 69 |
-
outputs=output
|
| 70 |
-
)
|
| 71 |
-
|
| 72 |
-
# Exemples
|
| 73 |
-
gr.Examples(
|
| 74 |
-
examples=[
|
| 75 |
-
[
|
| 76 |
-
'[{"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"}]',
|
| 77 |
-
"casual",
|
| 78 |
-
"Tunis"
|
| 79 |
-
]
|
| 80 |
-
],
|
| 81 |
-
inputs=[clothes_input, preference_input, city_input]
|
| 82 |
-
)
|
| 83 |
|
| 84 |
-
# ✅ IMPORTANT : api_name="predict" expose l'endpoint pour l'API externe
|
| 85 |
if __name__ == "__main__":
|
| 86 |
-
|
| 87 |
server_name="0.0.0.0",
|
| 88 |
server_port=7860,
|
| 89 |
share=False
|
|
|
|
| 1 |
"""
|
| 2 |
Labasni Recommender Service - Hugging Face Space
|
| 3 |
Interface Gradio pour les recommandations d'outfits
|
| 4 |
+
Version simplifiée avec gr.Interface
|
| 5 |
"""
|
| 6 |
|
| 7 |
import gradio as gr
|
|
|
|
| 27 |
except Exception as e:
|
| 28 |
return json.dumps({"success": False, "error": str(e)})
|
| 29 |
|
| 30 |
+
# ✅ Interface Gradio avec api_name explicite
|
| 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 |
+
# ✅ CRUCIAL : Définir api_name pour exposer l'endpoint
|
| 57 |
+
api_name="predict"
|
| 58 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
|
|
|
|
| 60 |
if __name__ == "__main__":
|
| 61 |
+
iface.launch(
|
| 62 |
server_name="0.0.0.0",
|
| 63 |
server_port=7860,
|
| 64 |
share=False
|