DavidJyes commited on
Commit
0799837
·
verified ·
1 Parent(s): 9772d68

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -7
app.py CHANGED
@@ -11,6 +11,8 @@ import os
11
  # Initialisation
12
  app = FastAPI(
13
  title="API Détection de Fraude",
 
 
14
  description="API de détection de fraude dans les transactions bancaires",
15
  version="1.0.0"
16
  )
@@ -70,14 +72,29 @@ def health_check():
70
  "model_loaded": model is not None,
71
  "timestamp": datetime.now().isoformat()
72
  }
 
 
 
73
 
74
- @app.get("/categories")
75
- def get_categories():
76
- return {
77
- "categories": list(mappings['categories'].keys()),
78
- "states": list(mappings['states'].keys()),
79
- "genders": list(mappings['genders'].keys())
80
- }
 
 
 
 
 
 
 
 
 
 
 
 
81
 
82
  @app.post("/predict", response_model=PredictionResponse)
83
  def predict_fraud(transaction: Transaction):
 
11
  # Initialisation
12
  app = FastAPI(
13
  title="API Détection de Fraude",
14
+ docs_url="/docs",
15
+ redoc_url="/redoc",
16
  description="API de détection de fraude dans les transactions bancaires",
17
  version="1.0.0"
18
  )
 
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):