shubham680 commited on
Commit
2515a07
Β·
verified Β·
1 Parent(s): 4bb185a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +197 -187
app.py CHANGED
@@ -1,32 +1,32 @@
1
- # import streamlit as st
2
- # import pickle
3
- # import sklearn
4
- # from sklearn.preprocessing import RobustScaler, OneHotEncoder, LabelEncoder
5
- # from sklearn.neighbors import KNeighborsClassifier
6
- # import pandas as pd
7
- # import numpy as np
8
- # import matplotlib.pyplot as plt
9
 
10
 
11
 
12
- # # st.markdown("""
13
- # # <style>
14
- # # .stApp {
15
- # # background-image: url('https://huggingface.co/spaces/shubham680/DiabetesPrediction/resolve/main/bg.jpg');
16
- # # background-size: cover;
17
- # # background-repeat: no-repeat;
18
- # # background-attachment: fixed;
19
- # # }
20
- # # .stTitle {
21
- # # color: #ffffff;
22
- # # font-size: 36px;
23
- # # font-weight: bold;
24
- # # text-align: center;
25
- # # }
26
- # # </style>
27
- # # """, unsafe_allow_html=True)
28
 
29
- # st.title("Introvert/Extrovert Prediction App")
30
 
31
 
32
 
@@ -36,77 +36,77 @@
36
 
37
 
38
 
39
- # #with st.sidebar:
40
- # #st.header("Patient Information")
41
- # time_spent = st.number_input("Enter Time_spent_Alone:",min_value=0,max_value=11,step=1)
42
- # stage_fear = st.selectbox("Stage Fear:",["Yes","No"])
43
- # social_event = st.number_input("Enter Social Event Frequency:",min_value=0,max_value=10,step=1)
44
- # going_outside = st.number_input("Enter Going Frequency:",min_value=0,max_value=7,step=1)
45
- # drained = st.selectbox("Drained After Socializing:",["Yes","No"])
46
- # friends = st.number_input("Enter Friend Circle Size:",min_value=0,max_value=15,step=1)
47
- # post_frequency = st.number_input("Enter Post Frequency:",min_value=0,max_value=10,step=1)
48
 
49
 
50
 
51
- # # def plot_health_metrics(inputs):
52
- # # labels = ["Age", "BMI", "Urea", "Creatinine", "HbA1c", "Cholesterol", "Triglycerides", "HDL", "LDL", "VLDL"]
53
- # # standard_ranges = [
54
- # # (20, 80), (18.5, 24.9), (2.3, 7.0), (0.6, 1.2), (4.0, 5.6), (125, 200), (40, 150), (40, 60), (50, 100), (5, 40)
55
- # # ]
56
- # # fig, ax = plt.subplots(figsize=(10, 6))
57
- # # ax.barh(labels, [inputs[i] for i in range(10)], color='skyblue')
58
- # # for i, (low, high) in enumerate(standard_ranges):
59
- # # ax.plot([low, high], [i, i], color='red', linewidth=2)
60
- # # ax.set_xlabel("Value")
61
- # # ax.set_title("Health Metrics vs Standard Ranges")
62
- # # st.pyplot(fig)
63
 
64
- # # plot_health_metrics([age, bmi, urea, cr, HbA1c, chol, tg, hdl, ldl, vldl])
65
 
66
 
67
- # with open("rs.pkl", "rb") as f:
68
- # rs = pickle.load(f)
69
 
70
- # with open("ohe_drain.pkl", "rb") as f:
71
- # ohe_drain = pickle.load(f)
72
 
73
- # with open("ohe_stage.pkl", "rb") as f:
74
- # ohe_stage = pickle.load(f)
75
 
76
- # with open("le.pkl", "rb") as f:
77
- # le = pickle.load(f)
78
 
79
- # with open("knn.pkl", "rb") as f:
80
- # knn = pickle.load(f)
81
 
82
- # stage_encoded = ohe_stage.transform([[stage_fear]])[0] # gender encoded using one hot encoding
83
- # drain_encoded = ohe_drain.transform([[drained]])[0]
84
 
85
 
86
- # numeric_features = np.array([[time_spent, social_event, going_outside, friends, post_frequency]])
87
- # scaled_features = rs.transform(numeric_features)[0]
88
 
89
- # st.write("Scaled Features:", scaled_features)
90
 
91
 
92
- # final_input = np.concatenate((
93
- # scaled_features[:1],
94
- # stage_encoded,
95
- # scaled_features[1:3],
96
- # drain_encoded,
97
- # scaled_features[3:]
98
- # )).reshape(1, -1)
99
 
100
 
101
- # #input_data = np.array([[gender_encoded, age, urea, cr, HbA1c, chol, tg, hdl, ldl, vldl, bmi]])
102
 
103
 
104
 
105
 
106
- # prediction_labels = {
107
- # 0: "Extrovert",
108
- # 1: "Introvert"
109
- # }
110
 
111
 
112
 
@@ -125,120 +125,130 @@
125
  # unsafe_allow_html=True
126
  # )
127
 
128
-
129
 
130
- import streamlit as st
131
- import pickle
132
- import numpy as np
133
- import pandas as pd
134
 
135
- # Inject custom CSS
136
- st.markdown("""
137
- <style>
138
- .stApp {
139
- background-image: url('https://huggingface.co/spaces/shubham680/DiabetesPrediction/resolve/main/bg.jpg');
140
- background-size: cover;
141
- background-attachment: fixed;
142
- }
143
- .main-container {
144
- background-color: rgba(255, 255, 255, 0.9);
145
- padding: 2rem;
146
- border-radius: 15px;
147
- box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
148
- }
149
- .stButton>button {
150
- background-color: #4CAF50;
151
- color: white;
152
- font-weight: bold;
153
- padding: 0.5em 1em;
154
- border-radius: 10px;
155
- }
156
- .prediction-box {
157
- background-color: #1f77b4;
158
- padding: 1em;
159
- border-radius: 10px;
160
- color: white;
161
- font-size: 18px;
162
- text-align: center;
163
- }
164
- </style>
165
- """, unsafe_allow_html=True)
166
-
167
- # Title
168
- st.markdown("<h1 style='text-align: center;'>Introvert vs Extrovert Predictor</h1>", unsafe_allow_html=True)
169
-
170
- with st.container():
171
- #st.markdown("<div class='main-container'>", unsafe_allow_html=True)
172
-
173
- # Create input layout with columns
174
- col1, col2 = st.columns(2)
175
-
176
- with col1:
177
- time_spent = st.number_input("πŸ•’ Time Spent Alone", min_value=0, max_value=11, step=1)
178
- social_event = st.number_input("πŸŽ‰ Social Event Attendance", min_value=0, max_value=10, step=1)
179
- going_outside = st.number_input("πŸšΆβ€β™‚οΈ Going Outside Frequency", min_value=0, max_value=7, step=1)
180
-
181
- with col2:
182
- stage_fear = st.selectbox("🎀 Stage Fear", ["Yes", "No"])
183
- drained = st.selectbox("πŸ˜“ Drained After Socializing", ["Yes", "No"])
184
- friends = st.number_input("πŸ‘₯ Friend Circle Size", min_value=0, max_value=15, step=1)
185
- post_frequency = st.number_input("πŸ“± Post Frequency on Social Media", min_value=0, max_value=10, step=1)
186
-
187
- # Load models and encoders
188
- with open("rs.pkl", "rb") as f:
189
- rs = pickle.load(f)
190
-
191
- with open("ohe_drain.pkl", "rb") as f:
192
- ohe_drain = pickle.load(f)
193
-
194
- with open("ohe_stage.pkl", "rb") as f:
195
- ohe_stage = pickle.load(f)
196
-
197
- with open("le.pkl", "rb") as f:
198
- le = pickle.load(f)
199
-
200
- with open("knn.pkl", "rb") as f:
201
- knn = pickle.load(f)
202
-
203
- # Encode categorical values
204
- stage_encoded = ohe_stage.transform([[stage_fear]])[0] # shape (1,)
205
- drain_encoded = ohe_drain.transform([[drained]])[0]
206
-
207
- # Scale numeric input
208
- numeric_features = np.array([[time_spent, social_event, going_outside, friends, post_frequency]])
209
- scaled_features = rs.transform(numeric_features)[0]
210
-
211
- # Debug: show scaled values
212
- st.markdown("### πŸ§ͺ Scaled Feature Values")
213
- feature_names = ["Time_spent_Alone", "Social_event", "Going_outside", "Friends", "Post_frequency"]
214
- st.json({name: val for name, val in zip(feature_names, scaled_features)})
215
-
216
- # Final input
217
- final_input = np.concatenate((
218
- scaled_features[:1], # Time_spent_Alone
219
- stage_encoded, # Stage_fear (1 col)
220
- scaled_features[1:3], # Social_event, Going_outside
221
- drain_encoded, # Drained_after_socializing (1 col)
222
- scaled_features[3:] # Friends, Post_frequency
223
- )).reshape(1, -1)
224
-
225
- # Prediction labels
226
- prediction_labels = {
227
- 0: "Extrovert",
228
- 1: "Introvert"
229
- }
230
-
231
- # Prediction trigger
232
- if st.button("πŸ” Predict"):
233
- prediction = knn.predict(final_input)[0]
234
- result_label = prediction_labels.get(prediction, "Unknown")
235
-
236
- # Styled result box
237
- st.markdown(
238
- f"<div class='prediction-box'><strong>Predicted Personality:</strong> {result_label}</div>",
239
- unsafe_allow_html=True
240
- )
241
-
242
- st.markdown("</div>", unsafe_allow_html=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
243
 
244
 
 
1
+ import streamlit as st
2
+ import pickle
3
+ import sklearn
4
+ from sklearn.preprocessing import RobustScaler, OneHotEncoder, LabelEncoder
5
+ from sklearn.neighbors import KNeighborsClassifier
6
+ import pandas as pd
7
+ import numpy as np
8
+ import matplotlib.pyplot as plt
9
 
10
 
11
 
12
+ # st.markdown("""
13
+ # <style>
14
+ # .stApp {
15
+ # background-image: url('https://huggingface.co/spaces/shubham680/DiabetesPrediction/resolve/main/bg.jpg');
16
+ # background-size: cover;
17
+ # background-repeat: no-repeat;
18
+ # background-attachment: fixed;
19
+ # }
20
+ # .stTitle {
21
+ # color: #ffffff;
22
+ # font-size: 36px;
23
+ # font-weight: bold;
24
+ # text-align: center;
25
+ # }
26
+ # </style>
27
+ # """, unsafe_allow_html=True)
28
 
29
+ st.title("Introvert/Extrovert Prediction App")
30
 
31
 
32
 
 
36
 
37
 
38
 
39
+ #with st.sidebar:
40
+ #st.header("Patient Information")
41
+ time_spent = st.number_input("πŸ•’ Time Spent Alone",min_value=0,max_value=11,step=1)
42
+ stage_fear = st.selectbox("🎀 Stage Fear",["Yes","No"])
43
+ social_event = st.number_input("πŸŽ‰ Social Event Attendance",min_value=0,max_value=10,step=1)
44
+ going_outside = st.number_input("πŸšΆβ€β™‚οΈ Going Outside Frequency",min_value=0,max_value=7,step=1)
45
+ drained = st.selectbox("πŸ˜“ Drained After Socializing",["Yes","No"])
46
+ friends = st.number_input("πŸ‘₯ Friend Circle Size",min_value=0,max_value=15,step=1)
47
+ post_frequency = st.number_input("πŸ“± Post Frequency on Social Media",min_value=0,max_value=10,step=1)
48
 
49
 
50
 
51
+ # def plot_health_metrics(inputs):
52
+ # labels = ["Age", "BMI", "Urea", "Creatinine", "HbA1c", "Cholesterol", "Triglycerides", "HDL", "LDL", "VLDL"]
53
+ # standard_ranges = [
54
+ # (20, 80), (18.5, 24.9), (2.3, 7.0), (0.6, 1.2), (4.0, 5.6), (125, 200), (40, 150), (40, 60), (50, 100), (5, 40)
55
+ # ]
56
+ # fig, ax = plt.subplots(figsize=(10, 6))
57
+ # ax.barh(labels, [inputs[i] for i in range(10)], color='skyblue')
58
+ # for i, (low, high) in enumerate(standard_ranges):
59
+ # ax.plot([low, high], [i, i], color='red', linewidth=2)
60
+ # ax.set_xlabel("Value")
61
+ # ax.set_title("Health Metrics vs Standard Ranges")
62
+ # st.pyplot(fig)
63
 
64
+ # plot_health_metrics([age, bmi, urea, cr, HbA1c, chol, tg, hdl, ldl, vldl])
65
 
66
 
67
+ with open("rs.pkl", "rb") as f:
68
+ rs = pickle.load(f)
69
 
70
+ with open("ohe_drain.pkl", "rb") as f:
71
+ ohe_drain = pickle.load(f)
72
 
73
+ with open("ohe_stage.pkl", "rb") as f:
74
+ ohe_stage = pickle.load(f)
75
 
76
+ with open("le.pkl", "rb") as f:
77
+ le = pickle.load(f)
78
 
79
+ with open("knn.pkl", "rb") as f:
80
+ knn = pickle.load(f)
81
 
82
+ stage_encoded = ohe_stage.transform([[stage_fear]])[0] # gender encoded using one hot encoding
83
+ drain_encoded = ohe_drain.transform([[drained]])[0]
84
 
85
 
86
+ numeric_features = np.array([[time_spent, social_event, going_outside, friends, post_frequency]])
87
+ scaled_features = rs.transform(numeric_features)[0]
88
 
89
+ st.write("Scaled Features:", scaled_features)
90
 
91
 
92
+ final_input = np.concatenate((
93
+ scaled_features[:1],
94
+ stage_encoded,
95
+ scaled_features[1:3],
96
+ drain_encoded,
97
+ scaled_features[3:]
98
+ )).reshape(1, -1)
99
 
100
 
101
+ #input_data = np.array([[gender_encoded, age, urea, cr, HbA1c, chol, tg, hdl, ldl, vldl, bmi]])
102
 
103
 
104
 
105
 
106
+ prediction_labels = {
107
+ 0: "Extrovert",
108
+ 1: "Introvert"
109
+ }
110
 
111
 
112
 
 
125
  # unsafe_allow_html=True
126
  # )
127
 
 
128
 
 
 
 
 
129
 
130
+ if st.button("πŸ” Predict"):
131
+ prediction = knn.predict(final_input)[0]
132
+ result_label = prediction_labels.get(prediction, "Unknown")
133
+
134
+ # Styled result box
135
+ st.markdown(
136
+ f"<div class='prediction-box'><strong>Predicted Personality:</strong> {result_label}</div>",
137
+ unsafe_allow_html=True
138
+ )
139
+
140
+
141
+
142
+
143
+ # import streamlit as st
144
+ # import pickle
145
+ # import numpy as np
146
+ # import pandas as pd
147
+
148
+ # # Inject custom CSS
149
+ # st.markdown("""
150
+ # <style>
151
+ # .stApp {
152
+ # background-image: url('https://huggingface.co/spaces/shubham680/DiabetesPrediction/resolve/main/bg.jpg');
153
+ # background-size: cover;
154
+ # background-attachment: fixed;
155
+ # }
156
+ # .main-container {
157
+ # background-color: rgba(255, 255, 255, 0.9);
158
+ # padding: 2rem;
159
+ # border-radius: 15px;
160
+ # box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
161
+ # }
162
+ # .stButton>button {
163
+ # background-color: #4CAF50;
164
+ # color: white;
165
+ # font-weight: bold;
166
+ # padding: 0.5em 1em;
167
+ # border-radius: 10px;
168
+ # }
169
+ # .prediction-box {
170
+ # background-color: #1f77b4;
171
+ # padding: 1em;
172
+ # border-radius: 10px;
173
+ # color: white;
174
+ # font-size: 18px;
175
+ # text-align: center;
176
+ # }
177
+ # </style>
178
+ # """, unsafe_allow_html=True)
179
+
180
+ # # Title
181
+ # st.markdown("<h1 style='text-align: center;'>Introvert vs Extrovert Predictor</h1>", unsafe_allow_html=True)
182
+
183
+ # with st.container():
184
+ # #st.markdown("<div class='main-container'>", unsafe_allow_html=True)
185
+
186
+ # # Create input layout with columns
187
+ # col1, col2 = st.columns(2)
188
+
189
+ # with col1:
190
+ # time_spent = st.number_input("πŸ•’ Time Spent Alone", min_value=0, max_value=11, step=1)
191
+ # social_event = st.number_input("πŸŽ‰ Social Event Attendance", min_value=0, max_value=10, step=1)
192
+ # going_outside = st.number_input("πŸšΆβ€β™‚οΈ Going Outside Frequency", min_value=0, max_value=7, step=1)
193
+
194
+ # with col2:
195
+ # stage_fear = st.selectbox("🎀 Stage Fear", ["Yes", "No"])
196
+ # drained = st.selectbox("πŸ˜“ Drained After Socializing", ["Yes", "No"])
197
+ # friends = st.number_input("πŸ‘₯ Friend Circle Size", min_value=0, max_value=15, step=1)
198
+ # post_frequency = st.number_input("πŸ“± Post Frequency on Social Media", min_value=0, max_value=10, step=1)
199
+
200
+ # # Load models and encoders
201
+ # with open("rs.pkl", "rb") as f:
202
+ # rs = pickle.load(f)
203
+
204
+ # with open("ohe_drain.pkl", "rb") as f:
205
+ # ohe_drain = pickle.load(f)
206
+
207
+ # with open("ohe_stage.pkl", "rb") as f:
208
+ # ohe_stage = pickle.load(f)
209
+
210
+ # with open("le.pkl", "rb") as f:
211
+ # le = pickle.load(f)
212
+
213
+ # with open("knn.pkl", "rb") as f:
214
+ # knn = pickle.load(f)
215
+
216
+ # # Encode categorical values
217
+ # stage_encoded = ohe_stage.transform([[stage_fear]])[0] # shape (1,)
218
+ # drain_encoded = ohe_drain.transform([[drained]])[0]
219
+
220
+ # # Scale numeric input
221
+ # numeric_features = np.array([[time_spent, social_event, going_outside, friends, post_frequency]])
222
+ # scaled_features = rs.transform(numeric_features)[0]
223
+
224
+
225
+
226
+ # # Final input
227
+ # final_input = np.concatenate((
228
+ # scaled_features[:1], # Time_spent_Alone
229
+ # stage_encoded, # Stage_fear (1 col)
230
+ # scaled_features[1:3], # Social_event, Going_outside
231
+ # drain_encoded, # Drained_after_socializing (1 col)
232
+ # scaled_features[3:] # Friends, Post_frequency
233
+ # )).reshape(1, -1)
234
+
235
+ # # Prediction labels
236
+ # prediction_labels = {
237
+ # 0: "Extrovert",
238
+ # 1: "Introvert"
239
+ # }
240
+
241
+ # # Prediction trigger
242
+ # if st.button("πŸ” Predict"):
243
+ # prediction = knn.predict(final_input)[0]
244
+ # result_label = prediction_labels.get(prediction, "Unknown")
245
+
246
+ # # Styled result box
247
+ # st.markdown(
248
+ # f"<div class='prediction-box'><strong>Predicted Personality:</strong> {result_label}</div>",
249
+ # unsafe_allow_html=True
250
+ # )
251
+
252
+ # st.markdown("</div>", unsafe_allow_html=True)
253
 
254