Prashantbhat1607's picture
Update app.py
fb06afa verified
import streamlit as st
st.write("βœ… NEW APP VERSION LOADED - COMMIT TEST")
import json
import joblib
import pandas as pd
import streamlit as st
from huggingface_hub import hf_hub_download
# ================= CONFIG =================
MODEL_REPO = "Prashantbhat1607/wellness-tourism-model"
MODEL_FILE = "model.joblib"
META_FILE = "model_meta.json"
# ==========================================
st.set_page_config(page_title="Wellness Tourism Predictor", layout="centered")
st.title("🏝️ Wellness Tourism Purchase Predictor")
st.write("Predict whether a customer will purchase the Wellness Tourism Package.")
@st.cache_resource
def load_model_and_meta():
model_path = hf_hub_download(
repo_id=MODEL_REPO,
filename=MODEL_FILE,
repo_type="model"
)
meta_path = hf_hub_download(
repo_id=MODEL_REPO,
filename=META_FILE,
repo_type="model"
)
model = joblib.load(model_path)
with open(meta_path, "r") as f:
meta = json.load(f)
return model, meta
model, meta = load_model_and_meta()
features = meta["features"]
cat_cols = set(meta["categorical_cols"])
num_cols = set(meta["numeric_cols"])
st.subheader("Enter customer details")
inputs = {}
for col in features:
if col in cat_cols:
inputs[col] = st.text_input(col, value="Unknown")
else:
inputs[col] = st.number_input(col, value=0.0)
if st.button("Predict"):
X = pd.DataFrame([inputs], columns=features)
proba = model.predict_proba(X)[0][1]
pred = int(proba >= 0.5)
st.success(
f"Prediction: {'βœ… Will Purchase' if pred==1 else '❌ Will NOT Purchase'}"
)
st.write(f"Probability of purchase: **{proba:.3f}**")