CoolFace
Apppublic

MaryanneMuchai/FastAPI_Sepsis_Classification_App

sourceHugging Faceupdated 3y agoView on Hugging Face
0likes
app.py62 linesDownload Raw Back to root
1# 1. Library imports2import uvicorn3from fastapi import FastAPI4from sepsis import Sepsis5import numpy as np6import pickle7import pandas as pd8# 2. Create the app object9app = FastAPI()10with open('pipeline.pkl', 'rb') as file:11    classifier_dict = pickle.load(file)12 13# Extract the classifier from the dictionary14classifier = classifier_dict['model']15#classifier=pickle.load(pickle_in)16 17# 3. Index route, opens automatically on http://127.0.0.1:800018@app.get('/')19def index():20    return {'message': 'Sepsis Prediction App'}21 22# 4. Route with a single parameter, returns the parameter within a message23#    Located at: http://127.0.0.1:8000/AnyNameHere24@app.get('/{name}')25def get_name(name: str):26    return {'Welcome the Sepssis prediction model': f'{name}'}27 28# 3. Expose the prediction functionality, make a prediction from the passed29#    JSON data and return the predicted Bank Note with the confidence30@app.post('/predict')31def predict_sepssis(data:Sepsis):32    data = data.dict()33    Plasmaglucose=data['Plasmaglucose']34    BloodWorkResult1=data['BloodWorkResult1']35    BloodPressure=data['BloodPressure']36    BloodWorkResult2=data['BloodWorkResult2']37    BloodWorkResult3=data['BloodWorkResult3']38    Bodymassindex =data['Bodymassindex']39    BloodWorkResult4=data['BloodWorkResult4']40    Age=data['Age']41    42     43    44    45   # print(classifier.predict([[variance,skewness,curtosis,entropy]]))46   # Extract the classifier from the dictionary47    48    prediction = classifier.predict([[Plasmaglucose,BloodWorkResult1,BloodPressure,BloodWorkResult2,BloodWorkResult3,Bodymassindex,BloodWorkResult4,Age]])49    if(prediction[0]>0.5):50        prediction="Sepssis present"51    else:52        prediction="Sepssis Absent"53    return {54        'prediction': prediction55    }56 57# 5. Run the API with uvicorn58#    Will run on http://127.0.0.1:800059if __name__ == '__main__':60    uvicorn.run(app, host='127.0.0.1', port=8000)61    62#uvicorn app:app --reload