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("""
Built with using Streamlit | Powered by Visit with Us
MLOps Pipeline • Hugging Face Deployment • Real-time Predictions