Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files- Dockerfile +15 -12
- app.py +80 -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,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import streamlit as st
|
| 3 |
+
import pandas as pd
|
| 4 |
+
import numpy as np
|
| 5 |
+
from huggingface_hub import hf_hub_download
|
| 6 |
+
import joblib
|
| 7 |
+
|
| 8 |
+
st.set_page_config(page_title="Visit With Us — Tourism Package Predictor", page_icon="🧳", layout="centered")
|
| 9 |
+
|
| 10 |
+
# Download the model from the Model Hub
|
| 11 |
+
model_path = hf_hub_download(repo_id="Abhilashu/tourism-model", filename="best_tourism_model_v1.joblib")
|
| 12 |
+
|
| 13 |
+
# Load the model
|
| 14 |
+
model = joblib.load(model_path)
|
| 15 |
+
|
| 16 |
+
st.title("Visit with us Tourism Package Purchase — Prediction")
|
| 17 |
+
st.write("Fill the details and click **Predict**. The model estimates the probability that a customer will buy the Tourism Package.")
|
| 18 |
+
|
| 19 |
+
with st.form("input_form"):
|
| 20 |
+
col1, col2 = st.columns(2)
|
| 21 |
+
|
| 22 |
+
with col1:
|
| 23 |
+
Age = st.number_input("Age", min_value=18, max_value=90, value=35, step=1)
|
| 24 |
+
CityTier = st.number_input("CityTier (1=metro, 2, 3)", min_value=1, max_value=3, value=1, step=1)
|
| 25 |
+
DurationOfPitch = st.number_input("DurationOfPitch (minutes)", min_value=0.0, value=10.0, step=1.0)
|
| 26 |
+
NumberOfPersonVisiting = st.number_input("NumberOfPersonVisiting", min_value=1.0, value=3.0, step=1.0)
|
| 27 |
+
NumberOfFollowups = st.number_input("NumberOfFollowups", min_value=0.0, value=3.0, step=1.0)
|
| 28 |
+
PreferredPropertyStar = st.number_input("PreferredPropertyStar (1-5)", min_value=1.0, max_value=5.0, value=3.0, step=1.0)
|
| 29 |
+
|
| 30 |
+
with col2:
|
| 31 |
+
NumberOfTrips = st.number_input("NumberOfTrips (per year)", min_value=0.0, value=2.0, step=1.0)
|
| 32 |
+
Passport = st.selectbox("Passport", options=[0,1], index=1)
|
| 33 |
+
PitchSatisfactionScore = st.number_input("PitchSatisfactionScore (1-5)", min_value=1.0, max_value=5.0, value=3.0, step=1.0)
|
| 34 |
+
OwnCar = st.selectbox("OwnCar", options=[0,1], index=0)
|
| 35 |
+
NumberOfChildrenVisiting = st.number_input("NumberOfChildrenVisiting (under 5)", min_value=0.0, value=0.0, step=1.0)
|
| 36 |
+
MonthlyIncome = st.number_input("MonthlyIncome", min_value=0.0, value=25000.0, step=500.0)
|
| 37 |
+
|
| 38 |
+
TypeofContact = st.selectbox("TypeofContact", ["Company Invited", "Self Enquiry"])
|
| 39 |
+
Occupation = st.selectbox("Occupation", ["Salaried", "Small Business", "Free Lancer"])
|
| 40 |
+
Gender = st.selectbox("Gender", ["Male", "Female"])
|
| 41 |
+
ProductPitched = st.selectbox("ProductPitched", ["Basic", "Deluxe", "Standard"])
|
| 42 |
+
MaritalStatus = st.selectbox("MaritalStatus", ["Single", "Married", "Divorced", "Unmarried"])
|
| 43 |
+
Designation = st.selectbox("Designation", ["Executive", "Manager", "Senior Manager"])
|
| 44 |
+
|
| 45 |
+
submitted = st.form_submit_button("Predict")
|
| 46 |
+
|
| 47 |
+
# Set the classification threshold
|
| 48 |
+
classification_threshold = 0.45
|
| 49 |
+
|
| 50 |
+
if submitted:
|
| 51 |
+
# NOTE: include ALL training features
|
| 52 |
+
row = {
|
| 53 |
+
"Age": float(Age),
|
| 54 |
+
"CityTier": float(CityTier),
|
| 55 |
+
"DurationOfPitch": float(DurationOfPitch),
|
| 56 |
+
"TypeofContact": str(TypeofContact).strip(), # <-- added
|
| 57 |
+
"Occupation": str(Occupation).strip(),
|
| 58 |
+
"Gender": str(Gender).strip(),
|
| 59 |
+
"NumberOfPersonVisiting": float(NumberOfPersonVisiting),
|
| 60 |
+
"NumberOfFollowups": float(NumberOfFollowups),
|
| 61 |
+
"ProductPitched": str(ProductPitched).strip(),
|
| 62 |
+
"PreferredPropertyStar": float(PreferredPropertyStar),
|
| 63 |
+
"MaritalStatus": str(MaritalStatus).strip(),
|
| 64 |
+
"NumberOfTrips": float(NumberOfTrips),
|
| 65 |
+
"Passport": float(Passport),
|
| 66 |
+
"PitchSatisfactionScore": float(PitchSatisfactionScore),
|
| 67 |
+
"OwnCar": float(OwnCar),
|
| 68 |
+
"NumberOfChildrenVisiting": float(NumberOfChildrenVisiting),
|
| 69 |
+
"Designation": str(Designation).strip(),
|
| 70 |
+
"MonthlyIncome": float(MonthlyIncome),
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
X = pd.DataFrame([row])
|
| 74 |
+
|
| 75 |
+
proba = model.predict_proba(X)[:, 1][0]
|
| 76 |
+
pred = int(proba >= classification_threshold)
|
| 77 |
+
|
| 78 |
+
st.subheader("Result")
|
| 79 |
+
st.metric("Predicted probability of purchase", f"{proba:.3f}")
|
| 80 |
+
st.write("Prediction:", "**Yes**" if pred==1 else "**No**")
|
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
|