Update app.py
Browse files
app.py
CHANGED
|
@@ -11,6 +11,21 @@ from typing import Any
|
|
| 11 |
|
| 12 |
app = FastAPI()
|
| 13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
# Încărcăm modelul
|
| 15 |
try:
|
| 16 |
model = joblib.load('rf_model.joblib')
|
|
@@ -190,11 +205,5 @@ async def model_info():
|
|
| 190 |
}
|
| 191 |
}
|
| 192 |
|
| 193 |
-
|
| 194 |
-
async def validation_exception_handler(request: Request, exc: ValidationError):
|
| 195 |
-
errors = [{"field": err['loc'][0], "message": err['msg']} for err in exc.errors()]
|
| 196 |
-
return JSONResponse(
|
| 197 |
-
status_code=422,
|
| 198 |
-
content={"message": "Validation Error", "details": errors},
|
| 199 |
-
)
|
| 200 |
|
|
|
|
| 11 |
|
| 12 |
app = FastAPI()
|
| 13 |
|
| 14 |
+
@app.exception_handler(ValidationError)
|
| 15 |
+
async def validation_exception_handler(request: Request, exc: ValidationError):
|
| 16 |
+
errors = []
|
| 17 |
+
for error in exc.errors():
|
| 18 |
+
# Elimină prefixul "Value error" din mesaj
|
| 19 |
+
message = error['msg']
|
| 20 |
+
if message.startswith("Value error: "):
|
| 21 |
+
message = message[12:] # Lungimea "Value error: " este 12
|
| 22 |
+
errors.append({"loc": error['loc'], "msg": message})
|
| 23 |
+
|
| 24 |
+
return JSONResponse(
|
| 25 |
+
status_code=422,
|
| 26 |
+
content={"detail": errors}
|
| 27 |
+
)
|
| 28 |
+
|
| 29 |
# Încărcăm modelul
|
| 30 |
try:
|
| 31 |
model = joblib.load('rf_model.joblib')
|
|
|
|
| 205 |
}
|
| 206 |
}
|
| 207 |
|
| 208 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 209 |
|