-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
73 lines (65 loc) · 1.98 KB
/
app.py
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
from flask import Flask, request, jsonify
from flask_cors import CORS
import pandas as pd
import joblib
df = pd.read_csv('sepsis_dataset/preprocessed_dataset.csv.gz',compression='gzip')
model = joblib.load('model/rf_model.joblib')
app = Flask(__name__)
CORS(app)
app.config['DEBUG'] = True
print(model.feature_names_in_)
@app.route('/',methods=['POST','GET'])
def home():
return "Welcome to Sepsis Prediction API click here to go to prediction page: /predict"
@app.route('/predict',methods=['POST'])
def predict():
data = request.json
Age = data['Age']
Gender = data['Gender']
HR = data['HR']
O2Sat = data['O2Sat']
Temp = data['Temp']
SBP = data['SBP']
MAP = data['MAP']
DBP = data['DBP']
Resp = data['Resp']
Bun = data['BUN']
Lactate = data['Lactate']
Creatinine = data['Creatinine']
Bilirubin_total = data['Bilirubin_total']
Glucose = data['Glucose']
WBC = data['WBC']
# Prepare data for prediction
input_data = pd.DataFrame({
'Age': [Age],
'Gender': [Gender], # Ensure the Gender is 0/1 in your data preprocessing
'HR' : [HR],
'O2Sat' : [O2Sat],
'Temp' : [Temp],
'SBP' : [SBP],
'MAP' : [MAP],
'DBP' : [DBP],
'Resp' : [Resp],
'BUN' : [Bun],
'Lactate' : [Lactate],
'Creatinine' : [Creatinine],
'Bilirubin_total' : [Bilirubin_total],
'Glucose' : [Glucose],
'WBC' : [WBC]
})
# Make predictions
prediction = model.predict(input_data)
probability = model.predict_proba(input_data)
print(probability)
if(int(prediction[0])==0):
prediction="No Sepsis"
outputstr = f" with a probability of {probability[0][0]*100:.2f}%"
else:
prediction="Sepsis"
outputstr = f" with a probability of {probability[0][1]*100:.2f}%"
result = {
'prediction':prediction+outputstr
}
return jsonify(result)
if __name__ == "__main__":
app.run()