salma-mahjoub commited on
Commit
dad1ac8
·
1 Parent(s): ae20115

Fix: Update Gradio 6.x API endpoint configuration

Browse files
Files changed (2) hide show
  1. app.py +28 -40
  2. requirements.txt +2 -1
app.py CHANGED
@@ -27,50 +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
- # ✅ Interface Gradio avec Blocks pour meilleur contrôle de l'API
31
- with gr.Blocks(title="🎽 Labasni Outfit Recommender") as demo:
32
- gr.Markdown("# 🎽 Labasni Outfit Recommender")
33
- gr.Markdown("Recommandations d'outfits basées sur ML (TensorFlow + PyTorch)")
34
-
35
- with gr.Row():
36
- with gr.Column():
37
- clothes_input = gr.Textbox(
38
- label="Clothes Data (JSON)",
39
- placeholder='[{"id":"top1","category":"top","style":"casual",...}]',
40
- lines=10
41
- )
42
- preference_input = gr.Dropdown(
43
- choices=["casual", "formal", "sport", "chic"],
44
- label="Preference",
45
- value="casual"
46
- )
47
- city_input = gr.Textbox(label="City", value="Tunis")
48
-
49
- submit_btn = gr.Button("Recommend", variant="primary")
50
-
51
- with gr.Column():
52
- output = gr.Textbox(label="Recommended Outfit (JSON)", lines=15)
53
-
54
- # ✅ Exemples
55
- gr.Examples(
56
- examples=[[
57
  '[{"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"}]',
58
  "casual",
59
  "Tunis"
60
- ]],
61
- inputs=[clothes_input, preference_input, city_input]
62
- )
63
-
64
- # ✅ Exposer l'API avec api_name explicite
65
- submit_btn.click(
66
- fn=recommend_outfit_api,
67
- inputs=[clothes_input, preference_input, city_input],
68
- outputs=output,
69
- api_name="predict" # ✅ CRUCIAL : Expose l'endpoint /api/predict
70
- )
71
 
72
- if __name__ == "__main__":
73
- demo.launch(
74
  server_name="0.0.0.0",
75
  server_port=7860,
76
  share=False
 
27
  except Exception as e:
28
  return json.dumps({"success": False, "error": str(e)})
29
 
30
+ # ✅ Interface Gradio - gr.Interface est plus fiable pour l'API
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
+ # ✅ Pour Gradio 6.x, l'endpoint standard est /run/predict (pas besoin d'api_name)
57
+ # L'API est automatiquement exposée via /run/predict
58
+ )
 
 
 
 
 
 
59
 
60
+ if _name_ == "_main_":
61
+ iface.launch(
62
  server_name="0.0.0.0",
63
  server_port=7860,
64
  share=False
requirements.txt CHANGED
@@ -1,4 +1,5 @@
1
  gradio==6.1.0
2
  numpy==1.24.3
3
  scikit-learn==1.3.0
4
- requests==2.31.0
 
 
1
  gradio==6.1.0
2
  numpy==1.24.3
3
  scikit-learn==1.3.0
4
+ requests==2.31.0
5
+ pydantic==2.10.6