Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files- Dockerfile +8 -13
- app.py +47 -0
- requirements.txt +2 -3
Dockerfile
CHANGED
|
@@ -1,21 +1,16 @@
|
|
|
|
|
| 1 |
FROM python:3.9-slim
|
| 2 |
|
|
|
|
| 3 |
WORKDIR /app
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
| 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 |
-
|
| 18 |
-
|
| 19 |
-
HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health
|
| 20 |
|
| 21 |
-
|
|
|
|
| 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,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import streamlit as st
|
| 3 |
+
import requests
|
| 4 |
+
|
| 5 |
+
st.title("Lead Prediction System")
|
| 6 |
+
|
| 7 |
+
# Input fields
|
| 8 |
+
age = st.number_input("Age", min_value=0, value=25)
|
| 9 |
+
current_occupation = st.selectbox("Current Occupation", ["Professional", "Unemployed", "Student"])
|
| 10 |
+
first_interaction = st.selectbox("First Interaction Platform", ["Website", "Mobile App"])
|
| 11 |
+
profile_completed = st.selectbox("Profile Completion Level", ["Low", "Medium", "High"])
|
| 12 |
+
website_visits = st.number_input("Number of Website Visits", min_value=0, value=3)
|
| 13 |
+
time_spent_on_website = st.number_input("Time Spent on Website (in seconds)", min_value=0.0, value=180.0)
|
| 14 |
+
page_views_per_visit = st.number_input("Page Views per Visit", min_value=0.0, value=4.5)
|
| 15 |
+
last_activity = st.selectbox("Last Activity Type", ["Email Activity", "Phone Activity", "Website Activity"])
|
| 16 |
+
print_media_type1 = st.selectbox("Seen Newspaper Ad?", ["Yes", "No"])
|
| 17 |
+
print_media_type2 = st.selectbox("Seen Magazine Ad?", ["Yes", "No"])
|
| 18 |
+
digital_media = st.selectbox("Seen Digital Media Ad?", ["Yes", "No"])
|
| 19 |
+
educational_channels = st.selectbox("Heard via Educational Channels?", ["Yes", "No"])
|
| 20 |
+
referral = st.selectbox("Heard via Referral?", ["Yes", "No"])
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
lead_data = {
|
| 24 |
+
"age": age,
|
| 25 |
+
"current_occupation": current_occupation,
|
| 26 |
+
"first_interaction": first_interaction,
|
| 27 |
+
"profile_completed": profile_completed,
|
| 28 |
+
"website_visits": website_visits,
|
| 29 |
+
"time_spent_on_website": time_spent_on_website,
|
| 30 |
+
"page_views_per_visit": page_views_per_visit,
|
| 31 |
+
"last_activity": last_activity,
|
| 32 |
+
"print_media_type1": print_media_type1,
|
| 33 |
+
"print_media_type2": print_media_type2,
|
| 34 |
+
"digital_media": digital_media,
|
| 35 |
+
"educational_channels": educational_channels,
|
| 36 |
+
"referral": referral
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
if st.button("Predict", type='primary'):
|
| 41 |
+
response = requests.post("https://HarishMaths-Learn-Model-API.hf.space/v1/predict", json=product_data) # Replace <user_name> and <space_name>
|
| 42 |
+
if response.status_code == 200:
|
| 43 |
+
result = response.json()
|
| 44 |
+
predicted_value = result["Lead"]
|
| 45 |
+
st.write("Predicted :",predicted_value)
|
| 46 |
+
else:
|
| 47 |
+
st.error("Error in API request")
|
requirements.txt
CHANGED
|
@@ -1,3 +1,2 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
streamlit
|
|
|
|
| 1 |
+
requests==2.32.3
|
| 2 |
+
streamlit==1.45.0
|
|
|