salma-mahjoub commited on
Commit
47429ca
·
1 Parent(s): dd09d95

Fix: Update Gradio 6.x API endpoint configuration

Browse files
Files changed (1) hide show
  1. app.py +31 -56
app.py CHANGED
@@ -1,7 +1,7 @@
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,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
- # ✅ 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
 
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