udbhav90 commited on
Commit
d27fc20
·
verified ·
1 Parent(s): 8feb8f4

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. Dockerfile +8 -11
  2. app.py +53 -0
  3. requirements.txt +3 -3
Dockerfile CHANGED
@@ -1,21 +1,18 @@
 
1
  FROM python:3.9-slim
2
 
 
3
  WORKDIR /app
4
 
5
- RUN apt-get update && apt-get install -y \
6
- build-essential \
7
- curl \
8
- software-properties-common \
9
- git \
10
- && rm -rf /var/lib/apt/lists/*
11
-
12
- COPY requirements.txt ./
13
- COPY src/ ./src/
14
 
 
15
  RUN pip3 install -r requirements.txt
16
 
17
  EXPOSE 8501
18
 
19
- HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health
 
20
 
21
- ENTRYPOINT ["streamlit", "run", "src/streamlit_app.py", "--server.port=8501", "--server.address=0.0.0.0"]
 
1
+ # Use a minimal base image with Python 3.9 installed
2
  FROM python:3.9-slim
3
 
4
+ # Set the working directory inside the container to /app
5
  WORKDIR /app
6
 
7
+ # Copy all files from the current directory on the host to the container's /app directory
8
+ COPY . .
 
 
 
 
 
 
 
9
 
10
+ # Install Python dependencies listed in requirements.txt
11
  RUN pip3 install -r requirements.txt
12
 
13
  EXPOSE 8501
14
 
15
+ # Define the command to run the Streamlit app on port 8501 and make it accessible externally
16
+ CMD ["streamlit", "run", "app.py", "--server.port=8501", "--server.address=0.0.0.0", "--server.enableXsrfProtection=false"]
17
 
18
+ # NOTE: Disable XSRF protection for easier external access in order to make batch predictions
app.py ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # ----------------------
2
+ # Streamlit UI (Frontend)
3
+ # ----------------------
4
+ import requests
5
+ import streamlit as st
6
+
7
+ st.title("Introvert vs Extrovert Predictor")
8
+
9
+ # Single Prediction Section
10
+ st.subheader("Predict Personality Type for a Single Entry")
11
+
12
+ # Input fields
13
+ Time_spent_Alone = st.slider("Time Spent Alone (hours per day)", min_value=0, max_value=24, value=5)
14
+ Social_event_attendance = st.slider("Social Event Attendance (events per month)", min_value=0, max_value=30, value=5)
15
+ Going_outside = st.slider("Going Outside Frequency (days per week)", min_value=0, max_value=7, value=3)
16
+ Friends_circle_size = st.slider("Friends Circle Size", min_value=0, max_value=100, value=10)
17
+ Post_frequency = st.slider("Social Media Post Frequency (posts per week)", min_value=0, max_value=50, value=5)
18
+ Stage_fear = st.selectbox("Do you have stage fear?", ["Yes", "No"])
19
+ Drained_after_socializing = st.selectbox("Do you feel drained after socializing?", ["Yes", "No"])
20
+
21
+ API_BASE = "https://udbhav90-introvert-extrovert-predictor.hf.space"
22
+
23
+ if st.button("🔍 Predict Personality"):
24
+ payload = {
25
+ "Time_spent_Alone": Time_spent_Alone,
26
+ "Social_event_attendance": Social_event_attendance,
27
+ "Going_outside": Going_outside,
28
+ "Friends_circle_size": Friends_circle_size,
29
+ "Post_frequency": Post_frequency,
30
+ "Stage_fear": 1 if Stage_fear.lower() == "yes" else 0,
31
+ "Drained_after_socializing": 1 if Drained_after_socializing.lower() == "yes" else 0
32
+ }
33
+
34
+ res = requests.post(f"{API_BASE}/v1/personality/predict", json=payload)
35
+
36
+ if res.status_code == 200:
37
+ st.success(f" Predicted Personality Type: {res.json()['Personality_Type']}")
38
+ else:
39
+ st.error("Failed to get prediction. Check backend logs.")
40
+
41
+ # Batch Prediction
42
+ st.subheader("Batch CSV Prediction")
43
+
44
+ batch_file = st.file_uploader("Upload CSV file", type=["csv"])
45
+
46
+ if batch_file is not None and st.button("Predict Batch"):
47
+ response = requests.post(f"{API_BASE}/v1/personality/predictbatch", files={"file": batch_file})
48
+ if response.status_code == 200:
49
+ result = response.json()
50
+ st.write("Prediction Results:")
51
+ st.dataframe(pd.DataFrame(result))
52
+ else:
53
+ st.error("Error from backend during batch prediction")
requirements.txt CHANGED
@@ -1,3 +1,3 @@
1
- altair
2
- pandas
3
- streamlit
 
1
+ pandas==2.2.2
2
+ requests==2.28.1
3
+ streamlit==1.43.2