Spaces:
Sleeping
Sleeping
Commit ·
dd09d95
1
Parent(s): eca5483
Fix: Update Gradio 6.x API endpoint configuration
Browse files
app.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
"""
|
| 2 |
Labasni Recommender Service - Hugging Face Space
|
| 3 |
Interface Gradio pour les recommandations d'outfits
|
|
|
|
| 4 |
"""
|
| 5 |
|
| 6 |
import gradio as gr
|
|
@@ -26,29 +27,64 @@ def recommend_outfit_api(clothes_json: str, preference: str, city: str = "Tunis"
|
|
| 26 |
except Exception as e:
|
| 27 |
return json.dumps({"success": False, "error": str(e)})
|
| 28 |
|
| 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 |
if __name__ == "__main__":
|
| 54 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
"""
|
| 2 |
Labasni Recommender Service - Hugging Face Space
|
| 3 |
Interface Gradio pour les recommandations d'outfits
|
| 4 |
+
Compatible avec Gradio 6.x
|
| 5 |
"""
|
| 6 |
|
| 7 |
import gradio as gr
|
|
|
|
| 27 |
except Exception as e:
|
| 28 |
return json.dumps({"success": False, "error": str(e)})
|
| 29 |
|
| 30 |
+
# ✅ CORRECTION : Configuration pour Gradio 6.x
|
| 31 |
+
# Utiliser gr.Blocks au lieu de gr.Interface pour plus de contrôle
|
| 32 |
+
with gr.Blocks(title="🎽 Labasni Outfit Recommender") as demo:
|
| 33 |
+
gr.Markdown("# 🎽 Labasni Outfit Recommender")
|
| 34 |
+
gr.Markdown("Recommandations d'outfits basées sur ML (TensorFlow + PyTorch)")
|
| 35 |
+
|
| 36 |
+
with gr.Row():
|
| 37 |
+
with gr.Column():
|
| 38 |
+
clothes_input = gr.Textbox(
|
| 39 |
+
label="Clothes Data (JSON)",
|
| 40 |
+
placeholder='[{"id":"top1","category":"top","style":"casual",...}]',
|
| 41 |
+
lines=10,
|
| 42 |
+
value='[{"id":"top1","category":"top","style":"casual","color":"white","season":"summer","score":0.8,"imageURL":"https://example.com/top.jpg"}]'
|
| 43 |
+
)
|
| 44 |
+
|
| 45 |
+
preference_input = gr.Dropdown(
|
| 46 |
+
choices=["casual", "formal", "sport", "chic"],
|
| 47 |
+
label="Preference",
|
| 48 |
+
value="casual"
|
| 49 |
+
)
|
| 50 |
+
|
| 51 |
+
city_input = gr.Textbox(
|
| 52 |
+
label="City",
|
| 53 |
+
value="Tunis"
|
| 54 |
+
)
|
| 55 |
+
|
| 56 |
+
submit_btn = gr.Button("🚀 Générer Recommandation", variant="primary")
|
| 57 |
+
|
| 58 |
+
with gr.Column():
|
| 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 |
+
demo.launch(
|
| 87 |
+
server_name="0.0.0.0",
|
| 88 |
+
server_port=7860,
|
| 89 |
+
share=False
|
| 90 |
+
)
|