DOMMETI commited on
Commit
2514e94
Β·
verified Β·
1 Parent(s): ef79993

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +59 -54
app.py CHANGED
@@ -1,42 +1,38 @@
1
  import streamlit as st
2
  import numpy as np
3
- import pickle
4
  import pandas as pd
 
5
 
6
-
7
  try:
8
  with open("final_model (3).pkl", "rb") as f:
9
  model = pickle.load(f)
10
  st.success("βœ… Model loaded successfully!")
11
  except FileNotFoundError:
12
- st.error("❌ Model file not found! Please upload `final_model.pkl`.")
13
  model = None
14
 
15
-
16
  st.markdown(
17
  """
18
  <style>
19
- body {
20
- background-color: #121212;
21
- color: #FFFFFF;
22
- }
23
  .stApp {
24
  background-color: #121212;
25
  color: #FFFFFF;
26
  }
27
  .title {
28
  text-align: center;
29
- font-size: 36px;
30
  font-weight: bold;
31
  color: #BB86FC;
 
32
  }
33
  .stButton > button {
34
- width: 100%;
35
  background-color: #6200EE;
36
  color: white;
37
  font-size: 18px;
38
  border-radius: 8px;
39
- padding: 10px;
40
  transition: 0.3s ease-in-out;
41
  }
42
  .stButton > button:hover {
@@ -45,17 +41,13 @@ st.markdown(
45
  }
46
  .result-box {
47
  text-align: center;
48
- font-size: 20px;
49
  font-weight: bold;
50
  color: white;
51
- padding: 12px;
52
- border-radius: 8px;
53
- margin-top: 20px;
54
- box-shadow: 0px 4px 8px rgba(255, 255, 255, 0.2);
55
- transition: 0.3s ease-in-out;
56
- }
57
- .result-box:hover {
58
- transform: scale(1.05);
59
  }
60
  .high-risk {
61
  background-color: #D32F2F;
@@ -65,51 +57,64 @@ st.markdown(
65
  }
66
  .probability {
67
  background-color: #FFA726;
 
68
  }
69
  </style>
70
  """,
71
  unsafe_allow_html=True,
72
  )
73
 
 
74
 
75
- st.markdown("<h1 class='title'> PCOS Risk Predictor</h1>", unsafe_allow_html=True)
76
-
77
-
78
- with st.expander("πŸ”Ή **Personal Information**", expanded=True):
79
- Age = st.slider("Age", 18, 44, 30)
80
-
81
- with st.expander("πŸ”Ή **Medical Information**", expanded=True):
82
- BMI = st.number_input("BMI", min_value=8, max_value=50, value=23)
83
- Menstrual_Irregularity = st.selectbox("Menstrual_Irregularity", [0,1])
84
- Testosterone_Level = st.number_input("Testosterone_Level(ng/dL)", min_value=20, max_value=135, value=53)
85
- Antral_Follicle_Count = st.number_input("Antral_Follicle_Count", min_value=3, max_value=39, value=8)
86
 
 
 
 
 
 
87
 
 
88
  if st.button("πŸ” Predict Risk"):
89
- try:
90
- input_df = pd.DataFrame([[Age,BMI,Menstrual_Irregularity, Testosterone_Level,Antral_Follicle_Count]], columns=['Age','BMI','Menstrual_Irregularity','Testosterone_Level(ng/dL)','Antral_Follicle_Count'])
91
- prediction = model.predict(input_df)[0]
92
- probability = model.predict_proba(input_df)[0][1] * 100
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
93
 
94
- # Determine Risk Category
95
- if prediction == 1:
96
- result_text = "❌⚠️ High Risk of PCOS Disease!"
97
- result_class = "high-risk"
98
- else:
99
- result_text = "βœ… Low Risk of PCOS Disease!"
100
- result_class = "low-risk"
101
 
102
- # Display Result
103
- st.markdown(
104
- f"<div class='result-box {result_class}'> {result_text} </div>",
105
- unsafe_allow_html=True,
106
- )
107
 
108
- # Display Probability Score
109
- st.markdown(
110
- f"<div class='result-box probability'> πŸ“Š Risk Probability: {probability:.2f}% </div>",
111
- unsafe_allow_html=True,
112
- )
113
 
114
- except Exception as e:
115
- st.error(f"⚠️ Prediction failed: {e}")
 
1
  import streamlit as st
2
  import numpy as np
 
3
  import pandas as pd
4
+ import pickle
5
 
6
+ # Load model
7
  try:
8
  with open("final_model (3).pkl", "rb") as f:
9
  model = pickle.load(f)
10
  st.success("βœ… Model loaded successfully!")
11
  except FileNotFoundError:
12
+ st.error("❌ Model file not found! Please upload `final_model (3).pkl`.")
13
  model = None
14
 
15
+ # Custom CSS for styling
16
  st.markdown(
17
  """
18
  <style>
 
 
 
 
19
  .stApp {
20
  background-color: #121212;
21
  color: #FFFFFF;
22
  }
23
  .title {
24
  text-align: center;
25
+ font-size: 38px;
26
  font-weight: bold;
27
  color: #BB86FC;
28
+ margin-top: 20px;
29
  }
30
  .stButton > button {
 
31
  background-color: #6200EE;
32
  color: white;
33
  font-size: 18px;
34
  border-radius: 8px;
35
+ padding: 10px 20px;
36
  transition: 0.3s ease-in-out;
37
  }
38
  .stButton > button:hover {
 
41
  }
42
  .result-box {
43
  text-align: center;
44
+ font-size: 22px;
45
  font-weight: bold;
46
  color: white;
47
+ padding: 16px;
48
+ border-radius: 10px;
49
+ margin-top: 30px;
50
+ box-shadow: 0px 4px 12px rgba(255, 255, 255, 0.3);
 
 
 
 
51
  }
52
  .high-risk {
53
  background-color: #D32F2F;
 
57
  }
58
  .probability {
59
  background-color: #FFA726;
60
+ margin-top: 12px;
61
  }
62
  </style>
63
  """,
64
  unsafe_allow_html=True,
65
  )
66
 
67
+ st.markdown("<h1 class='title'>🩺 PCOS Risk Predictor</h1>", unsafe_allow_html=True)
68
 
69
+ # Collect user inputs
70
+ with st.expander("πŸ“„ Personal Information", expanded=True):
71
+ Age = st.slider("πŸŽ‚ Age", 18, 44, 30)
 
 
 
 
 
 
 
 
72
 
73
+ with st.expander("πŸ₯ Medical Information", expanded=True):
74
+ BMI = st.number_input("βš–οΈ BMI", min_value=8, max_value=50, value=23)
75
+ Menstrual_Irregularity = st.selectbox("🩸 Menstrual Irregularity (0 = No, 1 = Yes)", [0, 1])
76
+ Testosterone_Level = st.number_input("🧬 Testosterone Level (ng/dL)", min_value=20, max_value=135, value=53)
77
+ Antral_Follicle_Count = st.number_input("πŸ§ͺ Antral Follicle Count", min_value=3, max_value=39, value=8)
78
 
79
+ # Predict
80
  if st.button("πŸ” Predict Risk"):
81
+ if model is None:
82
+ st.error("⚠️ Model is not loaded. Please ensure the model file exists.")
83
+ else:
84
+ try:
85
+ input_df = pd.DataFrame([[
86
+ Age,
87
+ BMI,
88
+ Menstrual_Irregularity,
89
+ Testosterone_Level,
90
+ Antral_Follicle_Count
91
+ ]], columns=[
92
+ 'Age',
93
+ 'BMI',
94
+ 'Menstrual_Irregularity',
95
+ 'Testosterone Level (ng/dL)',
96
+ 'Antral_Follicle_Count'
97
+ ])
98
+
99
+ prediction = model.predict(input_df)[0]
100
+ probability = model.predict_proba(input_df)[0][1] * 100
101
 
102
+ if prediction == 1:
103
+ result_text = "⚠️❌ High Risk of PCOS Detected!"
104
+ result_class = "high-risk"
105
+ else:
106
+ result_text = "βœ… Low Risk of PCOS β€” You're Good!"
107
+ result_class = "low-risk"
 
108
 
109
+ st.markdown(
110
+ f"<div class='result-box {result_class}'>{result_text}</div>",
111
+ unsafe_allow_html=True
112
+ )
 
113
 
114
+ st.markdown(
115
+ f"<div class='result-box probability'>πŸ“Š Estimated Probability: {probability:.2f}%</div>",
116
+ unsafe_allow_html=True
117
+ )
 
118
 
119
+ except Exception as e:
120
+ st.error(f"🚫 Prediction failed: {e}")