Spaces:
Sleeping
Sleeping
from fastapi import FastAPI | |
import pickle | |
import uvicorn | |
import pandas as pd | |
app = FastAPI() | |
# @app.get("/") | |
# def read_root(): | |
# return {"Hello": "World!"} | |
# Function to load pickle file | |
def load_pickle(filename): | |
with open(filename, 'rb') as file: | |
data = pickle.load(file) | |
return data | |
# Load pickle file | |
ml_components = load_pickle('ml_sepsis.pkl') | |
# Components in the pickle file | |
ml_model = ml_components['model'] | |
pipeline_processing = ml_components['pipeline'] | |
async def predict(Plasma_glucose: int, Blood_Work_Result_1: int, | |
Blood_Pressure: int, Blood_Work_Result_2: int, | |
Blood_Work_Result_3: int, Body_mass_index: float, | |
Blood_Work_Result_4: float,Age: int, Insurance:float): | |
data = pd.DataFrame({'Plasma glucose': [Plasma_glucose], 'Blood Work Result-1': [Blood_Work_Result_1], | |
'Blood Pressure': [Blood_Pressure], 'Blood Work Result-2': [Blood_Work_Result_2], | |
'Blood Work Result-3': [Blood_Work_Result_3], 'Body mass index': [Body_mass_index], | |
'Blood Work Result-4': [Blood_Work_Result_4], 'Age': [Age], 'Insurance':[Insurance]}) | |
data_prepared = pipeline_processing.transform(data) | |
model_output = ml_model.predict(data_prepared).tolist() | |
prediction = make_prediction(model_output) | |
return prediction | |
def make_prediction(data_prepared): | |
output_pred = data_prepared | |
if output_pred == 0: | |
output_pred = "Sepsis status is Negative" | |
else: | |
output_pred = "Sepsis status is Positive" | |
return output_pred |