Spaces:
Sleeping
Sleeping
Commit ·
f67fb7d
1
Parent(s): d1a3d0b
fix: Use gr.Interface for REST API exposure
Browse files
app.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
"""
|
| 2 |
Labasni Recommender Service - Hugging Face Space
|
| 3 |
-
✅ Compatible Gradio 6.x avec API
|
| 4 |
"""
|
| 5 |
|
| 6 |
import gradio as gr
|
|
@@ -47,61 +47,46 @@ 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 |
-
fn=recommend_outfit_api,
|
| 88 |
-
inputs=[clothes_input, preference_input, city_input],
|
| 89 |
-
outputs=output
|
| 90 |
-
)
|
| 91 |
-
|
| 92 |
-
gr.Markdown("""
|
| 93 |
-
### 📋 Exemple de données
|
| 94 |
-
```json
|
| 95 |
-
[
|
| 96 |
-
{"id":"top1","category":"top","style":"casual","color":"white","season":"summer","score":0.8},
|
| 97 |
-
{"id":"bottom1","category":"bottom","style":"casual","color":"blue","season":"summer","score":0.7},
|
| 98 |
-
{"id":"shoe1","category":"footwear","style":"casual","color":"black","season":"summer","score":0.9}
|
| 99 |
-
]
|
| 100 |
-
```
|
| 101 |
-
""")
|
| 102 |
|
| 103 |
-
# ✅ CRUCIAL : Lancer avec l'API activée
|
| 104 |
if __name__ == "__main__":
|
|
|
|
| 105 |
demo.launch(
|
| 106 |
server_name="0.0.0.0",
|
| 107 |
server_port=7860,
|
|
|
|
| 1 |
"""
|
| 2 |
Labasni Recommender Service - Hugging Face Space
|
| 3 |
+
✅ Compatible Gradio 6.x avec API REST accessible via /api/predict
|
| 4 |
"""
|
| 5 |
|
| 6 |
import gradio as gr
|
|
|
|
| 47 |
"message": "Erreur lors de la recommandation"
|
| 48 |
}, indent=2)
|
| 49 |
|
| 50 |
+
# ✅ SOLUTION : Utiliser gr.Interface qui expose automatiquement /api/predict
|
| 51 |
+
demo = gr.Interface(
|
| 52 |
+
fn=recommend_outfit_api,
|
| 53 |
+
inputs=[
|
| 54 |
+
gr.Textbox(
|
| 55 |
+
label="Clothes Data (JSON)",
|
| 56 |
+
placeholder='[{"id":"top1","category":"top","style":"casual","color":"white","season":"summer","score":0.5}]',
|
| 57 |
+
lines=10,
|
| 58 |
+
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}]'
|
| 59 |
+
),
|
| 60 |
+
gr.Dropdown(
|
| 61 |
+
choices=["casual", "formal", "sport", "chic", "elegant"],
|
| 62 |
+
label="Preference",
|
| 63 |
+
value="casual"
|
| 64 |
+
),
|
| 65 |
+
gr.Textbox(
|
| 66 |
+
label="City",
|
| 67 |
+
value="Tunis"
|
| 68 |
+
)
|
| 69 |
+
],
|
| 70 |
+
outputs=gr.Textbox(
|
| 71 |
+
label="Recommended Outfit (JSON)",
|
| 72 |
+
lines=15
|
| 73 |
+
),
|
| 74 |
+
title="🎽 Labasni Outfit Recommender",
|
| 75 |
+
description="Recommandations d'outfits basées sur ML (TensorFlow + PyTorch)",
|
| 76 |
+
examples=[
|
| 77 |
+
[
|
| 78 |
+
'[{"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}]',
|
| 79 |
+
"casual",
|
| 80 |
+
"Tunis"
|
| 81 |
+
]
|
| 82 |
+
],
|
| 83 |
+
# ✅ CRUCIAL : Ces paramètres exposent l'API
|
| 84 |
+
api_name="predict",
|
| 85 |
+
allow_flagging="never"
|
| 86 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
|
|
|
|
| 88 |
if __name__ == "__main__":
|
| 89 |
+
# ✅ Lancer avec l'API activée
|
| 90 |
demo.launch(
|
| 91 |
server_name="0.0.0.0",
|
| 92 |
server_port=7860,
|