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