Spaces:
Sleeping
Sleeping
File size: 6,838 Bytes
b45d5bf d395486 745b714 7617592 745b714 b45d5bf d395486 b45d5bf 745b714 b45d5bf 7233e4d b45d5bf 745b714 b45d5bf 745b714 b45d5bf 745b714 1cd6e45 d395486 745b714 b45d5bf 745b714 72a5a3d b45d5bf 72a5a3d d395486 72a5a3d b45d5bf 72a5a3d b45d5bf 745b714 d395486 745b714 d395486 72a5a3d b45d5bf 745b714 72a5a3d 745b714 72a5a3d 745b714 d395486 72a5a3d b45d5bf 745b714 d395486 72a5a3d 745b714 b45d5bf 745b714 d395486 72a5a3d 745b714 72a5a3d d395486 745b714 72a5a3d b45d5bf d395486 745b714 b45d5bf d395486 745b714 d395486 745b714 72a5a3d 745b714 72a5a3d 745b714 d395486 72a5a3d 745b714 72a5a3d 745b714 b45d5bf 745b714 d395486 745b714 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 | import streamlit as st
import pandas as pd
import numpy as np
import joblib
from huggingface_hub import hf_hub_download
st.set_page_config(
page_title="Tourism Package Predictor",
page_icon="✈️",
layout="wide"
)
st.title(" Wellness Tourism Package Purchase Predictor")
st.markdown("""
This application predicts whether a customer is likely to purchase the Wellness Tourism Package.
Enter customer details below to get a prediction.
""")
@st.cache_resource
def load_model():
try:
model_path = hf_hub_download(
repo_id='SharleyK/TourismPackagePrediction-Model',
filename='best_model.pkl'
)
model = joblib.load(model_path)
return model
except Exception as e:
st.error(f"Error loading model: {e}")
return None
model = load_model()
st.header("Customer Information")
col1, col2, col3 = st.columns(3)
with col1:
age = st.number_input("Age", min_value=18, max_value=100, value=30)
city_tier = st.selectbox("City Tier", [1, 2, 3])
duration_of_pitch = st.number_input("Duration of Pitch (minutes)", min_value=0.0, value=15.0)
occupation = st.selectbox("Occupation", ['Salaried', 'Small Business', 'Large Business', 'Free Lancer'])
gender = st.selectbox("Gender", ['Male', 'Female'])
with col2:
num_persons = st.number_input("Number of Persons Visiting", min_value=1, max_value=10, value=2)
num_followups = st.number_input("Number of Followups", min_value=0.0, value=3.0)
product_pitched = st.selectbox("Product Pitched", ['Basic', 'Standard', 'Deluxe', 'Super Deluxe', 'King'])
preferred_star = st.selectbox("Preferred Property Star", [3.0, 4.0, 5.0])
marital_status = st.selectbox("Marital Status", ['Single', 'Married', 'Divorced', 'Unmarried'])
with col3:
num_trips = st.number_input("Number of Trips Per Year", min_value=0.0, value=2.0)
passport = st.selectbox("Has Passport", [0, 1], format_func=lambda x: "Yes" if x == 1 else "No")
pitch_satisfaction = st.slider("Pitch Satisfaction Score", 1, 5, 3)
own_car = st.selectbox("Owns Car", [0, 1], format_func=lambda x: "Yes" if x == 1 else "No")
num_children = st.number_input("Number of Children Visiting", min_value=0.0, value=0.0)
col4, col5 = st.columns(2)
with col4:
designation = st.selectbox("Designation", ['Executive', 'Manager', 'Senior Manager', 'AVP', 'VP'])
with col5:
monthly_income = st.number_input("Monthly Income", min_value=0.0, value=25000.0)
type_of_contact = st.selectbox("Type of Contact", ['Company Invited', 'Self Inquiry'])
occupation_map = {'Salaried': 0, 'Small Business': 1, 'Large Business': 2, 'Free Lancer': 3}
product_map = {'Basic': 0, 'Standard': 1, 'Deluxe': 2, 'Super Deluxe': 3, 'King': 4}
marital_map = {'Single': 0, 'Married': 1, 'Divorced': 2, 'Unmarried': 3}
designation_map = {'Executive': 0, 'Manager': 1, 'Senior Manager': 2, 'AVP': 3, 'VP': 4}
if st.button(" Predict Purchase Probability", type="primary"):
if model is not None:
try:
input_data = pd.DataFrame({
'Age': [age],
'TypeofContact': [1 if type_of_contact == 'Company Invited' else 0],
'CityTier': [city_tier],
'DurationOfPitch': [duration_of_pitch],
'Occupation': [occupation_map[occupation]],
'Gender': [0 if gender == 'Male' else 1],
'NumberOfPersonVisiting': [num_persons],
'NumberOfFollowups': [num_followups],
'ProductPitched': [product_map[product_pitched]],
'PreferredPropertyStar': [preferred_star],
'MaritalStatus': [marital_map[marital_status]],
'NumberOfTrips': [num_trips],
'Passport': [passport],
'PitchSatisfactionScore': [pitch_satisfaction],
'OwnCar': [own_car],
'NumberOfChildrenVisiting': [num_children],
'Designation': [designation_map[designation]],
'MonthlyIncome': [monthly_income]
})
prediction = model.predict(input_data)[0]
probability = model.predict_proba(input_data)[0]
st.success(" Prediction Complete!")
col_pred1, col_pred2 = st.columns(2)
with col_pred1:
if prediction == 1:
st.metric("Prediction", " Will Purchase", delta="High Priority")
else:
st.metric("Prediction", " Will Not Purchase", delta="Low Priority")
with col_pred2:
confidence = max(probability) * 100
st.metric("Confidence", f"{confidence:.2f}%")
st.progress(confidence / 100)
st.markdown("---")
st.subheader(" Recommendation")
if prediction == 1:
st.balloons()
st.success("""
**High Conversion Probability!**
This customer shows strong indicators for purchase:
- Consider prioritizing this lead
- Assign to experienced sales representative
- Offer personalized package options
- Schedule follow-up within 24-48 hours
""")
else:
st.warning("""
**Requires More Engagement**
This customer may need additional nurturing:
- Schedule more follow-up calls
- Provide tailored promotional offers
- Share customer testimonials and reviews
- Highlight unique package benefits
""")
with st.expander(" View Input Summary"):
st.dataframe(input_data, use_container_width=True)
except Exception as e:
st.error(f" Prediction error: {e}")
st.info("Please ensure all fields are filled correctly.")
else:
st.error(" Model not loaded. Please check the configuration.")
with st.sidebar:
st.header(" About")
st.markdown("""
This ML-powered application helps **Visit with Us** identify potential customers
for the Wellness Tourism Package.
**Features:**
- AI-powered predictions
- Confidence scores
- Actionable recommendations
- Real-time results
**Model Info:**
- Algorithm: Ensemble ML Models
- Accuracy: 85%+
- Training Data: 4,000+ customers
""")
st.markdown("---")
st.markdown("**Need Help?**")
st.markdown("Contact: support@visitwithus.com")
st.markdown("---")
st.markdown("""
<div style='text-align: center'>
<p>Built with using Streamlit | Powered by <b>Visit with Us</b></p>
<p style='font-size: 12px; color: gray;'>MLOps Pipeline • Hugging Face Deployment • Real-time Predictions</p>
</div>
""", unsafe_allow_html=True)
|