Spaces:
Runtime error
Runtime error
feat(prediction):correct single prediction error
Browse files
src/controllers/prediction_controller.py
CHANGED
|
@@ -48,9 +48,8 @@ def global_prediction_on_csv(file: UploadFile):
|
|
| 48 |
except Exception as e:
|
| 49 |
raise HTTPException(status_code=500, detail=str(e))
|
| 50 |
|
| 51 |
-
def
|
| 52 |
try:
|
| 53 |
-
# log dans la console
|
| 54 |
if not isinstance(data, dict):
|
| 55 |
raise HTTPException(status_code=400, detail="Invalid JSON payload")
|
| 56 |
|
|
@@ -61,12 +60,11 @@ def single_prediction(data: dict):
|
|
| 61 |
detail=f"Missing required columns: {missing_columns}"
|
| 62 |
)
|
| 63 |
|
| 64 |
-
# Ici tu peux faire la prédiction
|
| 65 |
print("Received data for single prediction:", data)
|
| 66 |
-
|
| 67 |
return {"message": "All required columns present", "to_do": "Not yet implemented"}
|
|
|
|
| 68 |
except HTTPException:
|
| 69 |
raise
|
| 70 |
except Exception as e:
|
| 71 |
raise HTTPException(status_code=500, detail=str(e))
|
| 72 |
-
|
|
|
|
| 48 |
except Exception as e:
|
| 49 |
raise HTTPException(status_code=500, detail=str(e))
|
| 50 |
|
| 51 |
+
def single_prediction_controller(data: dict):
|
| 52 |
try:
|
|
|
|
| 53 |
if not isinstance(data, dict):
|
| 54 |
raise HTTPException(status_code=400, detail="Invalid JSON payload")
|
| 55 |
|
|
|
|
| 60 |
detail=f"Missing required columns: {missing_columns}"
|
| 61 |
)
|
| 62 |
|
| 63 |
+
# Ici tu peux faire la prédiction
|
| 64 |
print("Received data for single prediction:", data)
|
|
|
|
| 65 |
return {"message": "All required columns present", "to_do": "Not yet implemented"}
|
| 66 |
+
|
| 67 |
except HTTPException:
|
| 68 |
raise
|
| 69 |
except Exception as e:
|
| 70 |
raise HTTPException(status_code=500, detail=str(e))
|
|
|
src/routes/prediction_routes.py
CHANGED
|
@@ -1,5 +1,10 @@
|
|
| 1 |
from fastapi import APIRouter, UploadFile, File
|
| 2 |
from src.controllers import prediction_controller
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
router = APIRouter(prefix="/predict", tags=["predict"])
|
| 5 |
|
|
@@ -11,6 +16,6 @@ def predict_from_csv(file: UploadFile = File(...)):
|
|
| 11 |
return prediction_controller.global_prediction_on_csv(file)
|
| 12 |
|
| 13 |
@router.post("/single-prediction")
|
| 14 |
-
def
|
| 15 |
-
return prediction_controller.single_prediction()
|
| 16 |
|
|
|
|
| 1 |
from fastapi import APIRouter, UploadFile, File
|
| 2 |
from src.controllers import prediction_controller
|
| 3 |
+
from pydantic import BaseModel
|
| 4 |
+
from typing import Dict
|
| 5 |
+
|
| 6 |
+
class SinglePredictionRequest(BaseModel):
|
| 7 |
+
__root__: Dict[str, float]
|
| 8 |
|
| 9 |
router = APIRouter(prefix="/predict", tags=["predict"])
|
| 10 |
|
|
|
|
| 16 |
return prediction_controller.global_prediction_on_csv(file)
|
| 17 |
|
| 18 |
@router.post("/single-prediction")
|
| 19 |
+
def single_prediction(req: SinglePredictionRequest):
|
| 20 |
+
return prediction_controller.single_prediction(req.__root__)
|
| 21 |
|