Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files- Dockerfile +23 -0
- app.py +67 -0
- requirements.txt +7 -0
Dockerfile
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Use a minimal base image with Python 3.9 installed
|
| 2 |
+
FROM python:3.9
|
| 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 |
+
RUN useradd -m -u 1000 user
|
| 14 |
+
USER user
|
| 15 |
+
ENV HOME=/home/user \
|
| 16 |
+
PATH=/home/user/.local/bin:$PATH
|
| 17 |
+
|
| 18 |
+
WORKDIR $HOME/app
|
| 19 |
+
|
| 20 |
+
COPY --chown=user . $HOME/app
|
| 21 |
+
|
| 22 |
+
# Define the command to run the Streamlit app on port "8501" and make it accessible externally
|
| 23 |
+
CMD ["streamlit", "run", "app.py", "--server.port=8501", "--server.address=0.0.0.0", "--server.enableXsrfProtection=false"]
|
app.py
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
from huggingface_hub import hf_hub_download
|
| 4 |
+
import joblib
|
| 5 |
+
|
| 6 |
+
# Download the model from the Model Hub
|
| 7 |
+
model_path = hf_hub_download(repo_id="Georgek17/vistit-predictor-model", filename="best_visit_predictor_model_v1.joblib")
|
| 8 |
+
|
| 9 |
+
# Load the model
|
| 10 |
+
model = joblib.load(model_path)
|
| 11 |
+
|
| 12 |
+
# Streamlit UI for Customer Churn Prediction
|
| 13 |
+
st.title("Customer visit Prediction App")
|
| 14 |
+
st.write("The Customer visit Prediction App is an internal tool for predicts whether customer will purchase the newly introduced Wellness Tourism Package before contacting them based on their details.")
|
| 15 |
+
st.write("Kindly enter the customer details to check whether they are likely to purchase the Wellness Tourism Package.")
|
| 16 |
+
|
| 17 |
+
# Collect user input
|
| 18 |
+
Age = st.number_input("Age (customer's age in years)", min_value=18, max_value=100, value=30)
|
| 19 |
+
TypeofContact = st.selectbox("Type of Contact (method by which the customer was contacted)", ["Self Enquiry", "Company Invited"])
|
| 20 |
+
CityTier= st.selectbox("City Tier (The city category based on development, population, and living standards)", ["1", "2", "3"])
|
| 21 |
+
DurationOfPitch = st.number_input("DurationOfPitch (Duration of the sales pitch delivered to the customer.)", min_value=1, value=14)
|
| 22 |
+
Occupation= st.selectbox("Occupation", ["Free Lancer", "Large Business", "Salaried", "Small Business"])
|
| 23 |
+
Gender= st.selectbox("Gender", ["Female", "Male"])
|
| 24 |
+
NumberOfPersonVisiting= st.number_input("Number Of PersonVisiting (Total number of people accompanying the customer on the trip.)", value=3)
|
| 25 |
+
NumberOfFollowups= st.number_input("Number Of Followups (Total number of follow-ups by the salesperson after the sales pitch.)", value=3)
|
| 26 |
+
ProductPitched= st.selectbox("Product Pitched (The type of product pitched to the customer.)", ["Basic", "Deluxe", "King", "Standard", "Super Deluxe"])
|
| 27 |
+
PreferredPropertyStar= st.selectbox("Preferred Property Star (Preferred hotel rating by the customer.)", ["1", "2", "3", "4", "5"])
|
| 28 |
+
MaritalStatus= st.selectbox("Marital Status", ["Divorced", "Married", "Single", "Unmarried"])
|
| 29 |
+
NumberOfTrips= st.number_input("Number Of Trips (Average number of trips the customer takes annually.)", min_value=1, value=2)
|
| 30 |
+
Passport= st.selectbox("Has Passport? (Whether the customer holds a valid passport (0: No, 1: Yes).)", ["0", "1"])
|
| 31 |
+
PitchSatisfactionScore= st.selectbox("Pitch Satisfaction Score (Score indicating the customer's satisfaction with the sales pitch.)", ["1", "2", "3", "4", "5"])
|
| 32 |
+
OwnCar= st.selectbox("Own Car? (Whether the customer owns a car (0: No, 1: Yes).)", ["0", "1"])
|
| 33 |
+
NumberOfChildrenVisiting= st.number_input("Number Of Children Visiting)", value=1)
|
| 34 |
+
Designation= st.selectbox("Designation (Customer's designation in their current organization.)", ["AVP", "Executive", "Manager", "Senior Manager", "VP"])
|
| 35 |
+
MonthlyIncome = st.number_input("Monthly Income (Gross monthly income of the customer.)", min_value=0, value=1700)
|
| 36 |
+
|
| 37 |
+
# Convert categorical inputs to match model training
|
| 38 |
+
input_data = pd.DataFrame([{
|
| 39 |
+
'Age': Age,
|
| 40 |
+
'TypeofContact': TypeofContact,
|
| 41 |
+
'CityTier': CityTier,
|
| 42 |
+
'DurationOfPitch': DurationOfPitch,
|
| 43 |
+
'Occupation': Occupation,
|
| 44 |
+
'Gender': Gender,
|
| 45 |
+
'NumberOfPersonVisiting': NumberOfPersonVisiting,
|
| 46 |
+
'NumberOfFollowups':NumberOfFollowups,
|
| 47 |
+
'ProductPitched': ProductPitched,
|
| 48 |
+
'PreferredPropertyStar' : PreferredPropertyStar,
|
| 49 |
+
'MaritalStatus' : MaritalStatus,
|
| 50 |
+
'NumberOfTrips' : NumberOfTrips,
|
| 51 |
+
'Passport' : Passport,
|
| 52 |
+
'PitchSatisfactionScore' : PitchSatisfactionScore,
|
| 53 |
+
'OwnCar' : OwnCar,
|
| 54 |
+
'NumberOfChildrenVisiting' : NumberOfChildrenVisiting,
|
| 55 |
+
'Designation' : Designation,
|
| 56 |
+
'MonthlyIncome' : MonthlyIncome
|
| 57 |
+
}])
|
| 58 |
+
|
| 59 |
+
# Set the classification threshold
|
| 60 |
+
classification_threshold = 0.45
|
| 61 |
+
|
| 62 |
+
# Predict button
|
| 63 |
+
if st.button("Predict"):
|
| 64 |
+
prediction_proba = model.predict_proba(input_data)[0, 1]
|
| 65 |
+
prediction = (prediction_proba >= classification_threshold).astype(int)
|
| 66 |
+
result = "purchase the Wellness Tourism Package " if prediction == 1 else "not purchase the Wellness Tourism Package"
|
| 67 |
+
st.write(f"Based on the information provided, the customer is likely to {result}.")
|
requirements.txt
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
pandas==2.2.2
|
| 2 |
+
huggingface_hub==0.32.6
|
| 3 |
+
streamlit==1.43.2
|
| 4 |
+
joblib==1.5.1
|
| 5 |
+
scikit-learn==1.6.0
|
| 6 |
+
xgboost==2.1.4
|
| 7 |
+
mlflow==3.0.1
|