File size: 1,687 Bytes
3671cba
ee259c3
 
 
3671cba
 
 
ee259c3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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']    

@app.get('/Predict_Sepsis')
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