udbhav90's picture
Upload folder using huggingface_hub
ba3e917 verified
# ----------------------
# 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")