Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files- Dockerfile +9 -13
- app.py +71 -0
- requirements.txt +3 -3
Dockerfile
CHANGED
|
@@ -1,20 +1,16 @@
|
|
| 1 |
-
|
|
|
|
| 2 |
|
|
|
|
| 3 |
WORKDIR /app
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
curl \
|
| 8 |
-
git \
|
| 9 |
-
&& rm -rf /var/lib/apt/lists/*
|
| 10 |
-
|
| 11 |
-
COPY requirements.txt ./
|
| 12 |
-
COPY src/ ./src/
|
| 13 |
|
|
|
|
| 14 |
RUN pip3 install -r requirements.txt
|
| 15 |
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health
|
| 19 |
|
| 20 |
-
|
|
|
|
| 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 |
+
# Define the command to run the Streamlit app on port 8501 and make it accessible externally
|
| 14 |
+
CMD ["streamlit", "run", "app.py", "--server.port=8501", "--server.address=0.0.0.0", "--server.enableXsrfProtection=false"]
|
|
|
|
| 15 |
|
| 16 |
+
# NOTE: Disable XSRF protection for easier external access in order to make batch predictions
|
app.py
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import requests
|
| 4 |
+
|
| 5 |
+
# Set the title of the Streamlit app
|
| 6 |
+
st.title("ExtraaLearn Status Prediction")
|
| 7 |
+
|
| 8 |
+
# Section for online prediction
|
| 9 |
+
st.subheader("Online Prediction")
|
| 10 |
+
|
| 11 |
+
# Collect user input for ExtraaLearn features
|
| 12 |
+
id_val = st.text_input("ID")
|
| 13 |
+
age = st.number_input("Age", min_value=0, max_value=100, step=1, value=25)
|
| 14 |
+
current_occupation = st.selectbox("Current Occupation", ["Student", "Professional", "Unemployed", "Other"])
|
| 15 |
+
first_interaction = st.selectbox("First Interaction", ["Website", "Mobile App"])
|
| 16 |
+
profile_completed = st.selectbox("Profile Completed", ["Low", "Medium", "High"])
|
| 17 |
+
website_visits = st.number_input("Website Visits", min_value=0, step=1, value=1)
|
| 18 |
+
time_spent_on_website = st.number_input("Time Spent on Website (seconds)", min_value=0, step=1, value=10)
|
| 19 |
+
page_views_per_visit = st.number_input("Page Views per Visit", min_value=0.0, step=0.1, value=1.0)
|
| 20 |
+
last_activity = st.selectbox("Last Activity", ["Website Activity", "Email Activity", "Phone Activity", "Other"])
|
| 21 |
+
print_media_type1 = st.selectbox("Print Media Type1", ["Yes", "No"])
|
| 22 |
+
print_media_type2 = st.selectbox("Print Media Type2", ["Yes", "No"])
|
| 23 |
+
digital_media = st.selectbox("Digital Media", ["Yes", "No"])
|
| 24 |
+
educational_channels = st.selectbox("Educational Channels", ["Yes", "No"])
|
| 25 |
+
referral = st.selectbox("Referral", ["Yes", "No"])
|
| 26 |
+
status = st.selectbox("Status", [0, 1]) # 0 = Not converted, 1 = Converted
|
| 27 |
+
|
| 28 |
+
# Convert user input into a DataFrame
|
| 29 |
+
input_data = pd.DataFrame([{
|
| 30 |
+
'ID': id_val,
|
| 31 |
+
'age': age,
|
| 32 |
+
'current_occupation': current_occupation,
|
| 33 |
+
'first_interaction': first_interaction,
|
| 34 |
+
'profile_completed': profile_completed,
|
| 35 |
+
'website_visits': website_visits,
|
| 36 |
+
'time_spent_on_website': time_spent_on_website,
|
| 37 |
+
'page_views_per_visit': page_views_per_visit,
|
| 38 |
+
'last_activity': last_activity,
|
| 39 |
+
'print_media_type1': print_media_type1,
|
| 40 |
+
'print_media_type2': print_media_type2,
|
| 41 |
+
'digital_media': digital_media,
|
| 42 |
+
'educational_channels': educational_channels,
|
| 43 |
+
'referral': referral,
|
| 44 |
+
'status': status
|
| 45 |
+
}])
|
| 46 |
+
|
| 47 |
+
# Make prediction when the "Predict" button is clicked
|
| 48 |
+
if st.button("Predict"):
|
| 49 |
+
response = requests.post("https://BabuRayapati-ExtraalearnFrontendDocker.hf.space/v1/extraalearn", json=input_data.to_dict(orient='records')[0]) # Send data to Flask API
|
| 50 |
+
if response.status_code == 200:
|
| 51 |
+
prediction = response.json()['Predicted status (in dollars)']
|
| 52 |
+
st.success(f"Predicted Product Status (in dollars): {prediction}")
|
| 53 |
+
else:
|
| 54 |
+
st.error("Error making prediction.")
|
| 55 |
+
|
| 56 |
+
# Section for batch prediction
|
| 57 |
+
st.subheader("Batch Prediction")
|
| 58 |
+
|
| 59 |
+
# Allow users to upload a CSV file for batch prediction
|
| 60 |
+
uploaded_file = st.file_uploader("Upload CSV file for batch prediction", type=["csv"])
|
| 61 |
+
|
| 62 |
+
# Make batch prediction when the "Predict Batch" button is clicked
|
| 63 |
+
if uploaded_file is not None:
|
| 64 |
+
if st.button("Predict Batch"):
|
| 65 |
+
response = requests.post("https://BabuRayapati-ExtraalearnFrontendDocker.hf.space/v1/extraalearnbatch", files={"file": uploaded_file}) # Send file to Flask API
|
| 66 |
+
if response.status_code == 200:
|
| 67 |
+
predictions = response.json()
|
| 68 |
+
st.success("Batch predictions completed!")
|
| 69 |
+
st.write(predictions) # Display the predictions
|
| 70 |
+
else:
|
| 71 |
+
st.error("Error making batch prediction.")
|
requirements.txt
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
streamlit
|
|
|
|
| 1 |
+
pandas==2.2.2
|
| 2 |
+
requests==2.28.1
|
| 3 |
+
streamlit==1.43.2
|