SilviaMartin commited on
Commit
301d65e
·
verified ·
1 Parent(s): f438296

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. Dockerfile +15 -12
  2. app.py +68 -0
  3. requirements.txt +5 -3
Dockerfile CHANGED
@@ -1,20 +1,23 @@
1
- FROM python:3.13.5-slim
 
2
 
 
3
  WORKDIR /app
4
 
5
- RUN apt-get update && apt-get install -y \
6
- build-essential \
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
- EXPOSE 8501
 
 
 
 
 
17
 
18
- HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health
19
 
20
- ENTRYPOINT ["streamlit", "run", "src/streamlit_app.py", "--server.port=8501", "--server.address=0.0.0.0"]
 
 
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,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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="SilviaMartin/Visitwithus", filename="visit_with_us_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 Purchase Prediction App")
14
+ st.write("The Customer Purchase Prediction App predicts whether customers will purchase the newly introduced Wellness Tourism Package before contacting them")
15
+ st.write("Kindly enter the customer details to check whether they are likely to purchase.")
16
+
17
+ # Collect user input
18
+ Age = st.number_input("Customer Age", min_value=18, max_value=61, value=40)
19
+ CityTier = st.number_input("The city tier of customer ", min_value=1, max_value=3, value=2)
20
+ DurationOfPitch = st.number_input("The duration of the pitch",min_value=5,max_value=127 value=20)
21
+ NumberOfPersonVisiting = st.number_input("Number of persons visiting", min_value=1, max_value=5, value=2)
22
+ NumberOfFollowups = st.number_input("Number of followups", min_value=1, max_value=10, value=2)
23
+ PreferredPropertyStar = st.number_input("The preferred property star rating", min_value=3, max_value=5, value=3)
24
+ NumberOfTrips = st.number_input("Number of trips", min_value=1, max_value=22, value=2)
25
+ Passport = st.number_input("Having Passport?", [0, 1])
26
+ OwnCar = st.number_input("Having Car?", [0, 1])
27
+ NumberOfChildrenVisiting = st.number_input("Number of children visiting", min_value=0, max_value=3, value=2)
28
+ MonthlyIncome=st.number_input("Specify the monthly income",min_value=1000,max_value=100000,value=3000)
29
+ PitchSatisfactionScore = st.number_input("Pitch Satisfaction Score", min_value=1, max_value=5, value=3)
30
+ TypeofContact=st.selectbox("Mention the type of contact", ["Company Invited","Self Enquiry"])
31
+ Occupation = st.selectbox("Occupation", ["Free Lancer","Large Business","Salaried","Small Business"])
32
+ Gender = st.selectbox("Customer Gender", ["Female","Male"])
33
+ ProductPitched=st.selectbox("Mention the product pitched to customer", ["Basic","Deluxe","Standard","King","Super Deluxe"])
34
+ MaritialStatus=st.selectbox("Mention the marital status of customer", ["Single","Married","Unmarried","Divorced"])
35
+ Designation=st.selectbox("Mention the designation of customer", ["Executive","Manager","Senior Manager","VP","AVP"])
36
+
37
+
38
+ # Convert categorical inputs to match model training
39
+ input_data = pd.DataFrame([{
40
+ 'Age': Age,
41
+ 'CityTier': CityTier,
42
+ 'DurationOfPitch': DurationOfPitch,
43
+ 'NumberOfPersonVisiting': NumberOfPersonVisiting,
44
+ 'NumberOfFollowups': NumberOfFollowups,
45
+ 'PreferredPropertyStar': PreferredPropertyStar,
46
+ 'NumberOfTrips':NumberOfTrips,
47
+ 'Passport':Passport,
48
+ 'OwnCar':OwnCar,
49
+ 'NumberOfChildrenVisiting':NumberOfChildrenVisiting,
50
+ 'MonthlyIncome':MonthlyIncome,
51
+ 'PitchSatisfactionScore':PitchSatisfactionScore,
52
+ 'TypeofContact': TypeofContact,
53
+ 'Occupation': Occupation,
54
+ 'Gender': Gender,
55
+ 'ProductPitched': ProductPitched,
56
+ 'MaritalStatus': MaritialStatus,
57
+ 'Designation': Designation
58
+ }])
59
+
60
+ # Set the classification threshold
61
+ classification_threshold = 0.45
62
+
63
+ # Predict button
64
+ if st.button("Predict"):
65
+ prediction_proba = model.predict_proba(input_data)[0, 1]
66
+ prediction = (prediction_proba >= classification_threshold).astype(int)
67
+ result = "Product Purchased" if prediction == 1 else "Not Purchased"
68
+ st.write(f"Based on the information provided, the customer is likely to {result}.")
requirements.txt CHANGED
@@ -1,3 +1,5 @@
1
- altair
2
- pandas
3
- streamlit
 
 
 
1
+ huggingface_hub==0.32.6
2
+ datasets==3.6.0
3
+ pandas==2.2.2
4
+ scikit-learn==1.6.0
5
+ xgboost==2.1.4