kanneboinakumar commited on
Commit
6454bda
·
verified ·
1 Parent(s): 779faa8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +51 -49
app.py CHANGED
@@ -1,115 +1,117 @@
1
  import streamlit as st
2
  import joblib
3
  import pandas as pd
 
 
4
  st.markdown(
5
  """
6
  <style>
7
- /* Set background image for the entire app */
8
  .stApp {
9
  background: url('https://mandayahospitalgroup.com/wp-content/uploads/2024/05/diabetes.jpg') no-repeat center center fixed;
10
  background-size: cover;
11
  }
12
- .stApp h1 {
13
  background-color: rgba(0, 0, 128, 0.7);
14
  color: #ffffff;
15
  padding: 10px;
16
  border-radius: 5px;
17
  font-size: 2.2em;
18
  text-align: center;
19
- white-space: nowrap; /* Prevents line break */
20
  overflow: hidden;
21
  text-overflow: ellipsis;
22
  max-width: 100%;
23
  margin: 0 auto;
24
  }
25
- /* Style for the button */
26
  .stButton>button {
27
- background-color: #4CAF50; /* Green */
28
  color: white;
29
  font-size: 1.2em;
30
  border-radius: 10px;
31
  padding: 10px 24px;
32
  border: none;
33
  }
34
- /* Center the button */
35
  .stButton {
36
  display: flex;
37
  justify-content: center;
38
  }
39
- /* Style for the output container */
40
- .output-container {
41
- background-color: lightpink;
42
- color: black;
43
  font-size: 1.5em;
44
- padding: 15px;
45
- border-radius: 10px;
46
- margin-top: 20px;
47
- box-shadow: 0 4px 8px rgba(0,0,0,0.1);
48
- width: 200%;
49
- margin-left: auto;
50
- margin-right: auto;
51
  text-align: center;
 
52
  }
53
- </style>
 
 
 
 
 
 
 
 
 
 
54
  """,
55
  unsafe_allow_html=True
56
  )
57
 
58
-
59
  # Load models
60
  model = joblib.load("lr_model.joblib")
61
  encoder = joblib.load("encoder_d.joblib")
62
  scaler = joblib.load("scaler.joblib")
63
 
64
- # Streamlit app
65
  st.title("🔍 Smart Diabetes Risk Assessment System")
66
  st.write("Provide the following details to assess risk factors for diabetes.")
67
 
68
- # Create 3 columns
69
  col1, col2, col3 = st.columns(3)
70
 
71
  with col1:
72
- bmi = st.number_input("Body Mass Index (BMI):", min_value=10.0, max_value=50.0, step=0.1)
73
- family_history = st.selectbox("Family History of Diabetes:", options=encoder["Family_History"].classes_)
74
  family_history = encoder["Family_History"].transform([family_history])[0]
75
- fasting_blood_sugar = st.number_input("Fasting Blood Sugar (mg/dL):", min_value=50, max_value=300, step=1)
76
- hba1c = st.number_input("HBA1C (%):", min_value=3.0, max_value=15.0, step=0.1)
77
- age = st.number_input("Age (years):", min_value=1, max_value=100, step=1)
78
 
79
  with col2:
80
- physical_activity = st.selectbox("Physical Activity Level:", options=encoder["Physical_Activity"].classes_)
81
  physical_activity = encoder["Physical_Activity"].transform([physical_activity])[0]
82
- postprandial_blood_sugar = st.number_input("Postprandial Blood Sugar (mg/dL):", min_value=50, max_value=400, step=1)
83
- waist_hip_ratio = st.number_input("Waist-to-Hip Ratio:", min_value=0.5, max_value=2.0, step=0.01)
84
- vitamin_d_level = st.number_input("Vitamin D Level (ng/mL):", min_value=5.0, max_value=100.0, step=0.1)
85
 
86
  with col3:
87
- diet_type = st.selectbox("Diet Type:", options=encoder["Diet_Type"].classes_)
88
  diet_type = encoder["Diet_Type"].transform([diet_type])[0]
89
- stress_level = st.selectbox("Stress Level:", options=encoder["Stress_Level"].classes_)
90
  stress_level = encoder["Stress_Level"].transform([stress_level])[0]
91
- glucose_tolerance = st.number_input("Glucose Tolerance Test Result (mg/dL):", min_value=50, max_value=300, step=1)
92
- c_protein_level = st.number_input("C-Reactive Protein Level (mg/L):", min_value=0.1, max_value=20.0, step=0.1)
93
- cholesterol_level = st.number_input("Cholesterol Level (mg/dL):", min_value=100, max_value=400, step=1)
94
 
95
- # Collect input values into a list
96
  values = [bmi, family_history, physical_activity, diet_type, stress_level, fasting_blood_sugar,
97
  postprandial_blood_sugar, hba1c, waist_hip_ratio, glucose_tolerance, age,
98
  vitamin_d_level, c_protein_level, cholesterol_level]
99
 
100
- # Submit button
101
  if st.button("Submit"):
102
- # Preprocess input data
103
- values = scaler.transform([values])
104
- prediction = model.predict(values)
105
 
106
- # Display result
107
- if prediction == 1:
108
- st.markdown('<div class="result-container">⚠️ **Risk Alert:** Based on the input data, there is a significant likelihood that the person may be at risk of developing diabetes. It is recommended to consult with a healthcare professional for further evaluation and possible diagnostic tests.</div>', unsafe_allow_html=True)
109
- st.success("")
110
- # st.error("⚠️ **Risk Alert:** Based on the input data, there is a significant likelihood that the person may be at risk of developing diabetes. It is recommended to consult with a healthcare professional for further evaluation and possible diagnostic tests.")
111
  else:
112
- st.markdown('<div class="result-container">✅ **Good News:** Based on the input data, there appears to be no immediate risk of diabetes. Maintaining a healthy lifestyle and regular check-ups are still important for long-term wellness.</div>', unsafe_allow_html=True)
113
- st.success("")
114
- # st.success("✅ **Good News:** Based on the input data, there appears to be no immediate risk of diabetes. Maintaining a healthy lifestyle and regular check-ups are still important for long-term wellness.")
115
-
 
1
  import streamlit as st
2
  import joblib
3
  import pandas as pd
4
+
5
+ # Custom CSS
6
  st.markdown(
7
  """
8
  <style>
 
9
  .stApp {
10
  background: url('https://mandayahospitalgroup.com/wp-content/uploads/2024/05/diabetes.jpg') no-repeat center center fixed;
11
  background-size: cover;
12
  }
13
+ .stApp h1 {
14
  background-color: rgba(0, 0, 128, 0.7);
15
  color: #ffffff;
16
  padding: 10px;
17
  border-radius: 5px;
18
  font-size: 2.2em;
19
  text-align: center;
20
+ white-space: nowrap;
21
  overflow: hidden;
22
  text-overflow: ellipsis;
23
  max-width: 100%;
24
  margin: 0 auto;
25
  }
 
26
  .stButton>button {
27
+ background-color: #4CAF50;
28
  color: white;
29
  font-size: 1.2em;
30
  border-radius: 10px;
31
  padding: 10px 24px;
32
  border: none;
33
  }
 
34
  .stButton {
35
  display: flex;
36
  justify-content: center;
37
  }
38
+ .positive-result {
39
+ background-color: rgba(0, 128, 0, 0.8);
40
+ color: white;
 
41
  font-size: 1.5em;
42
+ padding: 20px;
43
+ border-radius: 12px;
44
+ margin-top: 25px;
 
 
 
 
45
  text-align: center;
46
+ box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
47
  }
48
+ .negative-result {
49
+ background-color: rgba(220, 20, 60, 0.85);
50
+ color: white;
51
+ font-size: 1.5em;
52
+ padding: 20px;
53
+ border-radius: 12px;
54
+ margin-top: 25px;
55
+ text-align: center;
56
+ box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
57
+ }
58
+ </style>
59
  """,
60
  unsafe_allow_html=True
61
  )
62
 
 
63
  # Load models
64
  model = joblib.load("lr_model.joblib")
65
  encoder = joblib.load("encoder_d.joblib")
66
  scaler = joblib.load("scaler.joblib")
67
 
68
+ # Title
69
  st.title("🔍 Smart Diabetes Risk Assessment System")
70
  st.write("Provide the following details to assess risk factors for diabetes.")
71
 
72
+ # Input columns
73
  col1, col2, col3 = st.columns(3)
74
 
75
  with col1:
76
+ bmi = st.number_input("Body Mass Index (BMI):", 10.0, 50.0, step=0.1)
77
+ family_history = st.selectbox("Family History of Diabetes:", encoder["Family_History"].classes_)
78
  family_history = encoder["Family_History"].transform([family_history])[0]
79
+ fasting_blood_sugar = st.number_input("Fasting Blood Sugar (mg/dL):", 50, 300, step=1)
80
+ hba1c = st.number_input("HBA1C (%):", 3.0, 15.0, step=0.1)
81
+ age = st.number_input("Age (years):", 1, 100, step=1)
82
 
83
  with col2:
84
+ physical_activity = st.selectbox("Physical Activity Level:", encoder["Physical_Activity"].classes_)
85
  physical_activity = encoder["Physical_Activity"].transform([physical_activity])[0]
86
+ postprandial_blood_sugar = st.number_input("Postprandial Blood Sugar (mg/dL):", 50, 400, step=1)
87
+ waist_hip_ratio = st.number_input("Waist-to-Hip Ratio:", 0.5, 2.0, step=0.01)
88
+ vitamin_d_level = st.number_input("Vitamin D Level (ng/mL):", 5.0, 100.0, step=0.1)
89
 
90
  with col3:
91
+ diet_type = st.selectbox("Diet Type:", encoder["Diet_Type"].classes_)
92
  diet_type = encoder["Diet_Type"].transform([diet_type])[0]
93
+ stress_level = st.selectbox("Stress Level:", encoder["Stress_Level"].classes_)
94
  stress_level = encoder["Stress_Level"].transform([stress_level])[0]
95
+ glucose_tolerance = st.number_input("Glucose Tolerance Test Result (mg/dL):", 50, 300, step=1)
96
+ c_protein_level = st.number_input("C-Reactive Protein Level (mg/L):", 0.1, 20.0, step=0.1)
97
+ cholesterol_level = st.number_input("Cholesterol Level (mg/dL):", 100, 400, step=1)
98
 
99
+ # Prediction logic
100
  values = [bmi, family_history, physical_activity, diet_type, stress_level, fasting_blood_sugar,
101
  postprandial_blood_sugar, hba1c, waist_hip_ratio, glucose_tolerance, age,
102
  vitamin_d_level, c_protein_level, cholesterol_level]
103
 
 
104
  if st.button("Submit"):
105
+ scaled_values = scaler.transform([values])
106
+ prediction = model.predict(scaled_values)
 
107
 
108
+ if prediction[0] == 1:
109
+ st.markdown(
110
+ '<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>',
111
+ unsafe_allow_html=True
112
+ )
113
  else:
114
+ st.markdown(
115
+ '<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>',
116
+ unsafe_allow_html=True
117
+ )