salma-mahjoub commited on
Commit
eebb212
·
1 Parent(s): c19c852

Fix: Update Gradio 6.x API endpoint configuration

Browse files
Files changed (1) hide show
  1. app.py +65 -0
app.py CHANGED
@@ -61,3 +61,68 @@ iface = gr.Interface(
61
  # ✅ Lancement de l'interface
62
  # Hugging Face Spaces détecte automatiquement l'interface Gradio
63
  iface.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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=[
100
+ gr.Textbox(
101
+ label="Clothes Data (JSON)",
102
+ placeholder='[{"id":"top1","category":"top","style":"casual",...}]',
103
+ lines=10
104
+ ),
105
+ gr.Dropdown(
106
+ choices=["casual", "formal", "sport", "chic"],
107
+ label="Preference",
108
+ value="casual"
109
+ ),
110
+ gr.Textbox(label="City", value="Tunis")
111
+ ],
112
+ outputs=gr.Textbox(label="Recommended Outfit (JSON)", lines=15),
113
+ title="🎽 Labasni Outfit Recommender",
114
+ description="Recommandations d'outfits basées sur ML (TensorFlow + PyTorch)",
115
+ examples=[
116
+ [
117
+ '[{"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"}]',
118
+ "casual",
119
+ "Tunis"
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