-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
76 lines (63 loc) · 2.75 KB
/
Copy pathapp.py
File metadata and controls
76 lines (63 loc) · 2.75 KB
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
74
75
76
import streamlit as st
from main import predict_diabetes
st.set_page_config(
page_title="Diabetes Risk Checker",
page_icon="🩺",
layout="centered",
)
st.title("🩺 Diabetes Risk Checker")
st.caption("Fill in your health details below to get a quick risk estimate. "
"This is not a medical diagnosis — always consult a healthcare professional.")
st.divider()
with st.form("diabetes_form"):
st.subheader("About you")
col1, col2 = st.columns(2)
with col1:
name = st.text_input("Name (optional)")
gender = st.selectbox("Gender", ["Male", "Female"])
with col2:
age = st.slider("Age", 0, 100, 25)
race = st.selectbox("Race", ['AfricanAmerican', 'Asian', 'Caucasian', 'Hispanic', 'Other'])
st.subheader("Medical history")
col3, col4 = st.columns(2)
with col3:
hypertension = st.checkbox("Hypertension")
with col4:
heartdisease = st.checkbox("Heart Disease")
smoking_history = st.selectbox(
"Smoking History", ['never', 'former', 'not current', 'current', 'ever']
)
st.subheader("Lab results")
col5, col6, col7 = st.columns(3)
with col5:
bmi = st.number_input("BMI", min_value=5.0, max_value=100.0, value=25.0)
with col6:
hba1c = st.number_input("HbA1c Level", min_value=1.0, max_value=15.0, value=5.0)
with col7:
blood_glucose = st.number_input("Blood Glucose Level", min_value=30, max_value=300, value=100)
submitted = st.form_submit_button("Predict", use_container_width=True)
if submitted:
race_encoded = [1 if race == r else 0 for r in ['AfricanAmerican', 'Asian', 'Caucasian', 'Hispanic', 'Other']]
input_row = [gender, age, *race_encoded, hypertension, heartdisease, smoking_history, bmi, hba1c, blood_glucose]
with st.spinner("Analyzing your results..."):
output = predict_diabetes([input_row])
st.divider()
greeting = f"{name}, h" if name else "H"
if output:
st.error(f"⚠️ {greeting}ere's your result: **you may be at risk of diabetes.**\n\n"
"Please consult a healthcare professional for a full evaluation.")
else:
st.success(f"✅ {greeting}ere's your result: **no significant risk of diabetes detected.**\n\n"
"Keep up the healthy lifestyle!")
with st.expander("See the details used for this prediction"):
st.write({
"Gender": gender,
"Age": age,
"Race": race,
"Hypertension": hypertension,
"Heart Disease": heartdisease,
"Smoking History": smoking_history,
"BMI": bmi,
"HbA1c Level": hba1c,
"Blood Glucose Level": blood_glucose,
})