DavidJyes commited on
Commit
f5e2d97
·
verified ·
1 Parent(s): 55d21eb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +55 -2
app.py CHANGED
@@ -161,6 +161,59 @@ def predict_fraud(transaction: Transaction):
161
  except Exception as e:
162
  raise HTTPException(status_code=500, detail=f"Erreur interne: {str(e)}")
163
 
 
 
 
164
  if __name__ == "__main__":
165
- import uvicorn
166
- uvicorn.run(app, host="0.0.0.0", port=7860)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
161
  except Exception as e:
162
  raise HTTPException(status_code=500, detail=f"Erreur interne: {str(e)}")
163
 
164
+ #if __name__ == "__main__":
165
+ # import uvicorn
166
+ # uvicorn.run(app, host="0.0.0.0", port=7860)
167
  if __name__ == "__main__":
168
+ import gradio as gr
169
+ from app import predict_fraud, Transaction # si tu es déjà dans app.py, inutile de réimporter
170
+
171
+ # Wrapper pour adapter les inputs de Gradio au modèle FastAPI
172
+ def api_predict_wrapper(
173
+ amt, category, merchant, trans_date_trans_time, gender, state,
174
+ lat, long, city_pop, dob, merch_lat, merch_long,
175
+ cc_num=None, avg_amt=50, std_amt=30, nb_trans=10
176
+ ):
177
+ tx = Transaction(
178
+ amt=amt,
179
+ category=category,
180
+ merchant=merchant,
181
+ trans_date_trans_time=trans_date_trans_time,
182
+ gender=gender,
183
+ state=state,
184
+ lat=lat,
185
+ long=long,
186
+ city_pop=city_pop,
187
+ dob=dob,
188
+ merch_lat=merch_lat,
189
+ merch_long=merch_long,
190
+ cc_num=cc_num,
191
+ avg_amt=avg_amt,
192
+ std_amt=std_amt,
193
+ nb_trans=nb_trans
194
+ )
195
+ result = predict_fraud(tx)
196
+ return result.dict()
197
+
198
+ # Définition de l'interface Gradio
199
+ iface = gr.Interface(
200
+ fn=api_predict_wrapper,
201
+ inputs=[
202
+ gr.Number(label="Montant"),
203
+ gr.Textbox(label="Catégorie"),
204
+ gr.Textbox(label="Marchand"),
205
+ gr.Textbox(label="Date/Heure"),
206
+ gr.Textbox(label="Genre"),
207
+ gr.Textbox(label="État"),
208
+ gr.Number(label="Latitude"),
209
+ gr.Number(label="Longitude"),
210
+ gr.Number(label="Population ville"),
211
+ gr.Textbox(label="Date de naissance"),
212
+ gr.Number(label="Lat march."),
213
+ gr.Number(label="Long march."),
214
+ ],
215
+ outputs=gr.JSON(label="Résultat")
216
+ )
217
+
218
+ # Lancement du front Gradio
219
+ iface.launch()