Upload folder using huggingface_hub
Browse files- Dockerfile +15 -12
- app.py +119 -0
- requirements.txt +8 -3
Dockerfile
CHANGED
|
@@ -1,20 +1,23 @@
|
|
| 1 |
-
|
|
|
|
| 2 |
|
|
|
|
| 3 |
WORKDIR /app
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
-
|
| 19 |
|
| 20 |
-
|
|
|
|
|
|
| 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,119 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import numpy as np
|
| 4 |
+
import joblib
|
| 5 |
+
from huggingface_hub import hf_hub_download
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
# 1. Load Model from Hugging Face Model Hub
|
| 9 |
+
# ============================================================
|
| 10 |
+
|
| 11 |
+
MODEL_REPO = "Quantum9999/Tourism-Package-Prediction"
|
| 12 |
+
MODEL_FILENAME = "xgb_model.pkl"
|
| 13 |
+
|
| 14 |
+
@st.cache_resource
|
| 15 |
+
def load_model():
|
| 16 |
+
model_path = hf_hub_download(repo_id=MODEL_REPO, filename=MODEL_FILENAME, repo_type="model")
|
| 17 |
+
model = joblib.load(model_path)
|
| 18 |
+
return model
|
| 19 |
+
|
| 20 |
+
model = load_model()
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
# 2. Streamlit UI
|
| 24 |
+
# ============================================================
|
| 25 |
+
|
| 26 |
+
st.title(" Wellness Tourism Package Purchase Prediction")
|
| 27 |
+
st.write("Fill in the customer details below to predict whether they will purchase the new Wellness Tourism Package.")
|
| 28 |
+
|
| 29 |
+
st.markdown("---")
|
| 30 |
+
|
| 31 |
+
# 3. User Inputs
|
| 32 |
+
# ============================================================
|
| 33 |
+
|
| 34 |
+
def user_input_form():
|
| 35 |
+
Age = st.number_input("Age", min_value=1, max_value=100, value=30)
|
| 36 |
+
CityTier = st.selectbox("City Tier", [1, 2, 3])
|
| 37 |
+
NumberOfPersonVisiting = st.number_input("Number of People Visiting", min_value=1, max_value=10, value=1)
|
| 38 |
+
PreferredPropertyStar = st.selectbox("Preferred Property Star", [3, 4, 5])
|
| 39 |
+
NumberOfTrips = st.number_input("Number of Trips per Year", min_value=0, max_value=20, value=2)
|
| 40 |
+
NumberOfChildrenVisiting = st.number_input("Children Visiting (Under 5 Years)", min_value=0, max_value=5, value=0)
|
| 41 |
+
MonthlyIncome = st.number_input("Monthly Income", min_value=1000, max_value=1000000, value=30000)
|
| 42 |
+
PitchSatisfactionScore = st.selectbox("Pitch Satisfaction Score", [1, 2, 3, 4, 5])
|
| 43 |
+
NumberOfFollowups = st.number_input("Number of Follow-ups", min_value=1, max_value=10, value=2)
|
| 44 |
+
DurationOfPitch = st.number_input("Duration of Pitch (Minutes)", min_value=1, max_value=60, value=15)
|
| 45 |
+
|
| 46 |
+
TypeofContact = st.selectbox("Type of Contact", ["Company Invited", "Self Enquiry"])
|
| 47 |
+
Occupation = st.selectbox("Occupation", ["Salaried", "Self Employed", "Small Business", "Large Business", "Free Lancer"])
|
| 48 |
+
Gender = st.selectbox("Gender", ["Male", "Female"])
|
| 49 |
+
MaritalStatus = st.selectbox("Marital Status", ["Married", "Single", "Divorced", "Unmarried"])
|
| 50 |
+
Passport = st.selectbox("Passport", [0, 1])
|
| 51 |
+
OwnCar = st.selectbox("Owns Car?", [0, 1])
|
| 52 |
+
Designation = st.selectbox("Designation", ["Junior", "Senior", "Manager", "Executive", "Other"])
|
| 53 |
+
ProductPitched = st.selectbox("Product Pitched", ["Basic", "Standard", "Deluxe", "Super Deluxe", "King"])
|
| 54 |
+
|
| 55 |
+
# Create DataFrame
|
| 56 |
+
data = pd.DataFrame({
|
| 57 |
+
"Age": [Age],
|
| 58 |
+
"CityTier": [CityTier],
|
| 59 |
+
"NumberOfPersonVisiting": [NumberOfPersonVisiting],
|
| 60 |
+
"PreferredPropertyStar": [PreferredPropertyStar],
|
| 61 |
+
"NumberOfTrips": [NumberOfTrips],
|
| 62 |
+
"NumberOfChildrenVisiting": [NumberOfChildrenVisiting],
|
| 63 |
+
"MonthlyIncome": [MonthlyIncome],
|
| 64 |
+
"PitchSatisfactionScore": [PitchSatisfactionScore],
|
| 65 |
+
"NumberOfFollowups": [NumberOfFollowups],
|
| 66 |
+
"DurationOfPitch": [DurationOfPitch],
|
| 67 |
+
"TypeofContact": [TypeofContact],
|
| 68 |
+
"Occupation": [Occupation],
|
| 69 |
+
"Gender": [Gender],
|
| 70 |
+
"MaritalStatus": [MaritalStatus],
|
| 71 |
+
"Passport": [Passport],
|
| 72 |
+
"OwnCar": [OwnCar],
|
| 73 |
+
"Designation": [Designation],
|
| 74 |
+
"ProductPitched": [ProductPitched]
|
| 75 |
+
})
|
| 76 |
+
|
| 77 |
+
return data
|
| 78 |
+
|
| 79 |
+
user_data = user_input_form()
|
| 80 |
+
|
| 81 |
+
st.markdown("---")
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
# 4. Preprocess User Input → MATCH Training Preprocessing
|
| 85 |
+
# ============================================================
|
| 86 |
+
|
| 87 |
+
# Categorical + numerical split (same as prep.py)
|
| 88 |
+
numerical_features = [
|
| 89 |
+
'Age', 'CityTier', 'NumberOfPersonVisiting', 'PreferredPropertyStar',
|
| 90 |
+
'NumberOfTrips', 'NumberOfChildrenVisiting', 'MonthlyIncome',
|
| 91 |
+
'PitchSatisfactionScore', 'NumberOfFollowups', 'DurationOfPitch'
|
| 92 |
+
]
|
| 93 |
+
|
| 94 |
+
categorical_features = [
|
| 95 |
+
'TypeofContact', 'Occupation', 'Gender', 'MaritalStatus',
|
| 96 |
+
'Passport', 'OwnCar', 'Designation', 'ProductPitched'
|
| 97 |
+
]
|
| 98 |
+
|
| 99 |
+
# Load preprocessors (generated in prep.py)
|
| 100 |
+
preprocessor_path = hf_hub_download(repo_id=MODEL_REPO, filename="preprocessing_pipeline.pkl", repo_type="model")
|
| 101 |
+
preprocessor = joblib.load(preprocessor_path)
|
| 102 |
+
|
| 103 |
+
processed_user_data = preprocessor.transform(user_data)
|
| 104 |
+
|
| 105 |
+
|
| 106 |
+
# 5. Make Prediction
|
| 107 |
+
# ============================================================
|
| 108 |
+
|
| 109 |
+
if st.button("Predict"):
|
| 110 |
+
prediction = model.predict(processed_user_data)[0]
|
| 111 |
+
proba = model.predict_proba(processed_user_data)[0][1]
|
| 112 |
+
|
| 113 |
+
st.subheader(" Prediction Result")
|
| 114 |
+
|
| 115 |
+
if prediction == 1:
|
| 116 |
+
st.success(f" Customer is LIKELY to purchase the Wellness Tourism Package! (Confidence: {proba:.2f})")
|
| 117 |
+
else:
|
| 118 |
+
st.error(f" Customer is NOT likely to purchase the package. (Confidence: {proba:.2f})")
|
| 119 |
+
|
requirements.txt
CHANGED
|
@@ -1,3 +1,8 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 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
|
| 8 |
+
numpy==1.26.4
|