Prashantbhat1607 commited on
Commit
3a1b0bd
·
verified ·
1 Parent(s): 9d17f57

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +46 -57
app.py CHANGED
@@ -1,59 +1,48 @@
1
- import streamlit as st
2
- import pandas as pd
3
  import joblib
4
- import numpy as np
5
-
6
- # Load assets
7
- model = joblib.load("model.pkl")
8
- mappings = joblib.load(".pkl")
9
- features = joblib.load("features.pkl")
10
-
11
- st.set_page_config(page_title="Visit with Us - Predictor", layout="wide")
12
-
13
- st.title("🏝️ Wellness Tourism Package Predictor")
14
- st.markdown("Predict if a customer will purchase the new Wellness Package based on their profile.")
15
-
16
- with st.sidebar:
17
- st.header("Customer Profile")
18
- age = st.number_input("Age", 18, 100, 35)
19
- gender = st.selectbox("Gender", list(mappings['Gender'].keys()))
20
- income = st.number_input("Monthly Income", 0, 100000, 25000)
21
- passport = st.selectbox("Has Passport? (1=Yes, 0=No)", [0, 1])
22
-
23
- col1, col2 = st.columns(2)
24
- with col1:
25
- contact = st.selectbox("Type of Contact", list(mappings['TypeofContact'].keys()))
26
- occupation = st.selectbox("Occupation", list(mappings['Occupation'].keys()))
27
- marital = st.selectbox("Marital Status", list(mappings['MaritalStatus'].keys()))
28
- designation = st.selectbox("Designation", list(mappings['Designation'].keys()))
29
-
30
- with col2:
31
- pitch_dur = st.slider("Duration of Pitch (min)", 5, 60, 15)
32
- pitch_sat = st.slider("Pitch Satisfaction Score", 1, 5, 3)
33
- trips = st.number_input("Number of Trips per Year", 0, 20, 2)
34
- property_star = st.selectbox("Preferred Property Star", [3, 4, 5])
35
-
36
- # Prepare input data
37
- input_dict = {
38
- 'Age': age, 'TypeofContact': mappings['TypeofContact'][contact],
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
- st.warning(f"❌ LOW POTENTIAL: {prob*100:.1f}% chance of purchase.")
 
 
 
 
 
 
 
 
 
 
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}**")