forked from aritra43/steadystridenew
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
40 lines (31 loc) · 1.14 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import os
import uvicorn
from fastapi import FastAPI, HTTPException
from pydantic import BaseModel
# from src.infer_model import predict_parkinsons
from src.infer_model_fast import predict_parkinsons
app = FastAPI()
from fastapi.middleware.cors import CORSMiddleware
app.add_middleware(
CORSMiddleware,
allow_origins=["*"], # Adjust to allow specific origins
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
# Define the request model
class PredictionRequest(BaseModel):
kwargs: dict # Accept keyword arguments as a dictionary
@app.post("/predict/")
async def predict(data: PredictionRequest):
try:
# Pass the keyword arguments to the prediction function
result = predict_parkinsons(data.kwargs)
return {"success": True, "result": result}
except Exception as e:
raise HTTPException(status_code=400, detail=f"Prediction failed: {str(e)}")
if __name__ == "__main__":
# PORT = 8095
PORT = int(os.getenv("PORT", "10000"))
uvicorn.run("main:app", port=PORT, host="0.0.0.0")
# uvicorn main:app --host 0.0.0.0 --port $PORT