Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -118,4 +118,23 @@ async def predict(req: Request):
|
|
| 118 |
"z_scores": z_detail,
|
| 119 |
"probabilities": {CLASSES[i]: float(probs[i]) for i in range(len(CLASSES))},
|
| 120 |
"predicted_state": CLASSES[pred_idx],
|
| 121 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 118 |
"z_scores": z_detail,
|
| 119 |
"probabilities": {CLASSES[i]: float(probs[i]) for i in range(len(CLASSES))},
|
| 120 |
"predicted_state": CLASSES[pred_idx],
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
# ---- add to app.py ----
|
| 124 |
+
from fastapi import FastAPI, HTTPException, Request
|
| 125 |
+
from fastapi.responses import JSONResponse
|
| 126 |
+
import traceback
|
| 127 |
+
|
| 128 |
+
@app.post("/echo")
|
| 129 |
+
async def echo(payload: dict):
|
| 130 |
+
return {"received": payload}
|
| 131 |
+
|
| 132 |
+
@app.post("/predict")
|
| 133 |
+
async def predict(payload: dict):
|
| 134 |
+
try:
|
| 135 |
+
return predict_from_json(payload) # your existing function
|
| 136 |
+
except Exception as e:
|
| 137 |
+
tb = traceback.format_exc()
|
| 138 |
+
print("PREDICT ERROR:", tb)
|
| 139 |
+
# Return 400 with details so Excel can read it
|
| 140 |
+
return JSONResponse(status_code=400, content={"error": str(e)})
|