Update app.py
Browse files
app.py
CHANGED
|
@@ -1,49 +1,68 @@
|
|
| 1 |
-
import streamlit as st
|
| 2 |
-
import joblib
|
| 3 |
-
import pandas as pd
|
| 4 |
-
|
| 5 |
-
# Load models
|
| 6 |
-
model = joblib.load("lr_model.joblib")
|
| 7 |
-
encoder = joblib.load("encoder_d.joblib")
|
| 8 |
-
scaler = joblib.load("scaler.joblib")
|
| 9 |
-
|
| 10 |
-
# Streamlit app
|
| 11 |
-
st.title("Diabetes Risk Prediction Tool")
|
| 12 |
-
st.write("Provide the following details to assess risk factors for diabetes.")
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import joblib
|
| 3 |
+
import pandas as pd
|
| 4 |
+
|
| 5 |
+
# Load models
|
| 6 |
+
model = joblib.load("lr_model.joblib")
|
| 7 |
+
encoder = joblib.load("encoder_d.joblib")
|
| 8 |
+
scaler = joblib.load("scaler.joblib")
|
| 9 |
+
|
| 10 |
+
# Streamlit app
|
| 11 |
+
st.title("Diabetes Risk Prediction Tool")
|
| 12 |
+
st.write("Provide the following details to assess risk factors for diabetes.")
|
| 13 |
+
|
| 14 |
+
# Row 1
|
| 15 |
+
col1, col2, col3, col4, col5 = st.columns(5)
|
| 16 |
+
with col1:
|
| 17 |
+
bmi = st.number_input("Body Mass Index (BMI):", min_value=10.0, max_value=50.0, step=0.1)
|
| 18 |
+
with col2:
|
| 19 |
+
family_history = st.selectbox("Family History of Diabetes:", options=encoder["Family_History"].classes_)
|
| 20 |
+
family_history = encoder["Family_History"].transform([family_history])[0]
|
| 21 |
+
with col3:
|
| 22 |
+
physical_activity = st.selectbox("Physical Activity Level:", options=encoder["Physical_Activity"].classes_)
|
| 23 |
+
physical_activity = encoder["Physical_Activity"].transform([physical_activity])[0]
|
| 24 |
+
with col4:
|
| 25 |
+
diet_type = st.selectbox("Diet Type:", options=encoder["Diet_Type"].classes_)
|
| 26 |
+
diet_type = encoder["Diet_Type"].transform([diet_type])[0]
|
| 27 |
+
with col5:
|
| 28 |
+
stress_level = st.selectbox("Stress Level:", options=encoder["Stress_Level"].classes_)
|
| 29 |
+
stress_level = encoder["Stress_Level"].transform([stress_level])[0]
|
| 30 |
+
|
| 31 |
+
# Row 2
|
| 32 |
+
col6, col7, col8, col9, col10 = st.columns(5)
|
| 33 |
+
with col6:
|
| 34 |
+
fasting_blood_sugar = st.number_input("Fasting Blood Sugar (mg/dL):", min_value=50, max_value=300, step=1)
|
| 35 |
+
with col7:
|
| 36 |
+
postprandial_blood_sugar = st.number_input("Postprandial Blood Sugar (mg/dL):", min_value=50, max_value=400, step=1)
|
| 37 |
+
with col8:
|
| 38 |
+
hba1c = st.number_input("HBA1C (%):", min_value=3.0, max_value=15.0, step=0.1)
|
| 39 |
+
with col9:
|
| 40 |
+
waist_hip_ratio = st.number_input("Waist-to-Hip Ratio:", min_value=0.5, max_value=2.0, step=0.01)
|
| 41 |
+
with col10:
|
| 42 |
+
glucose_tolerance = st.number_input("Glucose Tolerance Test Result (mg/dL):", min_value=50, max_value=300, step=1)
|
| 43 |
+
|
| 44 |
+
# Row 3
|
| 45 |
+
col11, col12, col13, col14 = st.columns(4)
|
| 46 |
+
with col11:
|
| 47 |
+
age = st.number_input("Age (years):", min_value=1, max_value=100, step=1)
|
| 48 |
+
with col12:
|
| 49 |
+
vitamin_d_level = st.number_input("Vitamin D Level (ng/mL):", min_value=5.0, max_value=100.0, step=0.1)
|
| 50 |
+
with col13:
|
| 51 |
+
c_protein_level = st.number_input("C-Reactive Protein Level (mg/L):", min_value=0.1, max_value=20.0, step=0.1)
|
| 52 |
+
with col14:
|
| 53 |
+
cholesterol_level = st.number_input("Cholesterol Level (mg/dL):", min_value=100, max_value=400, step=1)
|
| 54 |
+
|
| 55 |
+
# Collect input values into a list
|
| 56 |
+
values = [bmi, family_history, physical_activity, diet_type, stress_level, fasting_blood_sugar,
|
| 57 |
+
postprandial_blood_sugar, hba1c, waist_hip_ratio, glucose_tolerance, age,
|
| 58 |
+
vitamin_d_level, c_protein_level, cholesterol_level]
|
| 59 |
+
|
| 60 |
+
# Submit button
|
| 61 |
+
if st.button("Submit"):
|
| 62 |
+
values = scaler.transform([values])
|
| 63 |
+
prediction = model.predict(values)
|
| 64 |
+
|
| 65 |
+
if prediction == 1:
|
| 66 |
+
st.success("Risk Detected: The person is at risk of diabetes.")
|
| 67 |
+
else:
|
| 68 |
+
st.success("No Risk Detected: The person is not at risk of diabetes.")
|