Spaces:
Sleeping
Sleeping
Commit ·
8a0497c
1
Parent(s): 7e9fa5a
fix: Remove allow_flagging parameter for Gradio 6.x compatibility
Browse files
app.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
"""
|
| 2 |
Labasni Recommender Service - Hugging Face Space
|
| 3 |
-
✅ Compatible Gradio 6.x avec API REST
|
| 4 |
"""
|
| 5 |
|
| 6 |
import gradio as gr
|
|
@@ -10,14 +10,6 @@ from recommender_model import recommend_outfit_ml
|
|
| 10 |
def recommend_outfit_api(clothes_json: str, preference: str, city: str = "Tunis"):
|
| 11 |
"""
|
| 12 |
API endpoint pour les recommandations d'outfit
|
| 13 |
-
|
| 14 |
-
Args:
|
| 15 |
-
clothes_json: JSON string contenant la liste des vêtements
|
| 16 |
-
preference: Style préféré (casual, formal, sport)
|
| 17 |
-
city: Ville pour la météo
|
| 18 |
-
|
| 19 |
-
Returns:
|
| 20 |
-
JSON avec l'outfit recommandé
|
| 21 |
"""
|
| 22 |
try:
|
| 23 |
print(f"🔍 Received request - Preference: {preference}, City: {city}")
|
|
@@ -47,47 +39,58 @@ def recommend_outfit_api(clothes_json: str, preference: str, city: str = "Tunis"
|
|
| 47 |
"message": "Erreur lors de la recommandation"
|
| 48 |
}, indent=2)
|
| 49 |
|
| 50 |
-
# ✅
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
|
| 87 |
if __name__ == "__main__":
|
| 88 |
-
# ✅ Lancer avec l'API activée
|
| 89 |
demo.launch(
|
| 90 |
server_name="0.0.0.0",
|
| 91 |
server_port=7860,
|
| 92 |
-
share=False
|
|
|
|
| 93 |
)
|
|
|
|
| 1 |
"""
|
| 2 |
Labasni Recommender Service - Hugging Face Space
|
| 3 |
+
✅ Compatible Gradio 6.x avec API REST forcée
|
| 4 |
"""
|
| 5 |
|
| 6 |
import gradio as gr
|
|
|
|
| 10 |
def recommend_outfit_api(clothes_json: str, preference: str, city: str = "Tunis"):
|
| 11 |
"""
|
| 12 |
API endpoint pour les recommandations d'outfit
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
"""
|
| 14 |
try:
|
| 15 |
print(f"🔍 Received request - Preference: {preference}, City: {city}")
|
|
|
|
| 39 |
"message": "Erreur lors de la recommandation"
|
| 40 |
}, indent=2)
|
| 41 |
|
| 42 |
+
# ✅ Version avec gr.Blocks pour plus de contrôle sur l'API
|
| 43 |
+
with gr.Blocks() as demo:
|
| 44 |
+
gr.Markdown("# 🎽 Labasni Outfit Recommender")
|
| 45 |
+
gr.Markdown("Recommandations d'outfits basées sur ML")
|
| 46 |
+
|
| 47 |
+
with gr.Row():
|
| 48 |
+
with gr.Column():
|
| 49 |
+
clothes_input = gr.Textbox(
|
| 50 |
+
label="Clothes Data (JSON)",
|
| 51 |
+
placeholder='[{"id":"top1","category":"top",...}]',
|
| 52 |
+
lines=10,
|
| 53 |
+
value='[{"id":"top1","category":"top","style":"casual","color":"white","season":"all","score":0.8},{"id":"bottom1","category":"bottom","style":"casual","color":"blue","season":"all","score":0.7},{"id":"shoe1","category":"footwear","style":"casual","color":"black","season":"all","score":0.9}]'
|
| 54 |
+
)
|
| 55 |
+
preference_input = gr.Dropdown(
|
| 56 |
+
choices=["casual", "formal", "sport", "chic", "elegant"],
|
| 57 |
+
label="Preference",
|
| 58 |
+
value="casual"
|
| 59 |
+
)
|
| 60 |
+
city_input = gr.Textbox(label="City", value="Tunis")
|
| 61 |
+
submit_btn = gr.Button("Get Recommendation", variant="primary")
|
| 62 |
+
|
| 63 |
+
with gr.Column():
|
| 64 |
+
output = gr.Textbox(
|
| 65 |
+
label="Recommended Outfit (JSON)",
|
| 66 |
+
lines=15
|
| 67 |
+
)
|
| 68 |
+
|
| 69 |
+
# Exemples
|
| 70 |
+
gr.Examples(
|
| 71 |
+
examples=[
|
| 72 |
+
[
|
| 73 |
+
'[{"id":"top1","category":"top","style":"casual","color":"white","season":"all","score":0.8},{"id":"bottom1","category":"bottom","style":"casual","color":"blue","season":"all","score":0.7},{"id":"shoe1","category":"footwear","style":"casual","color":"black","season":"all","score":0.9}]',
|
| 74 |
+
"casual",
|
| 75 |
+
"Tunis"
|
| 76 |
+
]
|
| 77 |
+
],
|
| 78 |
+
inputs=[clothes_input, preference_input, city_input]
|
| 79 |
+
)
|
| 80 |
+
|
| 81 |
+
# Event handler
|
| 82 |
+
submit_btn.click(
|
| 83 |
+
fn=recommend_outfit_api,
|
| 84 |
+
inputs=[clothes_input, preference_input, city_input],
|
| 85 |
+
outputs=output,
|
| 86 |
+
api_name="predict" # ✅ Force le nom de l'API
|
| 87 |
+
)
|
| 88 |
|
| 89 |
if __name__ == "__main__":
|
| 90 |
+
# ✅ Lancer avec l'API activée explicitement
|
| 91 |
demo.launch(
|
| 92 |
server_name="0.0.0.0",
|
| 93 |
server_port=7860,
|
| 94 |
+
share=False,
|
| 95 |
+
show_api=True # ✅ Force l'affichage de l'API
|
| 96 |
)
|