CoolFace
Apppublic

Ausbel/Sepsis-Prediction-App-FastAPI-1

sourceHugging Faceupdated 3y agoView on Hugging Face
0likes
main.py71 linesDownload Raw Back to root
1from fastapi import FastAPI, HTTPException, Query2import pandas as pd3import joblib4 5 6 7app = FastAPI()8 9 10 11# Load the sepsis prediction model12model = joblib.load('XGB.joblib')13 14 15 16@app.get("/")17async def read_root():18    return {"message": "Sepsis Prediction API using FastAPI"}19 20 21 22def classify(prediction):23    if prediction == 0:24        return "Patient does not have sepsis"25    else:26        return "Patient has sepsis"27 28 29 30@app.get("/predict/")31async def predict_sepsis(32    prg: float = Query(..., description="Plasma glucose"),33    pl: float = Query(..., description="Blood Work Result-1 (mu U/ml)"),34    pr: float = Query(..., description="Blood Pressure (mm Hg)"),35    sk: float = Query(..., description="Blood Work Result-2 (mm)"),36    ts: float = Query(..., description="Blood Work Result-3 (mu U/ml)"),37    m11: float = Query(..., description="Body mass index (weight in kg/(height in m)^2"),38    bd2: float = Query(..., description="Blood Work Result-4 (mu U/ml)"),39    age: int = Query(..., description="Patient's age (years)")40):41    input_data = [prg, pl, pr, sk, ts, m11, bd2, age]42 43 44 45    input_df = pd.DataFrame([input_data], columns=[46        "Plasma glucose", "Blood Work Result-1", "Blood Pressure",47        "Blood Work Result-2", "Blood Work Result-3",48        "Body mass index", "Blood Work Result-4", "Age"49    ])50 51 52 53    pred = model.predict(input_df)54    output = classify(pred[0])55 56 57 58    response = {59        "prediction": output60    }61 62 63 64    return response65 66 67 68# Run the app using Uvicorn69if __name__ == "__main__":70    import uvicorn71    uvicorn.run(app, host="127.0.0.1", port=7860)