import streamlit as st import pandas as pd from huggingface_hub import hf_hub_download import joblib # Download and load the model from Hugging Face Hub model_path = hf_hub_download( repo_id="Sudu1976/tourismpkg_prediction_model", # Corrected repo_id filename="tourismpkg_prediction_model_v1.joblib" ) model = joblib.load(model_path) # Streamlit UI for Tourism Package Prediction st.title("Tourism Package Prediction App") st.write(""" This application predicts whether a customer will purchase the **Wellness Tourism Package** based on their details. Please enter the required information below to get a prediction. """) # User input age = st.number_input("Age", min_value=18, max_value=100, value=30, step=1) typeofcontact = st.selectbox("TypeofContact", ["Company Invited", "Self Inquiry"]) citytier = st.number_input("CityTier", min_value=1, max_value=3, value=1, step=1) occupation = st.selectbox("Occupation", ["Salaried", "Free Lancer", "Small Business", "Large Business"]) gender = st.selectbox("Gender", ["male", "female"]) nrofpersonvisiting = st.number_input("NumberOfPersonVisiting", min_value=1, max_value=8, value=2, step=1) prfpropertystar = st.number_input("PreferredPropertyStar", min_value=3, max_value=5, value=3, step=1) maritalstatus = st.selectbox("MaritalStatus", ["Single", "Married", "Unmarried", "Divorced"]) nroftrips = st.number_input("NumberOfTrips", min_value=1, max_value=20, value=3, step=1) passport = st.number_input("Passport", min_value=0, max_value=1, value=1, step=1) designation = st.selectbox("Designation", ["Manager", "Senior Manager", "Executive", "AVP", "VP"]) monthlyincome = st.number_input("MonthlyIncome", min_value=1000, max_value=40000, value=5000, step=100) csi = st.number_input("PitchSatisfactionScore", min_value=1, max_value=5, value=2, step=1) productpitched = st.selectbox("ProductPitched", ["Basic", "Standard", "Deluxe", "Super Deluxe", "King"]) nroffups = st.number_input("NumberOfFollowups", min_value=1, max_value=6, value=2, step=1) pitchduration = st.number_input("DurationOfPitch", min_value=5, max_value=40, value=10, step=1) # Assemble input into DataFrame input_data = pd.DataFrame([ { 'Age': age, 'TypeofContact': typeofcontact, 'CityTier': citytier, 'Occupation': occupation, 'Gender': gender, 'NumberOfPersonVisiting': nrofpersonvisiting, 'PreferredPropertyStar': prfpropertystar, 'MaritalStatus': maritalstatus, 'NumberOfTrips': nroftrips, 'Passport': passport, 'Designation': designation, 'MonthlyIncome': monthlyincome, # Fixed typo here 'PitchSatisfactionScore': csi, 'ProductPitched' : productpitched, 'NumberOfFollowups' : nroffups, 'DurationOfPitch' :pitchduration }]) # Prediction if st.button("Predict Purchase"): # The model expects raw categorical features, which its internal preprocessor will handle. # The model's predict method should handle the transformation. prediction_proba = model.predict_proba(input_data)[:, 1] # Using a classification threshold, let's say 0.45, to decide on the class. classification_threshold = 0.45 if prediction_proba[0] >= classification_threshold: st.success(f"Prediction: Customer is likely to purchase the Wellness Tourism Package (Probability: {prediction_proba[0]:.2f})") else: st.info(f"Prediction: Customer is unlikely to purchase the Wellness Tourism Package (Probability: {prediction_proba[0]:.2f})")