Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files- Dockerfile +9 -13
- app.py +51 -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,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import streamlit as st
|
| 3 |
+
import pandas as pd
|
| 4 |
+
import requests
|
| 5 |
+
|
| 6 |
+
# Set the title of the Streamlit app
|
| 7 |
+
st.title("ExtraaLearn Prediction")
|
| 8 |
+
|
| 9 |
+
# Section for online prediction
|
| 10 |
+
st.subheader("Online Prediction")
|
| 11 |
+
|
| 12 |
+
# Input fields for Lead data
|
| 13 |
+
Age = st.number_input("Age", min_value=0, value=99)
|
| 14 |
+
Current_Occupation = st.selectbox("Current Occupation", ["Professional", "Student", "Unemployed"])
|
| 15 |
+
First_Interaction = st.selectbox("First Interaction", ["Website", "Mobile App"])
|
| 16 |
+
Profile_Completed = st.selectbox("Profile Completed", ["High", "Medium", "Low"])
|
| 17 |
+
Website_Visits = st.number_input("Website Visits", min_value=0, value=99)
|
| 18 |
+
Time_Spent_on_Website = st.number_input("Time Spent on Website")
|
| 19 |
+
Page_Views_Per_Visit = st.number_input("Page Views Per Visit", min_value=0.000, value=99.000)
|
| 20 |
+
Last_Activity = st.selectbox("Last Activity", ["Website Activity", "Email Activity", "Phone Activity"])
|
| 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 |
+
|
| 27 |
+
# Convert user input into a DataFrame
|
| 28 |
+
input_data = pd.DataFrame([{
|
| 29 |
+
"Age": Age,
|
| 30 |
+
"Current_Occupation": Current_Occupation,
|
| 31 |
+
"First_Interaction": First_Interaction,
|
| 32 |
+
"Profile_Completed": Profile_Completed,
|
| 33 |
+
"Website_Visits": Website_Visits,
|
| 34 |
+
"Time_Spent_on_Website": Time_Spent_on_Website,
|
| 35 |
+
"Page_Views_Per_Visit": Page_Views_Per_Visit,
|
| 36 |
+
"Last_Activity": Last_Activity,
|
| 37 |
+
"Print_Media_Type1": Print_Media_Type1,
|
| 38 |
+
"Print_Media_Type2": Print_Media_Type2,
|
| 39 |
+
"Digital_Media": Digital_Media,
|
| 40 |
+
"Educational_Channels": Educational_Channels,
|
| 41 |
+
"Referral": Referral
|
| 42 |
+
}])
|
| 43 |
+
|
| 44 |
+
# Make prediction when the "Predict" button is clicked
|
| 45 |
+
if st.button("Predict"):
|
| 46 |
+
response = requests.post("https://vijayendras-ExtraaLearnBackend.hf.space/v1/predict", json=input_data.to_dict(orient='records')[0]) # Send data to Flask API
|
| 47 |
+
if response.status_code == 200:
|
| 48 |
+
prediction = response.json()['Predicted Sales Conversion Status (0/1)']
|
| 49 |
+
st.success(f"Predicted Sales Conversion Status (0/1): {prediction}")
|
| 50 |
+
else:
|
| 51 |
+
st.error("Error making 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
|