Spaces:
Build error
Build error
Upload app.py with huggingface_hub
Browse files
app.py
CHANGED
|
@@ -1,59 +1,48 @@
|
|
| 1 |
-
import
|
| 2 |
-
import pandas as pd
|
| 3 |
import joblib
|
| 4 |
-
import
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
st.
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
'CityTier': 1, 'DurationOfPitch': pitch_dur,
|
| 40 |
-
'Occupation': mappings['Occupation'][occupation], 'Gender': mappings['Gender'][gender],
|
| 41 |
-
'NumberOfPersonVisiting': 2, 'NumberOfFollowups': 3,
|
| 42 |
-
'ProductPitched': mappings['ProductPitched']['Basic'], # Default for prediction
|
| 43 |
-
'PreferredPropertyStar': property_star, 'MaritalStatus': mappings['MaritalStatus'][marital],
|
| 44 |
-
'NumberOfTrips': trips, 'Passport': passport, 'PitchSatisfactionScore': pitch_sat,
|
| 45 |
-
'OwnCar': 1, 'NumberOfChildrenVisiting': 1,
|
| 46 |
-
'Designation': mappings['Designation'][designation], 'MonthlyIncome': income
|
| 47 |
-
}
|
| 48 |
-
|
| 49 |
-
# Ensure feature order matches training
|
| 50 |
-
input_df = pd.DataFrame([input_dict])[features]
|
| 51 |
-
|
| 52 |
-
if st.button("Calculate Purchase Probability"):
|
| 53 |
-
prediction = model.predict(input_df)[0]
|
| 54 |
-
prob = model.predict_proba(input_df)[0][1]
|
| 55 |
-
|
| 56 |
-
if prediction == 1:
|
| 57 |
-
st.success(f"✅ HIGH POTENTIAL: {prob*100:.1f}% chance of purchase.")
|
| 58 |
else:
|
| 59 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json
|
|
|
|
| 2 |
import joblib
|
| 3 |
+
import pandas as pd
|
| 4 |
+
import streamlit as st
|
| 5 |
+
from huggingface_hub import hf_hub_download
|
| 6 |
+
|
| 7 |
+
# ========= CONFIG (YOUR EXACT DETAILS) =========
|
| 8 |
+
MODEL_REPO = "Prashantbhat1607/wellness-tourism-model" # <-- your HF model repo
|
| 9 |
+
MODEL_FILE = "model.joblib"
|
| 10 |
+
META_FILE = "model_meta.json"
|
| 11 |
+
# ==============================================
|
| 12 |
+
|
| 13 |
+
st.set_page_config(page_title="Wellness Tourism Predictor", layout="centered")
|
| 14 |
+
st.title("🏝️ Wellness Tourism Purchase Predictor")
|
| 15 |
+
st.write("Predict whether a customer will purchase the Wellness Tourism Package (ProdTaken).")
|
| 16 |
+
|
| 17 |
+
@st.cache_resource
|
| 18 |
+
def load_artifacts():
|
| 19 |
+
model_path = hf_hub_download(repo_id=MODEL_REPO, filename=MODEL_FILE, repo_type="model")
|
| 20 |
+
meta_path = hf_hub_download(repo_id=MODEL_REPO, filename=META_FILE, repo_type="model")
|
| 21 |
+
model = joblib.load(model_path)
|
| 22 |
+
with open(meta_path, "r") as f:
|
| 23 |
+
meta = json.load(f)
|
| 24 |
+
return model, meta
|
| 25 |
+
|
| 26 |
+
model, meta = load_artifacts()
|
| 27 |
+
features = meta["features"]
|
| 28 |
+
cat_cols = set(meta["categorical_cols"])
|
| 29 |
+
num_cols = set(meta["numeric_cols"])
|
| 30 |
+
|
| 31 |
+
st.subheader("Enter customer details")
|
| 32 |
+
|
| 33 |
+
inputs = {}
|
| 34 |
+
for col in features:
|
| 35 |
+
if col in cat_cols:
|
| 36 |
+
# free text input for categorical
|
| 37 |
+
inputs[col] = st.text_input(col, value="")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
else:
|
| 39 |
+
# numeric input
|
| 40 |
+
inputs[col] = st.number_input(col, value=0.0)
|
| 41 |
+
|
| 42 |
+
if st.button("Predict"):
|
| 43 |
+
X = pd.DataFrame([inputs], columns=features)
|
| 44 |
+
proba = model.predict_proba(X)[0][1]
|
| 45 |
+
pred = int(proba >= 0.5)
|
| 46 |
+
|
| 47 |
+
st.success(f"Prediction: {'✅ Will Purchase (Yes)' if pred==1 else '❌ Will NOT Purchase (No)'}")
|
| 48 |
+
st.write(f"Probability of purchase: **{proba:.3f}**")
|