subratm62 commited on
Commit
18aa42a
·
verified ·
1 Parent(s): 4fd3ec9

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. Dockerfile +23 -0
  2. app.py +114 -0
  3. requirements.txt +6 -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,114 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import joblib
4
+ from huggingface_hub import hf_hub_download
5
+
6
+ st.set_page_config(page_title="Wellness Tourism Package Purchase Predictor", layout="centered")
7
+
8
+ # ------------------------------
9
+ # Load Model + Threshold from Hugging Face Hub
10
+ # ------------------------------
11
+
12
+ REPO_ID = "subratm62/tourism-project"
13
+
14
+ # Download model pipeline
15
+ model_path = hf_hub_download(repo_id=REPO_ID, filename="best_tourism_model.joblib")
16
+ model = joblib.load(model_path)
17
+
18
+ # Download threshold metadata (saved during training)
19
+ threshold_path = hf_hub_download(repo_id=REPO_ID, filename="chosen_threshold.txt")
20
+ with open(threshold_path, "r") as f:
21
+ classification_threshold = float(f.read().strip())
22
+
23
+ # ------------------------------
24
+ # Streamlit UI
25
+ # ------------------------------
26
+
27
+ st.title("Wellness Tourism Package Purchase Predictor")
28
+ st.write("Predict whether a customer is likely to purchase the **Wellness Tourism Package** based on their details.")
29
+
30
+ st.markdown("---")
31
+
32
+ # ------------------------------
33
+ # Create Input Form
34
+ # ------------------------------
35
+
36
+ st.subheader("Customer Information")
37
+
38
+ col1, col2 = st.columns(2)
39
+
40
+ with col1:
41
+ Age = st.number_input("Age", min_value=1, max_value=100, value=35)
42
+ TypeofContact = st.selectbox("Type of Contact", ["Self Enquiry", "Company Invited"])
43
+ CityTier = st.selectbox("City Tier", [1, 2, 3])
44
+ DurationOfPitch = st.number_input("Duration of Pitch (minutes)", min_value=0, max_value=60, value=10)
45
+ Occupation = st.selectbox("Occupation", ["Salaried", "Self Employed", "Business", "Free Lancer"])
46
+
47
+ with col2:
48
+ Gender = st.selectbox("Gender", ["Male", "Female"])
49
+ NumberOfPersonVisiting = st.number_input("Number Of Persons Visiting", min_value=1, max_value=10, value=2)
50
+ NumberOfFollowups = st.number_input("Number of Follow-ups", min_value=0, max_value=10, value=2)
51
+ PreferredPropertyStar = st.selectbox("Preferred Property Star", [3, 4, 5])
52
+ ProductPitched = st.selectbox("Product Pitched", ["Basic", "Deluxe", "Super Deluxe", "King", "Queen"])
53
+
54
+ st.markdown("---")
55
+
56
+ col3, col4 = st.columns(2)
57
+
58
+ with col3:
59
+ MaritalStatus = st.selectbox("Marital Status", ["Single", "Married", "Divorced"])
60
+ NumberOfTrips = st.number_input("Number of Trips per year", min_value=0, max_value=50, value=2)
61
+ Passport = st.selectbox("Passport Available?", ["Yes", "No"])
62
+
63
+ with col4:
64
+ PitchSatisfactionScore = st.slider("Pitch Satisfaction Score", 1, 5, 3)
65
+ OwnCar = st.selectbox("Owns a Car?", ["Yes", "No"])
66
+ NumberOfChildrenVisiting = st.number_input("Number of Children Visiting", min_value=0, max_value=10, value=0)
67
+ Designation = st.selectbox("Designation", ["Executive", "Manager", "Senior Manager", "AVP"])
68
+
69
+ MonthlyIncome = st.number_input("Monthly Income (₹)", min_value=0.0, value=25000.0)
70
+
71
+ st.markdown("---")
72
+
73
+ # ------------------------------
74
+ # Prepare input for model
75
+ # ------------------------------
76
+
77
+ input_data = pd.DataFrame([{
78
+ "Age": Age,
79
+ "CityTier": CityTier,
80
+ "DurationOfPitch": DurationOfPitch,
81
+ "NumberOfPersonVisiting": NumberOfPersonVisiting,
82
+ "NumberOfFollowups": NumberOfFollowups,
83
+ "PreferredPropertyStar": PreferredPropertyStar,
84
+ "NumberOfTrips": NumberOfTrips,
85
+ "PitchSatisfactionScore": PitchSatisfactionScore,
86
+ "NumberOfChildrenVisiting": NumberOfChildrenVisiting,
87
+ "MonthlyIncome": MonthlyIncome,
88
+
89
+ "TypeofContact": TypeofContact,
90
+ "Occupation": Occupation,
91
+ "Gender": Gender,
92
+ "ProductPitched": ProductPitched,
93
+ "MaritalStatus": MaritalStatus,
94
+ "Designation": Designation,
95
+
96
+ "Passport": 1 if Passport == "Yes" else 0,
97
+ "OwnCar": 1 if OwnCar == "Yes" else 0
98
+ }])
99
+
100
+ # ------------------------------
101
+ # Prediction
102
+ # ------------------------------
103
+ if st.button("Predict Purchase Likelihood"):
104
+ proba = model.predict_proba(input_data)[0, 1]
105
+ prediction = 1 if proba >= classification_threshold else 0
106
+
107
+ st.subheader("Prediction Result")
108
+ if prediction == 1:
109
+ st.success(f" The customer is **LIKELY to buy** the Wellness Tourism Package.")
110
+ else:
111
+ st.error(f"❗ The customer is **NOT likely to buy** the package.")
112
+
113
+ st.write(f"**Predicted Probability:** {proba:.4f}")
114
+ st.write(f"**Decision Threshold:** {classification_threshold:.2f}")
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
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