File size: 4,375 Bytes
648641f
 
 
6454bda
 
b63bd88
 
 
 
 
 
 
6454bda
b63bd88
 
 
 
 
 
6454bda
b63bd88
 
 
 
 
 
6454bda
b63bd88
 
 
 
 
 
 
 
 
 
6454bda
 
 
b63bd88
6454bda
 
 
b63bd88
6454bda
b63bd88
6454bda
 
 
 
 
 
 
 
 
 
 
b63bd88
 
 
 
648641f
 
 
 
 
6454bda
26cd754
648641f
 
6454bda
26cd754
 
648641f
6454bda
 
648641f
6454bda
 
 
26cd754
 
6454bda
648641f
6454bda
 
 
26cd754
 
6454bda
648641f
6454bda
648641f
6454bda
 
 
648641f
6454bda
648641f
 
 
 
 
6454bda
 
648641f
6454bda
 
 
 
 
648641f
6454bda
 
 
 
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import streamlit as st
import joblib
import pandas as pd

# Custom CSS
st.markdown(
    """
    <style>
    .stApp {
        background: url('https://mandayahospitalgroup.com/wp-content/uploads/2024/05/diabetes.jpg') no-repeat center center fixed;
        background-size: cover;
    }
    .stApp h1 {
        background-color: rgba(0, 0, 128, 0.7); 
        color: #ffffff; 
        padding: 10px;
        border-radius: 5px;
        font-size: 2.2em; 
        text-align: center;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 100%;
        margin: 0 auto;
    }
    .stButton>button {
        background-color: #4CAF50;
        color: white;
        font-size: 1.2em;
        border-radius: 10px;
        padding: 10px 24px;
        border: none;
    }
    .stButton {
        display: flex;
        justify-content: center;
    }
    .positive-result {
        background-color: rgba(0, 128, 0, 0.8);
        color: white;
        font-size: 1.5em;
        padding: 20px;
        border-radius: 12px;
        margin-top: 25px;
        text-align: center;
        box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
    }
    .negative-result {
        background-color: rgba(220, 20, 60, 0.85);
        color: white;
        font-size: 1.5em;
        padding: 20px;
        border-radius: 12px;
        margin-top: 25px;
        text-align: center;
        box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
    }
    </style>
    """,
    unsafe_allow_html=True
)

# Load models
model = joblib.load("lr_model.joblib")
encoder = joblib.load("encoder_d.joblib")
scaler = joblib.load("scaler.joblib")

# Title
st.title("🔍 Smart Diabetes Risk Assessment System")
st.write("Provide the following details to assess risk factors for diabetes.")

# Input columns
col1, col2, col3 = st.columns(3)

with col1:
    bmi = st.number_input("Body Mass Index (BMI):", 10.0, 50.0, step=0.1)
    family_history = st.selectbox("Family History of Diabetes:", encoder["Family_History"].classes_)
    family_history = encoder["Family_History"].transform([family_history])[0]
    fasting_blood_sugar = st.number_input("Fasting Blood Sugar (mg/dL):", 50, 300, step=1)
    hba1c = st.number_input("HBA1C (%):", 3.0, 15.0, step=0.1)
    age = st.number_input("Age (years):", 1, 100, step=1)

with col2:
    physical_activity = st.selectbox("Physical Activity Level:", encoder["Physical_Activity"].classes_)
    physical_activity = encoder["Physical_Activity"].transform([physical_activity])[0]
    postprandial_blood_sugar = st.number_input("Postprandial Blood Sugar (mg/dL):", 50, 400, step=1)
    waist_hip_ratio = st.number_input("Waist-to-Hip Ratio:", 0.5, 2.0, step=0.01)
    vitamin_d_level = st.number_input("Vitamin D Level (ng/mL):", 5.0, 100.0, step=0.1)

with col3:
    diet_type = st.selectbox("Diet Type:", encoder["Diet_Type"].classes_)
    diet_type = encoder["Diet_Type"].transform([diet_type])[0]
    stress_level = st.selectbox("Stress Level:", encoder["Stress_Level"].classes_)
    stress_level = encoder["Stress_Level"].transform([stress_level])[0]
    glucose_tolerance = st.number_input("Glucose Tolerance Test Result (mg/dL):", 50, 300, step=1)
    c_protein_level = st.number_input("C-Reactive Protein Level (mg/L):", 0.1, 20.0, step=0.1)
    cholesterol_level = st.number_input("Cholesterol Level (mg/dL):", 100, 400, step=1)

# Prediction logic
values = [bmi, family_history, physical_activity, diet_type, stress_level, fasting_blood_sugar,
          postprandial_blood_sugar, hba1c, waist_hip_ratio, glucose_tolerance, age,
          vitamin_d_level, c_protein_level, cholesterol_level]

if st.button("Submit"):
    scaled_values = scaler.transform([values])
    prediction = model.predict(scaled_values)

    if prediction[0] == 1:
        st.markdown(
            '<div class="negative-result">⚠️ <strong>Risk Alert:</strong> Based on the input data, there is a <strong>significant likelihood</strong> of diabetes. Please consult a healthcare provider for further evaluation.</div>',
            unsafe_allow_html=True
        )
    else:
        st.markdown(
            '<div class="positive-result">✅ <strong>Good News:</strong> Based on the input data, there appears to be <strong>no immediate risk</strong> of diabetes. Keep maintaining a healthy lifestyle!</div>',
            unsafe_allow_html=True
        )