import streamlit as st import pandas as pd import joblib # Load model model = joblib.load("model.pkl") st.title("Tourism Prediction App") # ------------------------- # INPUT FIELDS (YOUR UI) # ------------------------- Age = st.slider("Age", 18, 70, 30) TypeofContact = st.selectbox("Type of Contact", ["Self Enquiry", "Company Invited"]) CityTier = st.selectbox("City Tier", [1, 2, 3]) DurationOfPitch = st.slider("Duration of Pitch (mins)", 0, 100, 15) Occupation = st.selectbox("Occupation", ["Salaried", "Small Business", "Large Business", "Free Lancer"]) Gender = st.selectbox("Gender", ["Male", "Female", "Others"]) NumberOfPersonVisiting = st.slider("Number of Persons Visiting", 1, 5, 2) NumberOfFollowups = st.slider("Number of Follow-ups", 1, 10, 3) ProductPitched = st.selectbox("Product Pitched", ["Basic", "Standard", "Deluxe", "Super Deluxe", "King"]) PreferredPropertyStar = st.selectbox("Preferred Property Star", [1, 2, 3, 4, 5]) MaritalStatus = st.selectbox("Marital Status", ["Married", "Single", "Divorced", "Unmarried"]) NumberOfTrips = st.slider("Number of Trips", 1, 20, 3) Passport = st.selectbox("Has Passport?", ["Yes", "No"]) PitchSatisfactionScore = st.slider("Pitch Satisfaction Score", 1, 5, 3) OwnCar = st.selectbox("Owns a Car?", ["Yes", "No"]) NumberOfChildrenVisiting = st.slider("Number of Children Visited", 0, 5, 1) Designation = st.selectbox("Designation", ["Executive", "Manager", "AVP", "VP", "Sr. Manager"]) MonthlyIncome = st.number_input("Monthly Income", min_value=1000.0, value=30000.0) # ------------------------- # VALUE FIXING # ------------------------- # Convert Yes/No → 1/0 Passport = 1 if Passport == "Yes" else 0 OwnCar = 1 if OwnCar == "Yes" else 0 # Fix category mismatches (VERY IMPORTANT) if Designation == "Sr. Manager": Designation = "Senior Manager" if MaritalStatus == "Unmarried": MaritalStatus = "Single" # ------------------------- # PREDICTION # ------------------------- if st.button("Predict"): try: input_data = pd.DataFrame([[ Age, TypeofContact, CityTier, DurationOfPitch, Occupation, Gender, NumberOfPersonVisiting, NumberOfFollowups, ProductPitched, PreferredPropertyStar, MaritalStatus, NumberOfTrips, Passport, PitchSatisfactionScore, OwnCar, NumberOfChildrenVisiting, Designation, MonthlyIncome ]], columns=[ 'Age', 'TypeofContact', 'CityTier', 'DurationOfPitch', 'Occupation', 'Gender', 'NumberOfPersonVisiting', 'NumberOfFollowups', 'ProductPitched', 'PreferredPropertyStar', 'MaritalStatus', 'NumberOfTrips', 'Passport', 'PitchSatisfactionScore', 'OwnCar', 'NumberOfChildrenVisiting', 'Designation', 'MonthlyIncome' ]) st.write("Input Data:", input_data) prediction = model.predict(input_data) st.success(f"Prediction: {prediction[0]}") except Exception as e: st.error(f"Error: {e}")