File size: 8,775 Bytes
3d0c5f4
 
 
 
 
 
 
 
5a0e16a
 
 
3d0c5f4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5a0e16a
3d0c5f4
5a0e16a
 
 
3d0c5f4
 
 
 
 
 
 
 
 
5a0e16a
 
 
 
3d0c5f4
 
5a0e16a
3d0c5f4
 
5a0e16a
3d0c5f4
 
5a0e16a
3d0c5f4
 
5a0e16a
3d0c5f4
 
5a0e16a
3d0c5f4
 
5a0e16a
d5164c7
3d0c5f4
 
5a0e16a
3d0c5f4
5a0e16a
 
3d0c5f4
 
 
 
 
 
 
5a0e16a
 
 
3d0c5f4
 
 
 
5a0e16a
 
 
 
3d0c5f4
5a0e16a
ed0ad1b
3d0c5f4
 
ed0ad1b
3d0c5f4
ed0ad1b
 
 
 
 
5a0e16a
3d0c5f4
 
 
5a0e16a
3d0c5f4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e860a05
fb13bc5
 
 
 
e860a05
fb13bc5
b9dcb0f
 
 
db9e6b8
fb13bc5
860a4d4
e860a05
fb13bc5
 
860a4d4
 
fb13bc5
 
e860a05
 
 
 
860a4d4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e860a05
1539832
e860a05
 
 
 
 
 
 
 
 
 
 
 
 
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
# import streamlit as st
# import pickle
# import sklearn
# from sklearn.preprocessing import RobustScaler, OneHotEncoder, LabelEncoder
# from sklearn.neighbors import KNeighborsClassifier
# import pandas as pd
# import numpy as np
# import matplotlib.pyplot as plt



# # st.markdown("""
# #     <style>
# #         .stApp {
# #             background-image: url('https://huggingface.co/spaces/shubham680/DiabetesPrediction/resolve/main/bg.jpg');
# #             background-size: cover;
# #             background-repeat: no-repeat;
# #             background-attachment: fixed;
# #         }
# #         .stTitle {
# #             color: #ffffff;
# #             font-size: 36px;
# #             font-weight: bold;
# #             text-align: center;
# #         }
# #     </style>
# # """, unsafe_allow_html=True)

# st.title("Introvert/Extrovert Prediction App")



# #with st.sidebar:
#     #st.header("Patient Information")
# time_spent = st.number_input("๐Ÿ•’ Time Spent Alone",min_value=0,max_value=11,step=1)
# stage_fear =  st.selectbox("๐ŸŽค Stage Fear",["Yes","No"])
# social_event =  st.number_input("๐ŸŽ‰ Social Event Attendance",min_value=0,max_value=10,step=1)
# going_outside = st.number_input("๐Ÿšถโ€โ™‚๏ธ Going Outside Frequency",min_value=0,max_value=7,step=1)
# drained =  st.selectbox("๐Ÿ˜“ Drained After Socializing",["Yes","No"])
# friends =  st.number_input("๐Ÿ‘ฅ Friend Circle Size",min_value=0,max_value=15,step=1)
# post_frequency =  st.number_input("๐Ÿ“ฑ Post Frequency on Social Media",min_value=0,max_value=10,step=1)




# with open("rs.pkl", "rb") as f:
#     rs = pickle.load(f)

# with open("ohe_drain.pkl", "rb") as f:
#     ohe_drain = pickle.load(f)

# with open("ohe_stage.pkl", "rb") as f:
#     ohe_stage = pickle.load(f)

# with open("le.pkl", "rb") as f:
#     le = pickle.load(f)

# with open("knn.pkl", "rb") as f:
#     knn = pickle.load(f)

# stage_encoded = ohe_stage.transform([[stage_fear]])[0]  # gender encoded using one hot encoding
# drain_encoded = ohe_drain.transform([[drained]])[0]


# numeric_features = np.array([[time_spent, social_event, going_outside, friends, post_frequency]])
# scaled_features = rs.transform(numeric_features)[0]

# st.write("Scaled Features:", scaled_features)


# final_input = np.concatenate((
#     scaled_features[:1],        
#     stage_encoded,              
#     scaled_features[1:3],       
#     drain_encoded,               
#     scaled_features[3:]          
# )).reshape(1, -1)



# prediction_labels = {
#     0: "Extrovert",
#     1: "Introvert"
# }




# if st.button("๐Ÿ” Predict"):
#     prediction = knn.predict(final_input)[0]
#     result_label = prediction_labels.get(prediction, "Unknown")

#     # Styled result box
#     st.markdown(
#         f"<div class='prediction-box'><strong>Predicted Personality:</strong> {result_label}</div>",
#         unsafe_allow_html=True
#     )




import streamlit as st
import pickle
import numpy as np

# --------- CSS Styling ---------
st.markdown("""
    <style>
        .stApp {
            background: linear-gradient(to right, #c9d6ff, #e2e2e2);
            font-family: 'Segoe UI', sans-serif;
        }
        .glass-card {
            background: rgba(255, 255, 255, 0.6);
            padding: 2rem;
            border-radius: 20px;
            box-shadow: 0 8px 32px rgba(31, 38, 135, 0.37);
            backdrop-filter: blur(10px);
            -webkit-backdrop-filter: blur(10px);
            border: 1px solid rgba(255, 255, 255, 0.18);
            margin-top: 2rem;
        }
        .title {
            font-size: 48px;
            font-weight: bold;
            text-align: center;
            background: linear-gradient(to right, #141E30, #243B55);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
        }
        .predict-button button {
            background-color: #6c63ff;
            color: white;
            font-size: 18px;
            font-weight: 600;
            border-radius: 12px;
            padding: 0.6em 1.5em;
            margin-top: 1rem;
        }
        .result-box {
            animation: fadeIn 1s ease-in-out;
            background: #141E30;
            color: white;
            padding: 1.5em;
            border-radius: 15px;
            text-align: center;
            margin-top: 2rem;
            font-size: 22px;
        }
        @keyframes fadeIn {
            from {opacity: 0;}
            to {opacity: 1;}
        }
    </style>
""", unsafe_allow_html=True)

# --------- Title ---------
st.markdown("<div class='title'>๐Ÿง  Introvert vs Extrovert Personality Predictor</div>", unsafe_allow_html=True)

# --------- Input Form ---------
with st.container():
    st.markdown("<div class='glass-card'>", unsafe_allow_html=True)

    st.markdown("#### ๐Ÿ‘ค Input Your Social Behavior Details")

    col1, col2 = st.columns(2)

    with col1:
        time_spent = st.slider("๐Ÿ•’ Time Spent Alone", 0, 11, 5)
        stage_fear = st.radio("๐ŸŽค Stage Fear", ["Yes", "No"])
        going_outside = st.slider("๐Ÿšถ Going Outside Frequency", 0, 7, 3)

    with col2:
        social_event = st.slider("๐ŸŽ‰ Social Event Attendance", 0, 10, 5)
        drained = st.radio("๐Ÿ˜“ Drained After Socializing", ["Yes", "No"])
        friends = st.slider("๐Ÿ‘ฅ Friend Circle Size", 0, 15, 7)
        post_frequency = st.slider("๐Ÿ“ฑ Social Media Post Frequency", 0, 10, 3)

    # --------- Load Pickles ---------
    with open("rs.pkl", "rb") as f:
        rs = pickle.load(f)
    with open("ohe_drain.pkl", "rb") as f:
        ohe_drain = pickle.load(f)
    with open("ohe_stage.pkl", "rb") as f:
        ohe_stage = pickle.load(f)
    with open("le.pkl", "rb") as f:
        le = pickle.load(f)
    with open("knn.pkl", "rb") as f:
        knn = pickle.load(f)

    # --------- Encoding & Scaling ---------
    stage_encoded = ohe_stage.transform([[stage_fear]])[0]
    drain_encoded = ohe_drain.transform([[drained]])[0]

    numeric_features = np.array([[time_spent, social_event, going_outside, friends, post_frequency]])
    scaled_features = rs.transform(numeric_features)[0]

    final_input = np.concatenate((
        scaled_features[:1],
        stage_encoded,
        scaled_features[1:3],
        drain_encoded,
        scaled_features[3:]
    )).reshape(1, -1)

    prediction_labels = {0: "๐ŸŒŸ Extrovert", 1: "๐ŸŒ™ Introvert"}

    st.markdown("</div>", unsafe_allow_html=True)  # Close glass card




        # --- Prediction Button & Result ---
    result_placeholder = st.empty()  # ๐Ÿ‘ˆ Reserve space near the button
    
    if st.button("๐Ÿ” Predict", key="predict", help="Click to see your personality"):
        prediction = knn.predict(final_input)[0]  # --> return 1d array further taking it as scalar value
        proba = knn.predict_proba(final_input)[0]  # --> returns 2d array containing both probablity taking as 1d array.
        

        label = prediction_labels.get(prediction, "โ“ Unknown")
        confidence = proba[prediction] * 100
    
        result_html = f"""
            <div class='result-box'>
                ๐Ÿ”ฎ <strong>Predicted Personality:</strong> {label}<br>
                ๐Ÿ“Š <strong>Confidence:</strong> {confidence:.2f}%
            </div>
        """
        result_placeholder.markdown(result_html, unsafe_allow_html=True)



    #     # --- Prediction Button & Result ---
    # result_placeholder = st.empty()  # ๐Ÿ‘ˆ Reserve space near the button
    
    # if st.button("๐Ÿ” Predict", key="predict", help="Click to see your personality"):
    #     prediction = knn.predict(final_input)[0]
    #     proba = knn.predict_proba(final_input)[0]
    #     label = prediction_labels.get(prediction, "โ“ Unknown")
    
    #     result_html = f"""
    #         <div class='result-box'>
    #             ๐Ÿ”ฎ <strong>Predicted Personality:</strong> {label}<br><br>
    #             ๐Ÿ“Š <strong>Probabilities:</strong><br>
    #             ๐ŸŒŸ Extrovert: {proba[0]*100:.2f}%<br>
    #             ๐ŸŒ™ Introvert: {proba[1]*100:.2f}%
    #         </div>
    #     """
    #     result_placeholder.markdown(result_html, unsafe_allow_html=True)





    #     # --- Prediction Button & Result ---
    # result_placeholder = st.empty()  # ๐Ÿ‘ˆ Reserve space near the button

    # if st.button("๐Ÿ” Predict", key="predict", help="Click to see your personality"):
    #     prediction = knn.predict(final_input)[0]
    #     label = prediction_labels.get(prediction, "โ“ Unknown")

    #     result_html = f"""
    #         <div class='result-box'>
    #             ๐Ÿ”ฎ <strong>Predicted Personality:</strong> {label}
    #         </div>
    #     """
    #     result_placeholder.markdown(result_html, unsafe_allow_html=True)  # ๐Ÿ‘ˆ result shows instantly in place