malek-messaoudii
commited on
Commit
·
8a40c79
1
Parent(s):
1d14fcd
Update label files
Browse files- models/label.py +1 -1
- routes/label.py +27 -2
models/label.py
CHANGED
|
@@ -152,7 +152,7 @@ class BatchPredictionResponse(BaseModel):
|
|
| 152 |
predictions: List[PredictionResponse]
|
| 153 |
total_processed: int = Field(..., description="Number of processed items")
|
| 154 |
summary: Dict[str, float] = Field(
|
| 155 |
-
|
| 156 |
description="Summary statistics of the batch prediction"
|
| 157 |
)
|
| 158 |
|
|
|
|
| 152 |
predictions: List[PredictionResponse]
|
| 153 |
total_processed: int = Field(..., description="Number of processed items")
|
| 154 |
summary: Dict[str, float] = Field(
|
| 155 |
+
default_factory=dict,
|
| 156 |
description="Summary statistics of the batch prediction"
|
| 157 |
)
|
| 158 |
|
routes/label.py
CHANGED
|
@@ -112,13 +112,38 @@ async def batch_predict_kpa(request: BatchPredictionRequest):
|
|
| 112 |
)
|
| 113 |
)
|
| 114 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 115 |
logger.info(f"Batch KPA prediction completed — {len(results)} items processed")
|
| 116 |
|
| 117 |
return BatchPredictionResponse(
|
| 118 |
predictions=results,
|
| 119 |
-
total_processed=len(results)
|
|
|
|
| 120 |
)
|
| 121 |
|
| 122 |
except Exception as e:
|
| 123 |
logger.error(f"Batch KPA prediction error: {str(e)}")
|
| 124 |
-
raise HTTPException(status_code=500, detail=f"Batch prediction failed: {str(e)}")
|
|
|
|
| 112 |
)
|
| 113 |
)
|
| 114 |
|
| 115 |
+
# CALCULER LE SUMMARY
|
| 116 |
+
successful_predictions = [r for r in results if r.prediction != -1]
|
| 117 |
+
|
| 118 |
+
if successful_predictions:
|
| 119 |
+
total_apparie = sum(1 for r in successful_predictions if r.prediction == 1)
|
| 120 |
+
total_non_apparie = sum(1 for r in successful_predictions if r.prediction == 0)
|
| 121 |
+
average_confidence = sum(r.confidence for r in successful_predictions) / len(successful_predictions)
|
| 122 |
+
|
| 123 |
+
summary = {
|
| 124 |
+
"total_apparie": total_apparie,
|
| 125 |
+
"total_non_apparie": total_non_apparie,
|
| 126 |
+
"average_confidence": round(average_confidence, 4),
|
| 127 |
+
"successful_predictions": len(successful_predictions),
|
| 128 |
+
"failed_predictions": len(results) - len(successful_predictions)
|
| 129 |
+
}
|
| 130 |
+
else:
|
| 131 |
+
summary = {
|
| 132 |
+
"total_apparie": 0,
|
| 133 |
+
"total_non_apparie": 0,
|
| 134 |
+
"average_confidence": 0.0,
|
| 135 |
+
"successful_predictions": 0,
|
| 136 |
+
"failed_predictions": len(results)
|
| 137 |
+
}
|
| 138 |
+
|
| 139 |
logger.info(f"Batch KPA prediction completed — {len(results)} items processed")
|
| 140 |
|
| 141 |
return BatchPredictionResponse(
|
| 142 |
predictions=results,
|
| 143 |
+
total_processed=len(results),
|
| 144 |
+
summary=summary
|
| 145 |
)
|
| 146 |
|
| 147 |
except Exception as e:
|
| 148 |
logger.error(f"Batch KPA prediction error: {str(e)}")
|
| 149 |
+
raise HTTPException(status_code=500, detail=f"Batch prediction failed: {str(e)}")
|