handex commited on
Commit
5bc344c
·
verified ·
1 Parent(s): 0162271

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. 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
- # Welcome to Streamlit!
8
-
9
- Edit `/streamlit_app.py` to customize this app to your heart's desire :heart:.
10
- If you have any questions, checkout our [documentation](https://docs.streamlit.io) and [community
11
- forums](https://discuss.streamlit.io).
12
-
13
- In the meantime, below is an example of what you can do with just a few lines of code:
14
- """
15
-
16
- num_points = st.slider("Number of points in spiral", 1, 10000, 1100)
17
- num_turns = st.slider("Number of turns in spiral", 1, 300, 31)
18
-
19
- indices = np.linspace(0, 1, num_points)
20
- theta = 2 * np.pi * num_turns * indices
21
- radius = indices
22
-
23
- x = radius * np.cos(theta)
24
- y = radius * np.sin(theta)
25
-
26
- df = pd.DataFrame({
27
- "x": x,
28
- "y": y,
29
- "idx": indices,
30
- "rand": np.random.randn(num_points),
31
- })
32
-
33
- st.altair_chart(alt.Chart(df, height=700, width=700)
34
- .mark_point(filled=True)
35
- .encode(
36
- x=alt.X("x", axis=None),
37
- y=alt.Y("y", axis=None),
38
- color=alt.Color("idx", legend=None, scale=alt.Scale()),
39
- size=alt.Size("rand", legend=None, scale=alt.Scale(range=[1, 150])),
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.")