Spaces:
Runtime error
Runtime error
Upload folder using huggingface_hub
Browse files- Dockerfile +9 -10
- app.py +60 -22
- requirements.txt +2 -2
Dockerfile
CHANGED
|
@@ -1,17 +1,16 @@
|
|
| 1 |
-
# Use
|
| 2 |
FROM python:3.9-slim
|
| 3 |
|
| 4 |
-
# Set the working directory
|
| 5 |
WORKDIR /app
|
| 6 |
|
| 7 |
-
# Copy the current directory
|
| 8 |
-
COPY .
|
| 9 |
|
| 10 |
-
# Install
|
| 11 |
-
RUN
|
| 12 |
|
| 13 |
-
#
|
| 14 |
-
|
| 15 |
|
| 16 |
-
#
|
| 17 |
-
CMD ["python", "app.py"]
|
|
|
|
| 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
CHANGED
|
@@ -1,33 +1,71 @@
|
|
| 1 |
|
| 2 |
-
import
|
| 3 |
-
import
|
| 4 |
-
import
|
| 5 |
|
| 6 |
-
|
| 7 |
-
model = joblib.load('tuned_random_forest_model.pkl') # Replace with the actual model filename
|
| 8 |
|
| 9 |
-
|
| 10 |
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
-
@app.route('/predict', methods=['POST'])
|
| 16 |
-
def predict():
|
| 17 |
try:
|
| 18 |
-
#
|
| 19 |
-
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
-
|
| 23 |
-
|
|
|
|
|
|
|
| 24 |
|
| 25 |
-
|
| 26 |
-
|
|
|
|
| 27 |
|
| 28 |
except Exception as e:
|
| 29 |
-
|
| 30 |
|
| 31 |
-
if __name__ == '__main__':
|
| 32 |
-
# Run the Flask app
|
| 33 |
-
app.run(host='0.0.0.0', port=5000)
|
|
|
|
| 1 |
|
| 2 |
+
import streamlit as st
|
| 3 |
+
import requests
|
| 4 |
+
import json
|
| 5 |
|
| 6 |
+
st.title("Lead Conversion Prediction")
|
|
|
|
| 7 |
|
| 8 |
+
st.write("Enter the lead details to predict conversion likelihood.")
|
| 9 |
|
| 10 |
+
# Input fields for lead features (replace with your actual features)
|
| 11 |
+
age = st.number_input("Age", min_value=0)
|
| 12 |
+
current_occupation = st.selectbox("Current Occupation", ['Professional', 'Unemployed', 'Student'])
|
| 13 |
+
first_interaction = st.selectbox("First Interaction", ['Website', 'Mobile App'])
|
| 14 |
+
profile_completed = st.selectbox("Profile Completed", ['Low', 'Medium', 'High'])
|
| 15 |
+
website_visits = st.number_input("Website Visits", min_value=0)
|
| 16 |
+
time_spent_on_website = st.number_input("Time Spent on Website (seconds)", min_value=0)
|
| 17 |
+
page_views_per_visit = st.number_input("Page Views per Visit", min_value=0.0)
|
| 18 |
+
last_activity = st.selectbox("Last Activity", ['Email Activity', 'Website Activity', 'Phone Activity'])
|
| 19 |
+
print_media_type1 = st.selectbox("Print Media Type 1", ['Yes', 'No'])
|
| 20 |
+
print_media_type2 = st.selectbox("Print Media Type 2", ['Yes', 'No'])
|
| 21 |
+
digital_media = st.selectbox("Digital Media", ['Yes', 'No'])
|
| 22 |
+
educational_channels = st.selectbox("Educational Channels", ['Yes', 'No'])
|
| 23 |
+
referral = st.selectbox("Referral", ['Yes', 'No'])
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
# Create a dictionary with the input data
|
| 27 |
+
input_data = {
|
| 28 |
+
'age': [age],
|
| 29 |
+
'current_occupation': [current_occupation],
|
| 30 |
+
'first_interaction': [first_interaction],
|
| 31 |
+
'profile_completed': [profile_completed],
|
| 32 |
+
'website_visits': [website_visits],
|
| 33 |
+
'time_spent_on_website': [time_spent_on_website],
|
| 34 |
+
'page_views_per_visit': [page_views_per_visit],
|
| 35 |
+
'last_activity': [last_activity],
|
| 36 |
+
'print_media_type1': [print_media_type1],
|
| 37 |
+
'print_media_type2': [print_media_type2],
|
| 38 |
+
'digital_media': [digital_media],
|
| 39 |
+
'educational_channels': [educational_channels],
|
| 40 |
+
'referral': [referral]
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
# Convert input data to a list of dictionaries (required by the backend)
|
| 44 |
+
input_data_list = [dict(zip(input_data, t)) for t in zip(*input_data.values())]
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
# Button to trigger prediction
|
| 48 |
+
if st.button("Predict Conversion"):
|
| 49 |
+
# Replace with the URL of your deployed backend API
|
| 50 |
+
backend_url = "YOUR_BACKEND_API_URL/predict" # e.g., "https://your-username-your-backend-space.hf.space/predict"
|
| 51 |
|
|
|
|
|
|
|
| 52 |
try:
|
| 53 |
+
# Send a POST request to the backend API
|
| 54 |
+
response = requests.post(backend_url, json=input_data_list)
|
| 55 |
+
|
| 56 |
+
if response.status_code == 200:
|
| 57 |
+
predictions = response.json()
|
| 58 |
+
prediction = predictions[0] # Assuming the backend returns a list with a single prediction
|
| 59 |
|
| 60 |
+
if prediction == 1:
|
| 61 |
+
st.success("This lead is likely to convert!")
|
| 62 |
+
else:
|
| 63 |
+
st.warning("This lead is less likely to convert.")
|
| 64 |
|
| 65 |
+
else:
|
| 66 |
+
st.error(f"Error from backend: {response.status_code}")
|
| 67 |
+
st.error(response.text)
|
| 68 |
|
| 69 |
except Exception as e:
|
| 70 |
+
st.error(f"An error occurred: {e}")
|
| 71 |
|
|
|
|
|
|
|
|
|
requirements.txt
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
pandas==2.2.2
|
| 4 |
scikit-learn==1.6.1
|
|
|
|
| 1 |
+
streamlit==1.36.0
|
| 2 |
+
requests==2.32.3
|
| 3 |
pandas==2.2.2
|
| 4 |
scikit-learn==1.6.1
|