DavidJyes commited on
Commit
83ee700
·
verified ·
1 Parent(s): 0799837

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -38
app.py CHANGED
@@ -53,48 +53,17 @@ class PredictionResponse(BaseModel):
53
 
54
  # Routes
55
  @app.get("/")
56
- def read_root():
57
- return {
58
- "message": "API de Détection de Fraude",
59
- "version": "1.0.0",
60
- "endpoints": {
61
- "/predict": "POST - Prédire une transaction",
62
- "/health": "GET - Statut de l'API",
63
- "/categories": "GET - Liste des catégories",
64
- "/docs": "GET - Documentation interactive"
65
- }
66
- }
67
-
68
- @app.get("/health")
69
- def health_check():
70
- return {
71
- "status": "healthy",
72
- "model_loaded": model is not None,
73
- "timestamp": datetime.now().isoformat()
74
- }
75
- @app.get("/")
76
  def root():
77
  return RedirectResponse(url="/docs")
78
 
79
- @app.middleware("http")
80
- async def catch_json_decode_errors(request: Request, call_next):
81
- try:
82
- if request.method in ["POST", "PUT", "PATCH"]:
83
- await request.json()
84
- except Exception:
85
- return JSONResponse(
86
- status_code=422,
87
- content={"error": "Le JSON est invalide ou mal formé, merci de consulter la documentation"}
88
- )
89
- return await call_next(request)
90
 
91
- #@app.get("/categories")
92
- # def get_categories():
93
- # return {
94
- # "categories": list(mappings['categories'].keys()),
95
- # "states": list(mappings['states'].keys()),
96
- # "genders": list(mappings['genders'].keys())
97
- # }
98
 
99
  @app.post("/predict", response_model=PredictionResponse)
100
  def predict_fraud(transaction: Transaction):
 
53
 
54
  # Routes
55
  @app.get("/")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56
  def root():
57
  return RedirectResponse(url="/docs")
58
 
 
 
 
 
 
 
 
 
 
 
 
59
 
60
+ @app.get("/categories")
61
+ def get_categories():
62
+ return {
63
+ "categories": list(mappings['categories'].keys()),
64
+ "states": list(mappings['states'].keys()),
65
+ "genders": list(mappings['genders'].keys())
66
+ }
67
 
68
  @app.post("/predict", response_model=PredictionResponse)
69
  def predict_fraud(transaction: Transaction):