Upload folder using huggingface_hub
Browse files- Dockerfile +15 -12
- app.py +136 -0
- requirements.txt +7 -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,136 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
from huggingface_hub import hf_hub_download
|
| 4 |
+
import joblib
|
| 5 |
+
import numpy as np
|
| 6 |
+
|
| 7 |
+
# Page config
|
| 8 |
+
st.set_page_config(page_title="Tourism Package Prediction", layout="wide")
|
| 9 |
+
|
| 10 |
+
# Download and load the model
|
| 11 |
+
model_path = hf_hub_download(repo_id="pragmat/Tourism", filename="best_prediction_model_v1.joblib")
|
| 12 |
+
model = joblib.load(model_path)
|
| 13 |
+
|
| 14 |
+
# Main title and description
|
| 15 |
+
st.title("Tourism Package Purchase Prediction")
|
| 16 |
+
st.markdown("""
|
| 17 |
+
**Predict whether a customer will purchase a tourism package** based on their demographic and travel preferences.
|
| 18 |
+
Enter customer details below to get a prediction!
|
| 19 |
+
""")
|
| 20 |
+
|
| 21 |
+
# Sidebar for inputs with proper feature names from your dataset
|
| 22 |
+
st.sidebar.header("Customer Profile")
|
| 23 |
+
st.sidebar.markdown("---")
|
| 24 |
+
|
| 25 |
+
# Numeric features (matching your dataset)
|
| 26 |
+
col1, col2 = st.columns(2)
|
| 27 |
+
with col1:
|
| 28 |
+
age = st.number_input("Age", min_value=18, max_value=80, value=35)
|
| 29 |
+
num_person = st.number_input("Number of Persons Visiting", min_value=1, max_value=6, value=2)
|
| 30 |
+
num_trips = st.number_input("Number of Trips", min_value=0, max_value=10, value=1)
|
| 31 |
+
with col2:
|
| 32 |
+
monthly_income = st.number_input("Monthly Income", min_value=10000, max_value=100000, value=50000)
|
| 33 |
+
num_children = st.number_input("Number of Children Visiting", min_value=0, max_value=5, value=0)
|
| 34 |
+
passport = st.selectbox("Has Passport?", [0, 1], format_func=lambda x: "Yes" if x else "No")
|
| 35 |
+
|
| 36 |
+
col3, col4 = st.columns(2)
|
| 37 |
+
with col3:
|
| 38 |
+
own_car = st.selectbox("Owns Car?", [0, 1], format_func=lambda x: "Yes" if x else "No")
|
| 39 |
+
pitch_satisfaction = st.slider("Pitch Satisfaction Score", 1, 5, 3)
|
| 40 |
+
num_followups = st.number_input("Number of Follow-ups", min_value=0, max_value=10, value=2)
|
| 41 |
+
with col4:
|
| 42 |
+
duration_pitch = st.slider("Duration of Pitch (days)", 1, 30, 7)
|
| 43 |
+
preferred_star = st.slider("Preferred Property Star Rating", 1, 5, 3)
|
| 44 |
+
|
| 45 |
+
# Categorical features
|
| 46 |
+
st.sidebar.markdown("---")
|
| 47 |
+
st.sidebar.subheader("Demographics & Preferences")
|
| 48 |
+
|
| 49 |
+
city_tier = st.sidebar.selectbox("City Tier", [1, 2, 3], format_func=lambda x: f"Tier {x}")
|
| 50 |
+
occupation = st.sidebar.selectbox("Occupation", [
|
| 51 |
+
"Employee", "Self Employed", "Housewife", "Student", "Business"
|
| 52 |
+
])
|
| 53 |
+
gender = st.sidebar.selectbox("Gender", ["Male", "Female"])
|
| 54 |
+
marital_status = st.sidebar.selectbox("Marital Status", [
|
| 55 |
+
"Single", "Married", "Divorced"
|
| 56 |
+
])
|
| 57 |
+
designation = st.sidebar.selectbox("Designation", [
|
| 58 |
+
"Executive", "Manager", "Senior Manager", "Director"
|
| 59 |
+
])
|
| 60 |
+
product_pitched = st.sidebar.selectbox("Product Pitched", [
|
| 61 |
+
"Basic", "Standard", "Premium", "Deluxe"
|
| 62 |
+
])
|
| 63 |
+
type_of_contact = st.sidebar.selectbox("Type of Contact", ["Email", "Self Enquiry"])
|
| 64 |
+
|
| 65 |
+
# Prepare input data with correct column names and proper encoding
|
| 66 |
+
input_data_dict = {
|
| 67 |
+
'Age': age,
|
| 68 |
+
'NumberOfPersonVisiting': num_person,
|
| 69 |
+
'PreferredPropertyStar': preferred_star,
|
| 70 |
+
'NumberOfTrips': num_trips,
|
| 71 |
+
'Passport': passport,
|
| 72 |
+
'OwnCar': own_car,
|
| 73 |
+
'NumberOfChildrenVisiting': num_children,
|
| 74 |
+
'MonthlyIncome': monthly_income,
|
| 75 |
+
'PitchSatisfactionScore': pitch_satisfaction,
|
| 76 |
+
'NumberOfFollowups': num_followups,
|
| 77 |
+
'DurationOfPitch': duration_pitch,
|
| 78 |
+
'TypeofContact': type_of_contact,
|
| 79 |
+
'CityTier': city_tier,
|
| 80 |
+
'Occupation': occupation,
|
| 81 |
+
'Gender': gender,
|
| 82 |
+
'MaritalStatus': marital_status,
|
| 83 |
+
'Designation': designation,
|
| 84 |
+
'ProductPitched': product_pitched
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
input_df = pd.DataFrame([input_data_dict])
|
| 88 |
+
|
| 89 |
+
# Main prediction section
|
| 90 |
+
st.markdown("---")
|
| 91 |
+
col1, col2, col3 = st.columns([2, 1, 1])
|
| 92 |
+
with col1:
|
| 93 |
+
st.subheader("Customer Summary")
|
| 94 |
+
summary_df = pd.DataFrame([{
|
| 95 |
+
"Feature": ["Age", "Income", "City Tier", "Product", "Trips"],
|
| 96 |
+
"Value": [f"{age} yrs", f"₹{monthly_income:,}", f"Tier {city_tier}", product_pitched, num_trips]
|
| 97 |
+
}])
|
| 98 |
+
st.dataframe(summary_df, use_container_width=True)
|
| 99 |
+
|
| 100 |
+
if st.button("Predict Package Purchase", type="primary", use_container_width=True):
|
| 101 |
+
with st.spinner("Generating prediction..."):
|
| 102 |
+
try:
|
| 103 |
+
# Get prediction probabilities
|
| 104 |
+
prediction_proba = model.predict_proba(input_df)[:, 1][0]
|
| 105 |
+
prediction = model.predict(input_df)[0]
|
| 106 |
+
|
| 107 |
+
# Results
|
| 108 |
+
st.subheader("Prediction Results")
|
| 109 |
+
|
| 110 |
+
col_a, col_b = st.columns(2)
|
| 111 |
+
with col_a:
|
| 112 |
+
probability = prediction_proba * 100
|
| 113 |
+
st.metric(
|
| 114 |
+
label="Purchase Probability",
|
| 115 |
+
value=f"{probability:.1f}%",
|
| 116 |
+
delta=f"{probability:.1f}% chance"
|
| 117 |
+
)
|
| 118 |
+
|
| 119 |
+
with col_b:
|
| 120 |
+
result = "**Will Purchase**" if prediction == 1 else "**Won't Purchase**"
|
| 121 |
+
st.markdown(result)
|
| 122 |
+
|
| 123 |
+
# Confidence bar
|
| 124 |
+
st.progress(prediction_proba)
|
| 125 |
+
|
| 126 |
+
# Recommendation
|
| 127 |
+
if prediction == 1:
|
| 128 |
+
st.success("**High conversion potential!** Prioritize follow-up calls and personalized offers.")
|
| 129 |
+
else:
|
| 130 |
+
st.warning("**Low conversion likelihood.** Consider alternative products or nurturing strategy.")
|
| 131 |
+
|
| 132 |
+
except Exception as e:
|
| 133 |
+
st.error(f"Prediction failed: {str(e)}")
|
| 134 |
+
st.info("Ensure all input features match your training data exactly.")
|
| 135 |
+
|
| 136 |
+
|
requirements.txt
CHANGED
|
@@ -1,3 +1,7 @@
|
|
| 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
|