| | import json |
| | import joblib |
| | import pandas as pd |
| | import streamlit as st |
| | from pathlib import Path |
| |
|
| | st.set_page_config(page_title="Wellness Predictor", layout="centered") |
| | st.title("ποΈ Wellness Tourism Purchase Predictor") |
| | st.caption("Predict whether a customer will purchase the Wellness Tourism Package") |
| |
|
| | MODEL_PATH = Path("model.pkl") |
| | META_PATH = Path("model_meta.json") |
| |
|
| | @st.cache_resource |
| | def load_artifacts(): |
| | if not MODEL_PATH.exists(): |
| | raise FileNotFoundError("model.pkl not found in Space repo root.") |
| | if not META_PATH.exists(): |
| | raise FileNotFoundError("model_meta.json not found in Space repo root.") |
| |
|
| | model = joblib.load(MODEL_PATH) |
| | meta = json.loads(META_PATH.read_text()) |
| | return model, meta |
| |
|
| | model, meta = load_artifacts() |
| | features = meta["features"] |
| | cat_cols = set(meta["categorical_cols"]) |
| | num_cols = set(meta["numeric_cols"]) |
| |
|
| | st.subheader("Enter customer details") |
| |
|
| | inputs = {} |
| | with st.form("predict_form"): |
| | for col in features: |
| | if col in cat_cols: |
| | |
| | inputs[col] = st.text_input(col, value="Unknown") |
| | else: |
| | |
| | if any(k in col.lower() for k in ["number", "count", "passport", "children", "car", "trips"]): |
| | inputs[col] = st.number_input(col, min_value=0, value=0, step=1) |
| | else: |
| | inputs[col] = st.number_input(col, value=0.0) |
| |
|
| | submitted = st.form_submit_button("Predict") |
| |
|
| | if submitted: |
| | X = pd.DataFrame([inputs], columns=features) |
| |
|
| | |
| | |
| | proba = float(model.predict_proba(X)[0][1]) |
| | pred = int(proba >= 0.5) |
| |
|
| | st.success("Will Purchase β
" if pred == 1 else "Will NOT Purchase β") |
| | st.write(f"Probability: **{proba:.3f}**") |
| |
|
| |
|