Update src/streamlit_app.py
Browse files- src/streamlit_app.py +56 -39
src/streamlit_app.py
CHANGED
|
@@ -1,40 +1,57 @@
|
|
| 1 |
-
import altair as alt
|
| 2 |
-
import numpy as np
|
| 3 |
-
import pandas as pd
|
| 4 |
import streamlit as st
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import numpy as np
|
| 4 |
+
import joblib
|
| 5 |
+
|
| 6 |
+
# Load the Model
|
| 7 |
+
try:
|
| 8 |
+
model = joblib.load('src/introvert_model.joblib')
|
| 9 |
+
except FileNotFoundError:
|
| 10 |
+
st.error("Model file not found.")
|
| 11 |
+
st.stop()
|
| 12 |
+
|
| 13 |
+
# Page
|
| 14 |
+
st.set_page_config(page_title="Personality Predictor", page_icon="🧠")
|
| 15 |
+
|
| 16 |
+
st.title("🧠 Introvert vs. Extrovert Predictor")
|
| 17 |
+
st.write("This application predicts whether you are an **Introvert** or an **Extrovert** based on your social habits and preferences.")
|
| 18 |
+
|
| 19 |
+
# User Inputs
|
| 20 |
+
with st.sidebar:
|
| 21 |
+
st.header("Please Enter Your Details")
|
| 22 |
+
time_spent_alone = st.slider("Time Spent Alone (Hours/Day)", 0.0, 10.0, 3.5)
|
| 23 |
+
social_event_attendance = st.slider("Social Event Attendance (Frequency 0-10)", 0, 10, 5)
|
| 24 |
+
going_outside = st.slider("Frequency of Going Out (0-10)", 0, 10, 5)
|
| 25 |
+
friends_circle_size = st.number_input("Friends Circle Size", min_value=0, max_value=20, value=5)
|
| 26 |
+
post_frequency = st.slider("Social Media Post Frequency (0-10)", 0, 10, 2)
|
| 27 |
+
stage_fear_input = st.radio("Do you have Stage Fear?", ["Yes", "No"])
|
| 28 |
+
drained_input = st.radio("Do you feel drained after socializing?", ["Yes", "No"])
|
| 29 |
+
|
| 30 |
+
# Feature Engineering
|
| 31 |
+
stage_fear = 1 if stage_fear_input == "Yes" else 0
|
| 32 |
+
drained = 1 if drained_input == "Yes" else 0
|
| 33 |
+
social_to_alone_ratio = social_event_attendance / (time_spent_alone + 1)
|
| 34 |
+
social_volume = friends_circle_size * going_outside
|
| 35 |
+
|
| 36 |
+
# Create DataFrame
|
| 37 |
+
input_data = pd.DataFrame({
|
| 38 |
+
'Time_spent_Alone': [time_spent_alone],
|
| 39 |
+
'Stage_fear': [stage_fear],
|
| 40 |
+
'Social_event_attendance': [social_event_attendance],
|
| 41 |
+
'Going_outside': [going_outside],
|
| 42 |
+
'Drained_after_socializing': [drained],
|
| 43 |
+
'Friends_circle_size': [friends_circle_size],
|
| 44 |
+
'Post_frequency': [post_frequency],
|
| 45 |
+
'Social_to_Alone_Ratio': [social_to_alone_ratio],
|
| 46 |
+
'Social_Volume': [social_volume]})
|
| 47 |
+
|
| 48 |
+
# Prediction
|
| 49 |
+
st.subheader("Prediction Result")
|
| 50 |
+
if st.button("Analyze Personality"):
|
| 51 |
+
prediction = model.predict(input_data)[0]
|
| 52 |
+
if prediction == 1:
|
| 53 |
+
st.success("Result: **INTROVERT**")
|
| 54 |
+
st.info("You likely prefer staying in your own space and recharging your energy through solitude.")
|
| 55 |
+
else:
|
| 56 |
+
st.info("Result: **EXTROVERT**")
|
| 57 |
+
st.success("You likely gain energy from social environments and enjoy engaging with the outside world.")
|