Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files- Dockerfile +23 -0
- app.py +115 -0
- 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
|
| 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,115 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
from huggingface_hub import hf_hub_download
|
| 4 |
+
import joblib
|
| 5 |
+
|
| 6 |
+
# ================================
|
| 7 |
+
# App Title & Description
|
| 8 |
+
# ================================
|
| 9 |
+
st.set_page_config(page_title="Tourism Package Prediction", page_icon="๐", layout="centered")
|
| 10 |
+
|
| 11 |
+
st.title("๐ Tourism Package Prediction App")
|
| 12 |
+
st.write(
|
| 13 |
+
"""
|
| 14 |
+
This application predicts whether a customer is likely to **opt for a tourism package**
|
| 15 |
+
based on their profile and preferences.
|
| 16 |
+
Please provide the customer details below:
|
| 17 |
+
""")
|
| 18 |
+
|
| 19 |
+
# ================================
|
| 20 |
+
# Load Model from Hugging Face Hub
|
| 21 |
+
# ================================
|
| 22 |
+
@st.cache_resource
|
| 23 |
+
def load_model():
|
| 24 |
+
model_path = hf_hub_download(
|
| 25 |
+
repo_id="Parthi07/Package-Prediction-Model",
|
| 26 |
+
filename="models/best_package_prediction_model_v1.joblib"
|
| 27 |
+
)
|
| 28 |
+
return joblib.load(model_path)
|
| 29 |
+
|
| 30 |
+
model = load_model()
|
| 31 |
+
|
| 32 |
+
# Mapping for City Tier
|
| 33 |
+
city_tier_map = {"Tier 1": 1, "Tier 2": 2, "Tier 3": 3}
|
| 34 |
+
|
| 35 |
+
# ================================
|
| 36 |
+
# Sidebar Input Form (Improved Layout)
|
| 37 |
+
# ================================
|
| 38 |
+
st.sidebar.header("๐ Enter Customer Details")
|
| 39 |
+
|
| 40 |
+
# --------- 1. Personal Information ---------
|
| 41 |
+
with st.sidebar.expander("๐ค Personal Information", expanded=True):
|
| 42 |
+
age = st.number_input("Age of Customer", min_value=18, max_value=100, value=30)
|
| 43 |
+
gender = st.selectbox("Gender", ["Female", "Male"])
|
| 44 |
+
marital_status = st.selectbox("Marital Status", ["Single", "Divorced", "Married", "Unmarried"])
|
| 45 |
+
occupation = st.selectbox("Occupation", ["Salaried", "Free Lancer", "Small Business", "Large Business"])
|
| 46 |
+
designation = st.selectbox("Designation", ["Manager", "Executive", "Senior Manager", "AVP", "VP"])
|
| 47 |
+
city_tier = st.selectbox("City Tier", ["Tier 1", "Tier 2", "Tier 3"])
|
| 48 |
+
# --------- 2. Lifestyle & Financial ---------
|
| 49 |
+
with st.sidebar.expander("๐ฐ Lifestyle & Financial", expanded=True):
|
| 50 |
+
monthly_income = st.number_input("Monthly Income", min_value=100, max_value=200000, value=10000)
|
| 51 |
+
own_car = st.radio("Owns a Car?", ["Yes", "No"])
|
| 52 |
+
passport = st.radio("Has Passport?", ["Yes", "No"])
|
| 53 |
+
|
| 54 |
+
# --------- 3. Travel Preferences ---------
|
| 55 |
+
with st.sidebar.expander("โ๏ธ Travel Preferences", expanded=False):
|
| 56 |
+
product_pitched = st.selectbox("Product Pitched", ["Deluxe", "Basic", "Standard", "Super Deluxe", "King"])
|
| 57 |
+
preferred_property_star = st.selectbox("Preferred Property Star", [3, 4, 5])
|
| 58 |
+
|
| 59 |
+
# --------- 4. Trip & Family Details ---------
|
| 60 |
+
with st.sidebar.expander("๐จโ๐ฉโ๐ง Family & Trips", expanded=False):
|
| 61 |
+
num_person_visiting = st.number_input("Number of Persons Visiting", min_value=1, max_value=5, value=1)
|
| 62 |
+
num_children_visiting = st.number_input("Number of Children Visiting", min_value=0, max_value=3, value=0)
|
| 63 |
+
num_trips = st.number_input("Number of Trips", min_value=1, max_value=22, value=3)
|
| 64 |
+
|
| 65 |
+
# --------- 5. Sales Interaction ---------
|
| 66 |
+
with st.sidebar.expander("๐ Sales Interaction", expanded=False):
|
| 67 |
+
type_of_contact = st.selectbox("Type of Contact", ["Self Enquiry", "Company Invited"])
|
| 68 |
+
duration_of_pitch = st.number_input("Pitch Duration (minutes)", min_value=0, max_value=150, value=30)
|
| 69 |
+
num_followups = st.number_input("Number of Followups", min_value=1, max_value=6, value=1)
|
| 70 |
+
pitch_satisfaction_score = st.number_input("Pitch Satisfaction Score", min_value=1, max_value=5, value=3)
|
| 71 |
+
|
| 72 |
+
# ================================
|
| 73 |
+
# Prepare Input Data
|
| 74 |
+
# ================================
|
| 75 |
+
input_data = pd.DataFrame([{
|
| 76 |
+
"TypeofContact": type_of_contact,
|
| 77 |
+
"CityTier": city_tier_map[city_tier],
|
| 78 |
+
"Occupation": occupation,
|
| 79 |
+
"Gender": gender,
|
| 80 |
+
"ProductPitched": product_pitched,
|
| 81 |
+
"PreferredPropertyStar": preferred_property_star,
|
| 82 |
+
"MaritalStatus": marital_status,
|
| 83 |
+
"Designation": designation,
|
| 84 |
+
"NumberOfPersonVisiting": num_person_visiting,
|
| 85 |
+
"NumberOfFollowups": num_followups,
|
| 86 |
+
"NumberOfTrips": num_trips,
|
| 87 |
+
"PitchSatisfactionScore": pitch_satisfaction_score,
|
| 88 |
+
"NumberOfChildrenVisiting": num_children_visiting,
|
| 89 |
+
"MonthlyIncome": monthly_income,
|
| 90 |
+
"DurationOfPitch": duration_of_pitch,
|
| 91 |
+
"Age": age,
|
| 92 |
+
"Passport": 1 if passport == "Yes" else 0,
|
| 93 |
+
"OwnCar": 1 if own_car == "Yes" else 0
|
| 94 |
+
}])
|
| 95 |
+
|
| 96 |
+
# ================================
|
| 97 |
+
# Prediction
|
| 98 |
+
# ================================
|
| 99 |
+
|
| 100 |
+
# Classification threshold used during training
|
| 101 |
+
CLASSIFICATION_THRESHOLD = 0.45
|
| 102 |
+
|
| 103 |
+
if st.button("๐ฎ Predict"):
|
| 104 |
+
# Get probability of "Product Taken" (class = 1)
|
| 105 |
+
proba = model.predict_proba(input_data)[0][1]
|
| 106 |
+
prediction = 1 if proba >= CLASSIFICATION_THRESHOLD else 0
|
| 107 |
+
|
| 108 |
+
result = "โ
Package Opted" if prediction == 1 else "โ Package Not Opted"
|
| 109 |
+
confidence = round(proba * 100, 2)
|
| 110 |
+
|
| 111 |
+
st.subheader("๐ Prediction Result")
|
| 112 |
+
st.success(f"**{result}** with {confidence}% confidence")
|
| 113 |
+
|
| 114 |
+
st.write("### Entered Customer Profile:")
|
| 115 |
+
st.dataframe(input_data.T, use_container_width=True)
|
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
|