SagarAtHf commited on
Commit
5bc4d50
·
verified ·
1 Parent(s): 4112be8

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. Dockerfile +15 -12
  2. app.py +84 -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,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import joblib
4
+ import os
5
+ from huggingface_hub import hf_hub_download
6
+
7
+ # 1. Configuration - Matching your train.py setup
8
+ REPO_ID = "SagarAtHf/tourismpackagepredict-model"
9
+ FILENAME = "productionmodel.joblib"
10
+
11
+ @st.cache_resource # This ensures the model only downloads once, not on every click
12
+ def load_model():
13
+ try:
14
+ # Pulling the model from the Model Hub
15
+ model_path = hf_hub_download(repo_id=REPO_ID, filename=FILENAME)
16
+ return joblib.load(model_path)
17
+ except Exception as e:
18
+ st.error(f"Error loading model from Hub: {e}")
19
+ return None
20
+
21
+ # Load the model
22
+ model = load_model()
23
+
24
+ # 2. UI Header
25
+ st.title("🌴 Wellness Tourism Package Predictor")
26
+ st.markdown("Enter customer details below to predict the likelihood of a package purchase.")
27
+
28
+ # 3. User Input Form
29
+ with st.form("prediction_form"):
30
+ col1, col2 = st.columns(2)
31
+
32
+ with col1:
33
+ age = st.number_input("Age", min_value=18, max_value=100, value=30)
34
+ city_tier = st.selectbox("City Tier", [1, 2, 3])
35
+ occupation = st.selectbox("Occupation", ["Salaried", "Small Business", "Large Business", "Free Lancer"])
36
+ gender = st.selectbox("Gender", ["Male", "Female"])
37
+ duration = st.number_input("Duration of Pitch", value=15)
38
+
39
+ with col2:
40
+ marital_status = st.selectbox("Marital Status", ["Married", "Unmarried", "Divorced"])
41
+ designation = st.selectbox("Designation", ["Manager", "Executive", "Senior Manager", "AVP", "VP"])
42
+ product_pitched = st.selectbox("Product Pitched", ["Deluxe", "Basic", "Standard", "Super Deluxe", "King"])
43
+ monthly_income = st.number_input("Monthly Income", value=20000)
44
+ passport = st.selectbox("Has Passport?", [0, 1], format_func=lambda x: "Yes" if x==1 else "No")
45
+
46
+ # Additional features required by the model (using averages/defaults)
47
+ submit = st.form_submit_button("Predict Probability")
48
+
49
+ # 4. Prediction Logic
50
+ if submit and model:
51
+ # Prepare input dataframe with exact column names from training
52
+ input_data = pd.DataFrame({
53
+ 'Age': [age],
54
+ 'CityTier': [city_tier],
55
+ 'DurationOfPitch': [duration],
56
+ 'Occupation': [occupation],
57
+ 'Gender': [gender],
58
+ 'NumberOfPersonVisiting': [2], # Defaulting common values
59
+ 'NumberOfFollowups': [3],
60
+ 'ProductPitched': [product_pitched],
61
+ 'PreferredPropertyStar': [3],
62
+ 'MaritalStatus': [marital_status],
63
+ 'NumberOfTrips': [1],
64
+ 'Passport': [passport],
65
+ 'PitchSatisfactionScore': [3],
66
+ 'OwnCar': [1],
67
+ 'NumberOfChildrenVisiting': [0],
68
+ 'Designation': [designation],
69
+ 'MonthlyIncome': [monthly_income],
70
+ 'TypeofContact': ["Self Enquiry"]
71
+ })
72
+
73
+ # Get probability from the model
74
+ # Note: We use the threshold 0.45 you defined in your local tests
75
+ prob = model.predict_proba(input_data)[0][1]
76
+ prediction = 1 if prob >= 0.45 else 0
77
+
78
+ # 5. Display Results
79
+ st.divider()
80
+ if prediction == 1:
81
+ st.success(f"🎯 High Potential Customer! (Probability: {prob:.2%})")
82
+ st.balloons()
83
+ else:
84
+ st.warning(f"⏳ Low Likelihood of purchase. (Probability: {prob:.2%})")
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