-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
71 lines (57 loc) · 3.03 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
import streamlit as st
import time
import requests
'''
# StrokeModel front
This front queries the [stroke model API](https://stroke-t44zttdg3q-ew.a.run.app/predict)
'''
with st.form(key='params_for_api'):
gender = st.selectbox('Gender',('Male', 'Female', 'Other'))
age = st.number_input('Age', min_value=0, max_value=100, step=1, help='insert value between 0 and 100')
hypertension = st.selectbox('Hypertension', (0,1))
st.caption("0 - I do not have hypertension \n\n 1 - I have hypertension")
heart_disease = st.selectbox('Heart Disease', (0,1))
st.caption("0 - I do not have a heart disease \n\n 1 - I have a heart disease")
ever_married = st.selectbox('Married',('Yes', 'No'))
work_type = st.selectbox('Work Type',('Government', 'Private', 'Children', 'Self-employed', 'Never worked'))
Residence_type = st.selectbox('Residence Type',('Urban', 'Rural'))
avg_glucose_level = st.number_input('Average Glucose Level', value=80, min_value=70, max_value=240, step=1, help='insert value between 70 and 240')
st.caption("If unsure, please move to next category.")
bmi = st.number_input('BMI', value=22.0, min_value=15.0, max_value=45.0, step=0.01, help='insert value between 15.0 and 45.0')
st.caption("If unsure, please move to next category.")
smoking_status = st.selectbox('Smoking Status',('Unknown','Formerly Smoked','Never Smoked','Smokes'))
submit = st.form_submit_button('Make Prediction')
if submit:
params = dict(
id=1,
gender=gender,
age=age,
hypertension=hypertension,
heart_disease=heart_disease,
ever_married=ever_married,
work_type=work_type,
Residence_type=Residence_type,
avg_glucose_level=avg_glucose_level,
bmi=bmi,
smoking_status=smoking_status
)
progress_text = "Predicting..."
my_bar = st.progress(0, text=progress_text)
for percent_complete in range(100):
time.sleep(0.02)
my_bar.progress(percent_complete + 1, text=progress_text)
stroke_api_url = 'https://stroke-t44zttdg3q-ew.a.run.app/predict'
response = requests.get(stroke_api_url, params=params)
prediction = response.json()
pred = prediction['stroke']
st.header(f'Chance of stroke: {pred}')
st.subheader('If 0, your answers indicate that you do not have an increased risk of having a stroke.')
st.subheader('If 1, your answers indicate that you have an increased risk of having a stroke.')
st.subheader('Open the cell below for more information:')
with st.expander("**Open for more info**"):
st.write("""
Whether or not you have an increased risk of having a stroke, it is
important to know how you and others may be affected by your lifestyles.
Check out the following page on the National Heart, Lung and Blood Institute
for more information: https://www.nhlbi.nih.gov/health/stroke/causes
""")