|
|
|
from pydantic import BaseModel |
|
import pandas as pd |
|
import joblib |
|
import uvicorn |
|
import numpy as np |
|
from fastapi import FastAPI, HTTPException,Query |
|
|
|
app = FastAPI() |
|
|
|
|
|
@app.get('/') |
|
def home(): |
|
return{'message':'Welcome to Sepsis Prediction Using Fastapi'} |
|
|
|
|
|
model = joblib.load("src/rf_pipeline.joblib") |
|
|
|
|
|
@app.post("/predict") |
|
def predict_sepsis( |
|
PRG: int = Query(..., description="Plasma_glucose"), |
|
PL: int = Query(..., description="Blood_Work_R1"), |
|
PR: int = Query(..., description="Blood_Pressure"), |
|
SK: int = Query(..., description="Blood_Work_R2"), |
|
TS: int = Query(..., description="Blood_Work_R3"), |
|
M11: float = Query(..., description="BMI"), |
|
BD2: float = Query(..., description="Blood_Work_R4"), |
|
Age: int = Query(..., description="Age") |
|
): |
|
try: |
|
|
|
input_data = { |
|
'PRG': PRG, |
|
'PL': PL, |
|
'PR': PR, |
|
'SK': SK, |
|
'TS': TS, |
|
'M11': M11, |
|
'BD2': BD2, |
|
'Age': Age, |
|
} |
|
|
|
|
|
|
|
input_data_df = pd.DataFrame([input_data]) |
|
|
|
|
|
|
|
prediction= model.predict(input_data_df)[0] |
|
|
|
sepsis_status = "patient has sepsis" if prediction == 1 else "Patient does not have sepsis" |
|
|
|
|
|
return {"prediction": sepsis_status} |
|
|
|
except Exception as e: |
|
raise HTTPException(status_code=500, detail=str(e)) |
|
|
|
if __name__ == "__main__": |
|
import uvicorn |
|
import nest_asyncio |
|
|
|
nest_asyncio.apply() |
|
|
|
uvicorn.run(app, host="127.0.0.1", port=8003, log_level="info") |