AzizBenAmmar7 commited on
Commit
f67fb7d
·
1 Parent(s): d1a3d0b

fix: Use gr.Interface for REST API exposure

Browse files
Files changed (1) hide show
  1. app.py +39 -54
app.py CHANGED
@@ -1,6 +1,6 @@
1
  """
2
  Labasni Recommender Service - Hugging Face Space
3
- ✅ Compatible Gradio 6.x avec API externe accessible
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
- # ✅ CORRECTION GRADIO 6.x : Utiliser gr.Blocks au lieu de gr.Interface
51
- with gr.Blocks(title="🎽 Labasni Outfit Recommender") as demo:
52
- gr.Markdown("""
53
- # 🎽 Labasni Outfit Recommender
54
- Recommandations d'outfits basées sur Machine Learning
55
- """)
56
-
57
- with gr.Row():
58
- with gr.Column():
59
- clothes_input = gr.Textbox(
60
- label="Clothes Data (JSON)",
61
- placeholder='[{"id":"top1","category":"top","style":"casual","color":"white","season":"summer","score":0.5}]',
62
- lines=10,
63
- value='[{"id":"top1","category":"top","style":"casual","color":"white","season":"summer","score":0.8},{"id":"bottom1","category":"bottom","style":"casual","color":"blue","season":"summer","score":0.7},{"id":"shoe1","category":"footwear","style":"casual","color":"black","season":"summer","score":0.9}]'
64
- )
65
-
66
- preference_input = gr.Dropdown(
67
- choices=["casual", "formal", "sport", "chic", "elegant"],
68
- label="Preference",
69
- value="casual"
70
- )
71
-
72
- city_input = gr.Textbox(
73
- label="City",
74
- value="Tunis"
75
- )
76
-
77
- submit_btn = gr.Button("🎯 Get Recommendation", variant="primary")
78
-
79
- with gr.Column():
80
- output = gr.Textbox(
81
- label="Recommended Outfit (JSON)",
82
- lines=15
83
- )
84
-
85
- # ✅ Lier le bouton à la fonction
86
- submit_btn.click(
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,