salma-mahjoub commited on
Commit
09bad31
·
1 Parent(s): edaff03

Fix: Update Gradio 6.x API endpoint configuration

Browse files
Files changed (1) hide show
  1. app.py +4 -70
app.py CHANGED
@@ -27,73 +27,7 @@ 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
- # ✅ Interface Gradio - gr.Interface avec api_name explicite pour Gradio 6.x
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 : api_name est nécessaire pour Gradio 6.x
57
- # Cela expose l'endpoint /api/predict
58
- api_name="predict"
59
- )
60
-
61
- # ✅ Lancement de l'interface
62
- # Hugging Face Spaces détecte automatiquement l'interface Gradio
63
- iface.launch()
64
- example.com
65
- Amine
66
- """
67
- Labasni Recommender Service - Hugging Face Space
68
- Interface Gradio pour les recommandations d'outfits
69
- Version simplifiée avec gr.Interface
70
- """
71
-
72
- import gradio as gr
73
- import json
74
- from recommender_model import recommend_outfit_ml
75
-
76
- def recommend_outfit_api(clothes_json: str, preference: str, city: str = "Tunis"):
77
- """
78
- API endpoint pour les recommandations d'outfit
79
-
80
- Args:
81
- clothes_json: JSON string contenant la liste des vêtements
82
- preference: Style préféré (casual, formal, sport)
83
- city: Ville pour la météo
84
-
85
- Returns:
86
- JSON avec l'outfit recommandé
87
- """
88
- try:
89
- clothes_data = json.loads(clothes_json)
90
- result = recommend_outfit_ml(clothes_data, preference, city)
91
- return json.dumps(result, indent=2)
92
- except Exception as e:
93
- return json.dumps({"success": False, "error": str(e)})
94
-
95
- # ✅ Interface Gradio - gr.Interface avec api_name explicite pour Gradio 6.x
96
- # Hugging Face Spaces détecte automatiquement la variable 'demo'
97
  demo = gr.Interface(
98
  fn=recommend_outfit_api,
99
  inputs=[
@@ -120,9 +54,9 @@ demo = gr.Interface(
120
  ]
121
  ],
122
  # ✅ CRUCIAL : api_name est nécessaire pour Gradio 6.x
123
- # Cela expose l'endpoint /api/predict
124
  api_name="predict"
125
  )
126
 
127
- # ✅ Pour Hugging Face Spaces, l'interface est automatiquement détectée et lancée
128
- # La variable 'demo' est la convention standard pour Hugging Face Spaces
 
27
  except Exception as e:
28
  return json.dumps({"success": False, "error": str(e)})
29
 
30
+ # ✅ CORRIGEZ CE POINT : Utilisez UNE seule variable 'demo'
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
  demo = gr.Interface(
32
  fn=recommend_outfit_api,
33
  inputs=[
 
54
  ]
55
  ],
56
  # ✅ CRUCIAL : api_name est nécessaire pour Gradio 6.x
57
+ # Cela expose l'endpoint /run/predict (NOT /api/predict)
58
  api_name="predict"
59
  )
60
 
61
+ # ✅ NE PAS appeler demo.launch() sur Hugging Face Spaces
62
+ # Hugging Face s'occupe du lancement automatiquement