Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
|
@@ -53,12 +53,13 @@ async def root():
|
|
| 53 |
|
| 54 |
@app.post("/predict/")
|
| 55 |
async def predict_income(data: IncomePredictionRequest):
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
|
|
|
| 62 |
|
| 63 |
except Exception as e:
|
| 64 |
logging.error(f"Prediction failed: {e}")
|
|
|
|
| 53 |
|
| 54 |
@app.post("/predict/")
|
| 55 |
async def predict_income(data: IncomePredictionRequest):
|
| 56 |
+
try:
|
| 57 |
+
input_data = data.dict()
|
| 58 |
+
input_df = pd.DataFrame([input_data])
|
| 59 |
+
prediction = dt_model.predict(input_df)
|
| 60 |
+
prediction_proba = dt_model.predict_proba(input_df)
|
| 61 |
+
prediction_result = "Income over $50K" if prediction[0] == 1 else "Income under $50K"
|
| 62 |
+
return {"income_prediction": prediction_result, "prediction_probability": prediction_proba[0][1]}
|
| 63 |
|
| 64 |
except Exception as e:
|
| 65 |
logging.error(f"Prediction failed: {e}")
|