Spaces:
Running
Running
Upload folder using huggingface_hub
Browse files- app/routers/predict.py +6 -4
app/routers/predict.py
CHANGED
|
@@ -44,14 +44,16 @@ async def predict_single(request: PredictionRequest):
|
|
| 44 |
result = pipeline.predict(df)
|
| 45 |
|
| 46 |
prediction = result["predictions"][0]
|
| 47 |
-
|
| 48 |
-
|
|
|
|
|
|
|
| 49 |
# Log prediction
|
| 50 |
prediction_logger.log_prediction(
|
| 51 |
input_data=input_dict,
|
| 52 |
prediction=int(prediction),
|
| 53 |
model_version="v1",
|
| 54 |
-
metadata={"probability":
|
| 55 |
)
|
| 56 |
|
| 57 |
# Update metrics
|
|
@@ -60,7 +62,7 @@ async def predict_single(request: PredictionRequest):
|
|
| 60 |
|
| 61 |
return PredictionResponse(
|
| 62 |
prediction=prediction,
|
| 63 |
-
probability=
|
| 64 |
)
|
| 65 |
except Exception as e:
|
| 66 |
prediction_counter.labels(model_version="v1", status="error").inc()
|
|
|
|
| 44 |
result = pipeline.predict(df)
|
| 45 |
|
| 46 |
prediction = result["predictions"][0]
|
| 47 |
+
proba_row = result.get("probabilities")[0] if result.get("probabilities") else None
|
| 48 |
+
# proba_row is a list [p_class0, p_class1, ...]; take the positive-class prob for logging
|
| 49 |
+
proba_scalar = float(proba_row[-1]) if proba_row is not None else None
|
| 50 |
+
|
| 51 |
# Log prediction
|
| 52 |
prediction_logger.log_prediction(
|
| 53 |
input_data=input_dict,
|
| 54 |
prediction=int(prediction),
|
| 55 |
model_version="v1",
|
| 56 |
+
metadata={"probability": proba_scalar}
|
| 57 |
)
|
| 58 |
|
| 59 |
# Update metrics
|
|
|
|
| 62 |
|
| 63 |
return PredictionResponse(
|
| 64 |
prediction=prediction,
|
| 65 |
+
probability=proba_row
|
| 66 |
)
|
| 67 |
except Exception as e:
|
| 68 |
prediction_counter.labels(model_version="v1", status="error").inc()
|