Upload folder using huggingface_hub
Browse files
app.py
CHANGED
|
@@ -4,19 +4,23 @@ import joblib
|
|
| 4 |
|
| 5 |
from huggingface_hub import hf_hub_download
|
| 6 |
|
|
|
|
|
|
|
|
|
|
| 7 |
MODEL_REPO_ID = "bhumitps/tourism_model"
|
| 8 |
MODEL_FILENAME = "best_tourism_model_v3.joblib"
|
| 9 |
|
| 10 |
|
| 11 |
@st.cache_resource
|
| 12 |
def load_model():
|
| 13 |
-
|
|
|
|
| 14 |
try:
|
| 15 |
model_path = hf_hub_download(
|
| 16 |
repo_id=MODEL_REPO_ID,
|
| 17 |
filename=MODEL_FILENAME,
|
| 18 |
repo_type="model",
|
| 19 |
-
force_download=True,
|
| 20 |
)
|
| 21 |
model = joblib.load(model_path)
|
| 22 |
st.write("Model loaded successfully.")
|
|
@@ -28,11 +32,15 @@ def load_model():
|
|
| 28 |
|
| 29 |
model = load_model()
|
| 30 |
|
|
|
|
|
|
|
|
|
|
| 31 |
st.title("Wellness Tourism Package Purchase Prediction")
|
| 32 |
|
| 33 |
st.write(
|
| 34 |
"""
|
| 35 |
-
Predict whether a customer is likely to purchase the
|
|
|
|
| 36 |
|
| 37 |
Fill in the customer details below and click **Predict**.
|
| 38 |
"""
|
|
@@ -44,56 +52,102 @@ col1, col2 = st.columns(2)
|
|
| 44 |
with col1:
|
| 45 |
Age = st.number_input("Age", min_value=0, max_value=100, value=35)
|
| 46 |
CityTier = st.selectbox("CityTier", options=[1, 2, 3], index=0)
|
| 47 |
-
DurationOfPitch = st.number_input(
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
|
| 55 |
with col2:
|
| 56 |
-
TypeofContact = st.selectbox(
|
| 57 |
-
|
| 58 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
ProductPitched = st.text_input("ProductPitched (raw value)", value="Basic")
|
| 60 |
-
MaritalStatus = st.selectbox(
|
|
|
|
|
|
|
| 61 |
Passport = st.selectbox("Passport", options=["No", "Yes"])
|
| 62 |
-
PitchSatisfactionScore = st.selectbox(
|
|
|
|
|
|
|
| 63 |
OwnCar = st.selectbox("OwnCar", options=["No", "Yes"])
|
| 64 |
-
Designation = st.selectbox(
|
|
|
|
|
|
|
|
|
|
| 65 |
|
| 66 |
st.markdown("---")
|
| 67 |
|
|
|
|
|
|
|
|
|
|
| 68 |
if st.button("Predict"):
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
pred_proba = model.predict_proba(input_data)[0][1]
|
| 91 |
pred_label = model.predict(input_data)[0]
|
| 92 |
|
| 93 |
st.subheader("Prediction Result")
|
| 94 |
if pred_label == 1:
|
| 95 |
-
st.success(
|
|
|
|
|
|
|
|
|
|
| 96 |
else:
|
| 97 |
-
st.info(
|
|
|
|
|
|
|
|
|
|
| 98 |
|
| 99 |
st.caption("Note: probabilities are model-based estimates and not guarantees.")
|
|
|
|
| 4 |
|
| 5 |
from huggingface_hub import hf_hub_download
|
| 6 |
|
| 7 |
+
# -------------------------------------------------------------------
|
| 8 |
+
# CONFIG
|
| 9 |
+
# -------------------------------------------------------------------
|
| 10 |
MODEL_REPO_ID = "bhumitps/tourism_model"
|
| 11 |
MODEL_FILENAME = "best_tourism_model_v3.joblib"
|
| 12 |
|
| 13 |
|
| 14 |
@st.cache_resource
|
| 15 |
def load_model():
|
| 16 |
+
"""Download the model from HF Hub and load it with joblib."""
|
| 17 |
+
st.write("Loading model from Hugging Face Hub...")
|
| 18 |
try:
|
| 19 |
model_path = hf_hub_download(
|
| 20 |
repo_id=MODEL_REPO_ID,
|
| 21 |
filename=MODEL_FILENAME,
|
| 22 |
repo_type="model",
|
| 23 |
+
force_download=True, # always fetch latest v3 model
|
| 24 |
)
|
| 25 |
model = joblib.load(model_path)
|
| 26 |
st.write("Model loaded successfully.")
|
|
|
|
| 32 |
|
| 33 |
model = load_model()
|
| 34 |
|
| 35 |
+
# -------------------------------------------------------------------
|
| 36 |
+
# UI
|
| 37 |
+
# -------------------------------------------------------------------
|
| 38 |
st.title("Wellness Tourism Package Purchase Prediction")
|
| 39 |
|
| 40 |
st.write(
|
| 41 |
"""
|
| 42 |
+
Predict whether a customer is likely to purchase the
|
| 43 |
+
**Wellness Tourism Package**.
|
| 44 |
|
| 45 |
Fill in the customer details below and click **Predict**.
|
| 46 |
"""
|
|
|
|
| 52 |
with col1:
|
| 53 |
Age = st.number_input("Age", min_value=0, max_value=100, value=35)
|
| 54 |
CityTier = st.selectbox("CityTier", options=[1, 2, 3], index=0)
|
| 55 |
+
DurationOfPitch = st.number_input(
|
| 56 |
+
"DurationOfPitch (minutes)", min_value=0, max_value=300, value=15
|
| 57 |
+
)
|
| 58 |
+
NumberOfPersonVisiting = st.number_input(
|
| 59 |
+
"NumberOfPersonVisiting", min_value=1, max_value=20, value=2
|
| 60 |
+
)
|
| 61 |
+
NumberOfFollowups = st.number_input(
|
| 62 |
+
"NumberOfFollowups", min_value=0, max_value=20, value=2
|
| 63 |
+
)
|
| 64 |
+
PreferredPropertyStar = st.selectbox(
|
| 65 |
+
"PreferredPropertyStar", options=[1, 2, 3, 4, 5], index=2
|
| 66 |
+
)
|
| 67 |
+
NumberOfTrips = st.number_input(
|
| 68 |
+
"NumberOfTrips", min_value=0, max_value=50, value=1
|
| 69 |
+
)
|
| 70 |
+
NumberOfChildrenVisiting = st.number_input(
|
| 71 |
+
"NumberOfChildrenVisiting", min_value=0, max_value=10, value=0
|
| 72 |
+
)
|
| 73 |
+
MonthlyIncome = st.number_input(
|
| 74 |
+
"MonthlyIncome", min_value=0, max_value=1_000_000, value=50_000, step=1000
|
| 75 |
+
)
|
| 76 |
|
| 77 |
with col2:
|
| 78 |
+
TypeofContact = st.selectbox(
|
| 79 |
+
"TypeofContact",
|
| 80 |
+
options=["Self Enquiry", "Company Invited", "Other"],
|
| 81 |
+
)
|
| 82 |
+
Occupation = st.selectbox(
|
| 83 |
+
"Occupation", options=["Salaried", "Self Employed", "Free Lancer", "Other"]
|
| 84 |
+
)
|
| 85 |
+
Gender = st.selectbox(
|
| 86 |
+
"Gender", options=["Male", "Female", "Other"]
|
| 87 |
+
)
|
| 88 |
ProductPitched = st.text_input("ProductPitched (raw value)", value="Basic")
|
| 89 |
+
MaritalStatus = st.selectbox(
|
| 90 |
+
"MaritalStatus", options=["Married", "Single", "Divorced", "Other"]
|
| 91 |
+
)
|
| 92 |
Passport = st.selectbox("Passport", options=["No", "Yes"])
|
| 93 |
+
PitchSatisfactionScore = st.selectbox(
|
| 94 |
+
"PitchSatisfactionScore", options=[1, 2, 3, 4, 5], index=2
|
| 95 |
+
)
|
| 96 |
OwnCar = st.selectbox("OwnCar", options=["No", "Yes"])
|
| 97 |
+
Designation = st.selectbox(
|
| 98 |
+
"Designation",
|
| 99 |
+
options=["Executive", "Manager", "Senior Manager", "AVP", "VP", "Other"],
|
| 100 |
+
)
|
| 101 |
|
| 102 |
st.markdown("---")
|
| 103 |
|
| 104 |
+
# -------------------------------------------------------------------
|
| 105 |
+
# Prediction
|
| 106 |
+
# -------------------------------------------------------------------
|
| 107 |
if st.button("Predict"):
|
| 108 |
+
# Map Yes/No to the numeric format used during training (0/1)
|
| 109 |
+
passport_num = 1 if Passport == "Yes" else 0
|
| 110 |
+
owncar_num = 1 if OwnCar == "Yes" else 0
|
| 111 |
+
|
| 112 |
+
input_data = pd.DataFrame(
|
| 113 |
+
[
|
| 114 |
+
{
|
| 115 |
+
"Age": Age,
|
| 116 |
+
"TypeofContact": TypeofContact,
|
| 117 |
+
"CityTier": CityTier,
|
| 118 |
+
"DurationOfPitch": DurationOfPitch,
|
| 119 |
+
"Occupation": Occupation,
|
| 120 |
+
"Gender": Gender,
|
| 121 |
+
"NumberOfPersonVisiting": NumberOfPersonVisiting,
|
| 122 |
+
"NumberOfFollowups": NumberOfFollowups,
|
| 123 |
+
"ProductPitched": ProductPitched,
|
| 124 |
+
"PreferredPropertyStar": PreferredPropertyStar,
|
| 125 |
+
"MaritalStatus": MaritalStatus,
|
| 126 |
+
"NumberOfTrips": NumberOfTrips,
|
| 127 |
+
"Passport": passport_num, # numeric
|
| 128 |
+
"PitchSatisfactionScore": PitchSatisfactionScore,
|
| 129 |
+
"OwnCar": owncar_num, # numeric
|
| 130 |
+
"NumberOfChildrenVisiting": NumberOfChildrenVisiting,
|
| 131 |
+
"Designation": Designation,
|
| 132 |
+
"MonthlyIncome": MonthlyIncome,
|
| 133 |
+
}
|
| 134 |
+
]
|
| 135 |
+
)
|
| 136 |
+
|
| 137 |
+
# Make prediction
|
| 138 |
pred_proba = model.predict_proba(input_data)[0][1]
|
| 139 |
pred_label = model.predict(input_data)[0]
|
| 140 |
|
| 141 |
st.subheader("Prediction Result")
|
| 142 |
if pred_label == 1:
|
| 143 |
+
st.success(
|
| 144 |
+
f"Customer is **LIKELY** to purchase the Wellness Tourism Package. "
|
| 145 |
+
f"(Probability: {pred_proba:.2%})"
|
| 146 |
+
)
|
| 147 |
else:
|
| 148 |
+
st.info(
|
| 149 |
+
f"Customer is **UNLIKELY** to purchase the Wellness Tourism Package. "
|
| 150 |
+
f"(Probability: {pred_proba:.2%})"
|
| 151 |
+
)
|
| 152 |
|
| 153 |
st.caption("Note: probabilities are model-based estimates and not guarantees.")
|