affanthinks commited on
Commit
c6505c9
·
verified ·
1 Parent(s): 959d7ed

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. Dockerfile +15 -12
  2. app.py +112 -0
  3. requirements.txt +7 -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,112 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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="affanthinks/Tourism-Package-Prediction", filename="best_tourism_pred_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("tourism Prediction App")
14
+ st.write("The tourism Prediction App is an internal tool for tourism staff that predicts whether customers are purchasing the product based on their details and pitch.")
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("Age (Age of the customer)", min_value=0, max_value=120, value=30)
19
+
20
+ TypeofContact = st.selectbox(
21
+ "Type of Contact (how the customer was contacted)",
22
+ ["Company Invited", "Self Inquiry"]
23
+ )
24
+
25
+ CityTier = st.selectbox(
26
+ "City Tier (city category based on development)",
27
+ [1, 2, 3]
28
+ )
29
+
30
+ Occupation = st.selectbox(
31
+ "Occupation (customer’s occupation)",
32
+ ["Salaried", "Self Employed", "Freelancer", "Student", "Housewife", "Other"]
33
+ )
34
+
35
+ Gender = st.selectbox(
36
+ "Gender",
37
+ ["Male", "Female"]
38
+ )
39
+
40
+ NumberOfPersonVisiting = st.number_input(
41
+ "Number of Persons Visiting (including the customer)",
42
+ min_value=1, max_value=20, value=2
43
+ )
44
+
45
+ PreferredPropertyStar = st.selectbox(
46
+ "Preferred Property Star Rating",
47
+ [1, 2, 3, 4, 5]
48
+ )
49
+
50
+ MaritalStatus = st.selectbox(
51
+ "Marital Status",
52
+ ["Single", "Married", "Divorced"]
53
+ )
54
+
55
+ NumberOfTrips = st.number_input(
56
+ "Number of Trips Annually",
57
+ min_value=0, max_value=50, value=1
58
+ )
59
+
60
+ Passport = st.selectbox(
61
+ "Passport (Does the customer hold a passport?)",
62
+ ["Yes", "No"]
63
+ )
64
+
65
+ OwnCar = st.selectbox(
66
+ "Own Car (Does the customer own a car?)",
67
+ ["Yes", "No"]
68
+ )
69
+
70
+ NumberOfChildrenVisiting = st.number_input(
71
+ "Number of Children Visiting (below age 5)",
72
+ min_value=0, max_value=10, value=0
73
+ )
74
+
75
+ Designation = st.selectbox(
76
+ "Designation in Current Organization",
77
+ ["Executive", "Manager", "Senior Manager", "AVP", "VP", "Other"]
78
+ )
79
+
80
+ MonthlyIncome = st.number_input(
81
+ "Monthly Income (Gross monthly income)",
82
+ min_value=0.0, value=50000.0
83
+ )
84
+
85
+ # Convert categorical + numeric inputs into a dataframe that matches the model training
86
+ input_data = pd.DataFrame([{
87
+ 'Age': Age,
88
+ 'TypeofContact': TypeofContact,
89
+ 'CityTier': CityTier,
90
+ 'Occupation': Occupation,
91
+ 'Gender': Gender,
92
+ 'NumberOfPersonVisiting': NumberOfPersonVisiting,
93
+ 'PreferredPropertyStar': PreferredPropertyStar,
94
+ 'MaritalStatus': MaritalStatus,
95
+ 'NumberOfTrips': NumberOfTrips,
96
+ 'Passport': 1 if Passport == "Yes" else 0,
97
+ 'OwnCar': 1 if OwnCar == "Yes" else 0,
98
+ 'NumberOfChildrenVisiting': NumberOfChildrenVisiting,
99
+ 'Designation': Designation,
100
+ 'MonthlyIncome': MonthlyIncome
101
+ }])
102
+
103
+
104
+ # Set the classification threshold
105
+ classification_threshold = 0.45
106
+
107
+ # Predict button
108
+ if st.button("Predict"):
109
+ prediction_proba = model.predict_proba(input_data)[0, 1]
110
+ prediction = (prediction_proba >= classification_threshold).astype(int)
111
+ result = "purchase" if prediction == 1 else "not purchase"
112
+ st.write(f"Based on the information provided, the customer is likely to {result}.")
requirements.txt CHANGED
@@ -1,3 +1,7 @@
1
- altair
2
- pandas
3
- streamlit
 
 
 
 
 
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