-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
64 lines (43 loc) · 2.29 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
#!/usr/bin/env python
# coding: utf-8
# In[ ]:
import streamlit as st
import joblib
import pandas as pd
from PIL import Image
st.set_page_config(page_title="Diabetes Prediction App", page_icon=None, layout='centered', initial_sidebar_state='auto')
# In[ ]:
@st.cache(allow_output_mutation=True)
def load(scaler_path, model_path):
sc = joblib.load(scaler_path)
model = joblib.load(model_path)
return sc , model
# In[ ]:
def inference(row, scaler, model, cols):
df = pd.DataFrame([row], columns = cols)
X = scaler.transform(df)
features = pd.DataFrame(X, columns = cols)
if (model.predict(features)==0):
return "This is a healthy person!"
else: return "This person has high chances of having diabetics!"
# In[ ]:
st.title('Diabetes Prediction App')
st.write('The data for the following example is originally from the National Institute of Diabetes and Digestive and Kidney Diseases and contains information on females at least 21 years old of Pima Indian heritage. This is a sample application and cannot be used as a substitute for real medical advice.')
image = Image.open('data/diabetes_image.jpg')
st.image(image, use_column_width=True)
st.write('Please fill in the details of the person under consideration in the left sidebar and click on the button below!')
age = st.sidebar.number_input("Age in Years", 1, 150, 25, 1)
pregnancies = st.sidebar.number_input("Number of Pregnancies", 0, 20, 0, 1)
glucose = st.sidebar.slider("Glucose Level", 0, 200, 25, 1)
skinthickness = st.sidebar.slider("Skin Thickness", 0, 99, 20, 1)
bloodpressure = st.sidebar.slider('Blood Pressure', 0, 122, 69, 1)
insulin = st.sidebar.slider("Insulin", 0, 846, 79, 1)
bmi = st.sidebar.slider("BMI", 0.0, 67.1, 31.4, 0.1)
dpf = st.sidebar.slider("Diabetics Pedigree Function", 0.000, 2.420, 0.471, 0.001)
row = [pregnancies, glucose, bloodpressure, skinthickness, insulin, bmi, dpf, age]
# In[ ]:
if (st.button('Find Health Status')):
cols = ['Pregnancies', 'Glucose', 'BloodPressure', 'SkinThickness', 'Insulin', 'BMI', 'DiabetesPedigreeFunction', 'Age']
sc, model = load('models/scaler.joblib', 'models/model.joblib')
result = inference(row, sc, model, cols)
st.write(result)