tourism_model / src /streamlit_app.py
Harini2973's picture
Update src/streamlit_app.py
157042e verified
Raw
History Blame Contribute Delete
2.51 kB
import streamlit as st
import pandas as pd
import joblib
st.title("Tourism Prediction App")
# Loading model
try:
model = joblib.load("src/model.pkl")
st.success("Model loaded successfully!")
except Exception as e:
st.error(f"Model failed to load: {e}")
st.stop()
st.header("Enter Customer Details")
# Numerical inputs
age = st.number_input("Age", 18, 100, 30)
income = st.number_input("Monthly Income", 0, 1000000, 50000)
duration_pitch = st.number_input("Duration Of Pitch", 0, 100, 10)
num_person = st.number_input("Number Of Persons Visiting", 1, 10, 2)
num_followups = st.number_input("Number Of Followups", 0, 10, 2)
num_trips = st.number_input("Number Of Trips", 0, 50, 5)
pitch_score = st.number_input("Pitch Satisfaction Score", 1, 5, 3)
children = st.number_input("Number Of Children Visiting", 0, 5, 0)
property_star = st.number_input("Preferred Property Star", 1, 5, 3)
# Categorical inputs
gender = st.selectbox("Gender", ["Male", "Female"])
marital = st.selectbox("Marital Status", ["Single", "Married"])
occupation = st.selectbox("Occupation", ["Salaried", "Self Employed", "Student"])
designation = st.selectbox("Designation", ["Manager", "Executive", "Senior Manager", "AVP", "VP"])
product = st.selectbox("Product Pitched", ["Basic", "Standard", "Deluxe", "Super Deluxe"])
contact = st.selectbox("Type of Contact", ["Company Invited", "Self Enquiry"])
city = st.selectbox("City Tier", [1, 2, 3])
passport = st.selectbox("Passport", [0, 1])
own_car = st.selectbox("Own Car", [0, 1])
# Prediction
if st.button("Predict"):
try:
input_df = pd.DataFrame([{
"Age": age,
"TypeofContact": contact,
"CityTier": city,
"DurationOfPitch": duration_pitch,
"Occupation": occupation,
"Gender": gender,
"NumberOfPersonVisiting": num_person,
"NumberOfFollowups": num_followups,
"ProductPitched": product,
"PreferredPropertyStar": property_star,
"MaritalStatus": marital,
"NumberOfTrips": num_trips,
"Passport": passport,
"PitchSatisfactionScore": pitch_score,
"OwnCar": own_car,
"NumberOfChildrenVisiting": children,
"Designation": designation,
"MonthlyIncome": income
}])
prediction = model.predict(input_df)
st.success(f"Prediction: {prediction[0]}")
except Exception as e:
st.error(f"Error during prediction: {e}")