File size: 2,211 Bytes
d27fc20
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1318157
 
d27fc20
 
 
 
 
ba3e917
d27fc20
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# ----------------------
# Streamlit UI (Frontend)
# ----------------------
import requests
import streamlit as st

st.title("Introvert vs Extrovert Predictor")

# Single Prediction Section
st.subheader("Predict Personality Type for a Single Entry")

# Input fields
Time_spent_Alone = st.slider("Time Spent Alone (hours per day)", min_value=0, max_value=24, value=5)
Social_event_attendance = st.slider("Social Event Attendance (events per month)", min_value=0, max_value=30, value=5)
Going_outside = st.slider("Going Outside Frequency (days per week)", min_value=0, max_value=7, value=3)
Friends_circle_size = st.slider("Friends Circle Size", min_value=0, max_value=100, value=10)
Post_frequency = st.slider("Social Media Post Frequency (posts per week)", min_value=0, max_value=50, value=5)
Stage_fear = st.selectbox("Do you have stage fear?", ["Yes", "No"])
Drained_after_socializing = st.selectbox("Do you feel drained after socializing?", ["Yes", "No"])

API_BASE = "https://udbhav90-introvert-extrovert-predictor.hf.space"

if st.button("🔍 Predict Personality"):
    payload = {
        "Time_spent_Alone": Time_spent_Alone,
        "Social_event_attendance": Social_event_attendance,
        "Going_outside": Going_outside,
        "Friends_circle_size": Friends_circle_size,
        "Post_frequency": Post_frequency,
        "Stage_fear": Stage_fear,
        "Drained_after_socializing": Drained_after_socializing
    }

    res = requests.post(f"{API_BASE}/v1/personality/predict", json=payload)

    if res.status_code == 200:
        st.success(f" Predicted Personality Type: {res.json()['Predicted_Personality']}")
    else:
        st.error("Failed to get prediction. Check backend logs.")

# Batch Prediction
st.subheader("Batch CSV Prediction")

batch_file = st.file_uploader("Upload CSV file", type=["csv"])

if batch_file is not None and st.button("Predict Batch"):
    response = requests.post(f"{API_BASE}/v1/personality/predictbatch", files={"file": batch_file})
    if response.status_code == 200:
        result = response.json()
        st.write("Prediction Results:")
        st.dataframe(pd.DataFrame(result))
    else:
        st.error("Error from backend during batch prediction")