Spaces:
Sleeping
Sleeping
File size: 4,230 Bytes
b9ac23e | 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 |
import streamlit as st
import pickle
import pandas as pd
# Load model
with open('src/model.pkl', 'rb') as file:
model = pickle.load(file)
# Set page config with background
st.set_page_config(page_title="Personality Predictor", layout="centered")
# Custom CSS for background image
st.markdown("""
<style>
.stApp {
background-image: url("");
background-size: cover;
background-repeat: no-repeat;
background-attachment: fixed;
}
</style>
""", unsafe_allow_html=True)
st.title("π§ Personality Prediction App")
st.markdown("π This app uses a Machine Learning model to analyze your social behavior and predict whether you're an Extrovert or an Introvert.")
# --- Input Section ---
col1, col2 = st.columns(2)
with col1:
Time_spent_Alone= st.slider("π Time Spent Alone (1-24) in Hours", 0, 24, 5)
Social_event_attendance= st.slider("π How Many Social Event You Attended Recently (1-15)", 0, 15, 5)
Friends_circle_size = st.slider("π₯ Friends Circle Size", 0, 5, 50)
Post_frequency = st.slider("π± How Much Post You Upload On Social Media Recently", 0, 20, 5)
with col2:
Going_outside = st.slider("πΆ Going Outside (1-10)", 0, 10, 5)
Stage_fear = st.selectbox("π€ Do you have stage fear?", ["Yes", "No"])
Drained_after_socializing = st.selectbox("π© Do social events make you feel exhausted?", ["Yes", "No"])
# Encode categorical inputs
stage_fear_encoded = 1 if Stage_fear == "Yes" else 0
drained_encoded = 1 if Drained_after_socializing == "Yes" else 0
# --- Predict ---
# Extrovert Case
if st.button("π Predict Personality"):
# Prepare input DataFrame
data = pd.DataFrame([{
"Time_spent_Alone": Time_spent_Alone,
"Stage_fear": stage_fear_encoded,
"Social_event_attendance": Social_event_attendance,
"Going_outside": Going_outside,
"Drained_after_socializing": drained_encoded,
"Friends_circle_size": Friends_circle_size,
"Post_frequency": Post_frequency
}])
# Make prediction
prediction = model.predict(data)
# π Extrovert Case
if prediction[0] == 0 or prediction[0] == "Extrovert":
# st.success("β
You are likely an **Extrovert** π")
st.markdown("""
<div style='
background-color: #d4edda;
color: #155724;
padding: 20px;
border-radius: 10px;
font-size: 32px;
font-weight: bold;
text-align: center;
line-height: 1.6;
'>
β
You are likely an <strong>Extrovert</strong> π
</div>
""", unsafe_allow_html=True)
st.balloons()
st.markdown("""
<div style='text-align: center;'>
<style>
.float-up {
animation: floatUp 2s ease-in-out forwards;
font-size: 40px;
position: relative;
}
@keyframes floatUp {
0% { bottom: -50px; opacity: 0; }
50% { bottom: 0px; opacity: 1; }
100% { bottom: 50px; opacity: 0; }
}
</style>
<div class="float-up">ππβ¨ππΊ</div>
</div>
""", unsafe_allow_html=True)
# π Introvert Case
else:
# st.warning("π You are likely an **Introvert** π")
st.markdown("""
<div style='
background-color: #f8f9fa;
color: #343a40;
padding: 20px;
border-radius: 10px;
font-size: 32px;
font-weight: bold;
text-align: center;
line-height: 1.6;
'>
π You are likely an <strong>Introvert</strong> π
</div>
""", unsafe_allow_html=True)
st.snow()
st.markdown("""
<div style='text-align: center;'>
<style>
.float-up-slow {
animation: floatSlow 3s ease-in-out forwards;
font-size: 40px;
position: relative;
}
@keyframes floatSlow {
0% { bottom: -30px; opacity: 0; }
50% { bottom: 0px; opacity: 1; }
100% { bottom: 30px; opacity: 0; }
}
</style>
<div class="float-up-slow">ππ§ββοΈπΆβπ«οΈπ</div>
</div>
""", unsafe_allow_html=True)
|