AdarshRL commited on
Commit
3559120
·
verified ·
1 Parent(s): ed438fe

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. Dockerfile +23 -0
  2. app.py +103 -0
  3. 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-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
+ 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,103 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ from huggingface_hub import hf_hub_download
4
+ import joblib
5
+ import os
6
+
7
+ # Common constants
8
+ HUGGINGFACE_USER_NAME = os.getenv('HUGGINGFACE_USER_NAME')
9
+ HUGGINGFACE_MODEL_NAME = os.getenv('HUGGINGFACE_MODEL_NAME')
10
+
11
+ # Download the model from the Model Hub
12
+ # Note: Ensure the filename matches what you uploaded in your training script
13
+ try:
14
+ model_path = hf_hub_download(
15
+ repo_id=f"{HUGGINGFACE_USER_NAME}/{HUGGINGFACE_MODEL_NAME}",
16
+ filename="model.joblib"
17
+ )
18
+ model = joblib.load(model_path)
19
+ except Exception as e:
20
+ st.error(f"Error loading model from Hugging Face: {e}")
21
+ st.stop()
22
+
23
+ # Streamlit UI Setup
24
+ st.set_page_config(page_title="Wellness Package Prediction", layout="centered")
25
+ st.title("Tourism Wellness Package Purchase Prediction")
26
+ st.write("""
27
+ This tool predicts whether a customer is likely to purchase a **Wellness Package** based on their demographic and interaction history.
28
+ """)
29
+
30
+ st.divider()
31
+
32
+ # Create two columns for a cleaner UI layout
33
+ col1, col2 = st.columns(2)
34
+
35
+ with col1:
36
+ st.subheader("Demographics")
37
+ Age = st.number_input("Age", min_value=18, max_value=100, value=30)
38
+ Gender = st.selectbox("Gender", ["Male", "Female"])
39
+ MaritalStatus = st.selectbox("Marital Status", ["Single", "Married", "Divorced"])
40
+ Occupation = st.selectbox("Occupation", ['Salaried' 'Free Lancer' 'Small Business' 'Large Business'])
41
+ Designation = st.selectbox("Designation", ['Manager' 'Executive' 'Senior Manager' 'AVP' 'VP'])
42
+ MonthlyIncome = st.number_input("Monthly Income", min_value=0.0, value=25000.0)
43
+ CityTier = st.slider("City Tier", 1, 3, 1)
44
+
45
+ with col2:
46
+ st.subheader("Travel Behavior")
47
+ TypeofContact = st.selectbox("Type of Contact", ['Self Enquiry' 'Company Invited'])
48
+ ProductPitched = st.selectbox("Product Pitched", ['Deluxe' 'Basic' 'Standard' 'Super Deluxe' 'King'])
49
+ DurationOfPitch = st.number_input("Duration of Pitch (minutes)", min_value=0, value=15)
50
+ NumberOfFollowups = st.slider("Number of Follow-ups", 1, 10, 3)
51
+ NumberOfTrips = st.number_input("Number of Trips", min_value=0, value=2)
52
+ PitchSatisfactionScore = st.slider("Pitch Satisfaction Score", 1, 5, 3)
53
+ PreferredPropertyStar = st.slider("Preferred Property Star", 3, 5, 3)
54
+
55
+ st.subheader("Additional Info")
56
+ c3, c4, c5 = st.columns(3)
57
+ with c3:
58
+ Passport = st.selectbox("Has Passport?", ["Yes", "No"])
59
+ with c4:
60
+ OwnCar = st.selectbox("Owns a Car?", ["Yes", "No"])
61
+ with c5:
62
+ NumberOfPersonVisiting = st.number_input("Adults Visiting", min_value=1, value=2)
63
+ NumberOfChildrenVisiting = st.number_input("Children Visiting", min_value=0, value=0)
64
+
65
+ # Prepare input data matching the exact training schema
66
+ input_dict = {
67
+ 'Age': Age,
68
+ 'CityTier': CityTier,
69
+ 'DurationOfPitch': DurationOfPitch,
70
+ 'NumberOfPersonVisiting': NumberOfPersonVisiting,
71
+ 'NumberOfFollowups': NumberOfFollowups,
72
+ 'PreferredPropertyStar': PreferredPropertyStar,
73
+ 'NumberOfTrips': NumberOfTrips,
74
+ 'Passport': 1 if Passport == "Yes" else 0,
75
+ 'PitchSatisfactionScore': PitchSatisfactionScore,
76
+ 'OwnCar': 1 if OwnCar == "Yes" else 0,
77
+ 'NumberOfChildrenVisiting': NumberOfChildrenVisiting,
78
+ 'MonthlyIncome': MonthlyIncome,
79
+ 'TypeofContact': TypeofContact,
80
+ 'Occupation': Occupation,
81
+ 'Gender': Gender,
82
+ 'ProductPitched': ProductPitched,
83
+ 'MaritalStatus': MaritalStatus,
84
+ 'Designation': Designation
85
+ }
86
+
87
+ input_data = pd.DataFrame([input_dict])
88
+
89
+ # Prediction Logic
90
+ classification_threshold = 0.45
91
+
92
+ st.divider()
93
+ if st.button("Generate Prediction", type="primary"):
94
+ # Get probability from XGBoost
95
+ prediction_proba = model.predict_proba(input_data)[0, 1]
96
+
97
+ # Apply custom threshold
98
+ prediction = 1 if prediction_proba >= classification_threshold else 0
99
+
100
+ if prediction == 1:
101
+ st.success(f"High Potential: Customer is likely to **PURCHASE** (Prob: {prediction_proba:.2f})")
102
+ else:
103
+ st.warning(f"Low Potential: Customer is likely to **NOT PURCHASE** (Prob: {prediction_proba:.2f})")
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