kanneboinakumar's picture
Update app.py
6454bda verified
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
)