Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files- Dockerfile +21 -13
- app.py +117 -0
- requirements.txt +7 -3
Dockerfile
CHANGED
|
@@ -1,20 +1,28 @@
|
|
| 1 |
-
|
| 2 |
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
curl \
|
| 8 |
-
git \
|
| 9 |
-
&& rm -rf /var/lib/apt/lists/*
|
| 10 |
|
| 11 |
-
|
| 12 |
-
COPY
|
|
|
|
|
|
|
| 13 |
|
| 14 |
-
|
|
|
|
| 15 |
|
|
|
|
| 16 |
EXPOSE 8501
|
| 17 |
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
ENTRYPOINT ["streamlit", "run", "src/streamlit_app.py", "--server.port=8501", "--server.address=0.0.0.0"]
|
|
|
|
| 1 |
+
# deployment/Dockerfile
|
| 2 |
|
| 3 |
+
# 1. Base image
|
| 4 |
+
FROM python:3.11-slim
|
| 5 |
+
|
| 6 |
+
# 2. Set environment variables
|
| 7 |
+
ENV PYTHONUNBUFFERED=1 \
|
| 8 |
+
HF_TOKEN=${HF_TOKEN} \
|
| 9 |
+
STREAMLIT_SERVER_HEADLESS=true \
|
| 10 |
+
STREAMLIT_SERVER_PORT=8501 \
|
| 11 |
+
STREAMLIT_SERVER_ADDRESS=0.0.0.0
|
| 12 |
|
| 13 |
+
# 3. Create working dir
|
| 14 |
+
WORKDIR /app
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
+
# 4. Copy & install dependencies
|
| 17 |
+
COPY requirements.txt .
|
| 18 |
+
RUN pip install --upgrade pip && \
|
| 19 |
+
pip install -r requirements.txt
|
| 20 |
|
| 21 |
+
# 5. Copy app code
|
| 22 |
+
COPY app.py hf_deploy.py ./
|
| 23 |
|
| 24 |
+
# 6. Expose Streamlit port
|
| 25 |
EXPOSE 8501
|
| 26 |
|
| 27 |
+
# 7. Start Streamlit
|
| 28 |
+
ENTRYPOINT ["streamlit", "run", "app.py"]
|
|
|
app.py
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import streamlit as st
|
| 3 |
+
import pandas as pd
|
| 4 |
+
import joblib
|
| 5 |
+
from huggingface_hub import hf_hub_download
|
| 6 |
+
|
| 7 |
+
# -------------------------------------------------
|
| 8 |
+
# Download and load the trained model from HF Model Hub
|
| 9 |
+
# -------------------------------------------------
|
| 10 |
+
HF_MODEL_REPO = "Amittripipathi/Wellness_tourism_project-model"
|
| 11 |
+
MODEL_FILENAME = "best_model.joblib"
|
| 12 |
+
|
| 13 |
+
model_path = hf_hub_download(
|
| 14 |
+
repo_id = HF_MODEL_REPO,
|
| 15 |
+
repo_type = "model",
|
| 16 |
+
filename = MODEL_FILENAME,
|
| 17 |
+
token = os.getenv("HF_TOKEN")
|
| 18 |
+
)
|
| 19 |
+
model = joblib.load(model_path)
|
| 20 |
+
|
| 21 |
+
# -------------------------------------------------
|
| 22 |
+
# Streamlit App Configuration
|
| 23 |
+
# -------------------------------------------------
|
| 24 |
+
st.set_page_config(
|
| 25 |
+
page_title="Wellness Tourism Package Purchase Predictor",
|
| 26 |
+
layout="centered"
|
| 27 |
+
)
|
| 28 |
+
|
| 29 |
+
st.title("Wellness Tourism Package Purchase Predictor")
|
| 30 |
+
st.markdown("""
|
| 31 |
+
Predict whether a customer will purchase our newly launched **Wellness Tourism Package**
|
| 32 |
+
based on demographic and interaction details. Fill in the fields below and click **Predict**.
|
| 33 |
+
""")
|
| 34 |
+
|
| 35 |
+
# -------------------------------------------------
|
| 36 |
+
# Customer Demographics Inputs
|
| 37 |
+
# -------------------------------------------------
|
| 38 |
+
age = st.number_input("Age", min_value=18, max_value=100, value=30)
|
| 39 |
+
gender = st.selectbox("Gender", ["Male", "Female"])
|
| 40 |
+
marital_status = st.selectbox("Marital Status", ["Single", "Married", "Divorced"])
|
| 41 |
+
occupation = st.selectbox(
|
| 42 |
+
"Occupation",
|
| 43 |
+
["Salaried", "Freelancer", "Business", "Student", "Retired", "Other"]
|
| 44 |
+
)
|
| 45 |
+
designation = st.text_input("Designation", value="")
|
| 46 |
+
|
| 47 |
+
city_tier = st.selectbox("City Tier", [1, 2, 3])
|
| 48 |
+
monthly_income = st.number_input(
|
| 49 |
+
"Monthly Income (Gross)", min_value=0, step=1000, value=50000
|
| 50 |
+
)
|
| 51 |
+
passport = st.selectbox("Valid Passport?", ["Yes", "No"])
|
| 52 |
+
own_car = st.selectbox("Owns a Car?", ["Yes", "No"])
|
| 53 |
+
number_of_persons = st.number_input(
|
| 54 |
+
"Number of People Visiting", min_value=1, max_value=10, value=2
|
| 55 |
+
)
|
| 56 |
+
number_of_children = st.number_input(
|
| 57 |
+
"Number of Children Under 5 Visiting", min_value=0, max_value=5, value=0
|
| 58 |
+
)
|
| 59 |
+
|
| 60 |
+
# -------------------------------------------------
|
| 61 |
+
# Customer Interaction Inputs
|
| 62 |
+
# -------------------------------------------------
|
| 63 |
+
type_of_contact = st.selectbox(
|
| 64 |
+
"Type of Contact", ["Company Invited", "Self Inquiry"]
|
| 65 |
+
)
|
| 66 |
+
product_pitched = st.selectbox(
|
| 67 |
+
"Product Pitched",
|
| 68 |
+
["Wellness Package", "Adventure Package", "Cultural Package", "Other"]
|
| 69 |
+
)
|
| 70 |
+
pitch_satisfaction = st.slider(
|
| 71 |
+
"Pitch Satisfaction Score", min_value=0, max_value=10, value=7
|
| 72 |
+
)
|
| 73 |
+
number_of_followups = st.number_input(
|
| 74 |
+
"Number of Follow-ups", min_value=0, max_value=20, value=1
|
| 75 |
+
)
|
| 76 |
+
duration_of_pitch = st.number_input(
|
| 77 |
+
"Duration of Pitch (minutes)", min_value=1, max_value=120, value=10
|
| 78 |
+
)
|
| 79 |
+
number_of_trips = st.number_input(
|
| 80 |
+
"Average Number of Trips per Year", min_value=0, max_value=50, value=2
|
| 81 |
+
)
|
| 82 |
+
preferred_property_star = st.number_input(
|
| 83 |
+
"Preferred Hotel Star Rating", min_value=1, max_value=5, value=3
|
| 84 |
+
)
|
| 85 |
+
|
| 86 |
+
# -------------------------------------------------
|
| 87 |
+
# Assemble Input DataFrame
|
| 88 |
+
# -------------------------------------------------
|
| 89 |
+
input_df = pd.DataFrame([{
|
| 90 |
+
"Age": age,
|
| 91 |
+
"Gender": gender,
|
| 92 |
+
"MaritalStatus": marital_status,
|
| 93 |
+
"Occupation": occupation,
|
| 94 |
+
"Designation": designation,
|
| 95 |
+
"CityTier": city_tier,
|
| 96 |
+
"MonthlyIncome": monthly_income,
|
| 97 |
+
"Passport": 1 if passport == "Yes" else 0,
|
| 98 |
+
"OwnCar": 1 if own_car == "Yes" else 0,
|
| 99 |
+
"NumberOfPersonVisiting": number_of_persons,
|
| 100 |
+
"NumberOfChildrenVisiting": number_of_children,
|
| 101 |
+
"TypeofContact": type_of_contact,
|
| 102 |
+
"ProductPitched": product_pitched,
|
| 103 |
+
"PitchSatisfactionScore": pitch_satisfaction,
|
| 104 |
+
"NumberOfFollowups": number_of_followups,
|
| 105 |
+
"DurationOfPitch": duration_of_pitch,
|
| 106 |
+
"NumberOfTrips": number_of_trips,
|
| 107 |
+
"PreferredPropertyStar": preferred_property_star
|
| 108 |
+
}])
|
| 109 |
+
|
| 110 |
+
# -------------------------------------------------
|
| 111 |
+
# Prediction & Display
|
| 112 |
+
# -------------------------------------------------
|
| 113 |
+
if st.button("Predict Purchase"):
|
| 114 |
+
pred = model.predict(input_df)[0]
|
| 115 |
+
label = "🚀 Will Purchase" if pred == 1 else "❌ Will Not Purchase"
|
| 116 |
+
st.subheader("Prediction Result")
|
| 117 |
+
st.success(label)
|
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
|