Spaces:
Sleeping
Sleeping
File size: 6,522 Bytes
a007fc2 b3dcaf4 a007fc2 b3dcaf4 a007fc2 b3dcaf4 a007fc2 b3dcaf4 43415ae 019f225 43415ae 08527e5 43415ae b3dcaf4 43415ae be1b8e6 43415ae b3dcaf4 43415ae 89b148d 43415ae 89b148d 5e7395a 89b148d 019f225 89b148d 5e7395a 87c753b 812e763 87c753b 4118d0a 63cb463 2061f2c 43415ae 812e763 07fcd30 89b148d 0d66391 812e763 07fcd30 89b148d 2061f2c 07fcd30 4118d0a 9e70f1d 07fcd30 89b148d 5e7395a 2061f2c 43f2c15 63cb463 812e763 4118d0a 63cb463 87c753b 812e763 87c753b be1b8e6 94cdaa2 63cb463 43f2c15 43415ae 812e763 07fcd30 63cb463 812e763 63cb463 9e70f1d 07fcd30 9e70f1d 63cb463 0d66391 87c753b 812e763 87c753b be1b8e6 94cdaa2 63cb463 2061f2c 0d66391 812e763 43415ae 63cb463 4118d0a 2061f2c 9e70f1d 2061f2c 07fcd30 2061f2c 43f2c15 5e7395a 43415ae b29c4c3 4118d0a b29c4c3 87c753b 43415ae 87c753b 43415ae 5e7395a 43415ae c3688c3 5e7395a 43415ae cb274c9 be1b8e6 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 |
# import streamlit library for IO
import streamlit as st
# import pandas
import pandas as pd
# library to download fine from Hugging Face
from huggingface_hub import hf_hub_download
# library to load model
import joblib
# ---------------------------------------------------------
# PAGE CONFIG
# ---------------------------------------------------------
st.set_page_config(
page_title="Tourism Prediction App",
layout="wide"
)
# ---------------------------------------------------------
# LIGHT CSS OPTIMIZATION
# ---------------------------------------------------------
st.markdown("""
<style>
/* Reduce page padding */
.block-container {
padding-top: 4rem; /* smaller padding on top */
padding-bottom: 1rem;
padding-left: 2rem;
padding-right: 2rem;
}
/* Reduce vertical gaps between widgets */
div[data-testid="stVerticalBlock"] {
row-gap: 0.5rem;
}
/* Tighter expander headers */
.streamlit-expanderHeader {
font-size: 1rem;
padding: 0.4rem 0.5rem;
}
/* section header */
.section-header {
font-size: 28px !important;
font-weight: 700 !important;
color: #333333 !important;
margin-top: 20px !important;
}
</style>
""", unsafe_allow_html=True)
# Download and load the model
model_path = hf_hub_download(
repo_id="harishsohani/MLOP-Project-Tourism",
filename="best_tourism_model.joblib"
)
model = joblib.load(model_path)
# ---------------------------------------------------------
# TITLE
# ---------------------------------------------------------
st.title("๐๏ธ Tourism Purchase Prediction App")
st.write("Fill in the details below and click **Predict** to see if the customer is likely to purchase the product.")
# ---------------------------------------------------------
# DROPDOWN VALUES
#
# Define predefines set values for each input applicable
# These are used to show pick list
# ---------------------------------------------------------
TypeofContact_vals = ['Self Enquiry', 'Company Invited']
Occupation_vals = ['Salaried', 'Free Lancer', 'Small Business', 'Large Business']
Gender_vals = ['Female', 'Male']
ProductPitched_vals = ['Deluxe', 'Basic', 'Standard', 'Super Deluxe', 'King']
MaritalStatus_vals = ['Single', 'Divorced', 'Married', 'Unmarried']
Designation_vals = ['Manager', 'Executive', 'Senior Manager', 'AVP', 'VP']
CityType = [ "Tier 1", "Tier 2", "Tier 3"]
PitchSatisfactionScore_vals = [1, 2, 3, 4, 5]
# ---------------------------------------------------------
# PERSONAL INFORMATION
# ---------------------------------------------------------
with st.expander("๐ค 1. Personal and Professional Information", expanded=True):
col1, col2, col3, col4, col5 = st.columns(5)
with col1:
Age = st.number_input("Age", 18, 120, 30)
Gender = st.selectbox("Gender", Gender_vals)
with col2:
MaritalStatus = st.selectbox("Marital Status", MaritalStatus_vals)
CityTier_label = st.selectbox("City Tier", CityType)
with col3:
OwnCar_display = st.radio("Own Car?", ["Yes", "No"])
Passport_display = st.radio("Has Passport?", ["Yes", "No"])
with col4:
Occupation = st.selectbox("Occupation", Occupation_vals)
Designation = st.selectbox("Designation", Designation_vals)
with col5:
MonthlyIncome = st.number_input("Monthly Income (โน)", 0, 1000000, 100000)
CityTier = {"Tier 1": 1, "Tier 2": 2, "Tier 3": 3}[CityTier_label]
OwnCar = 1 if OwnCar_display == "Yes" else 0
Passport = 1 if Passport_display == "Yes" else 0
# ---------------------------------------------------------
# TRAVEL INFORMATION
# ---------------------------------------------------------
# Keep section expanded by default - so it is visible when we open
with st.expander("โ๏ธ 2. Travel Information", expanded=True):
col1, col2, col3, col4, col5 = st.columns(5)
with col1:
NumberOfTrips = st.number_input("Average Trips per Year", 0, 50, 2)
with col2:
NumberOfPersonVisiting = st.number_input("Total Persons Visiting", 1, 10, 2)
with col3:
NumberOfChildrenVisiting = st.number_input("Children (Below 5 yrs)", 0, 10, 0)
with col4:
PreferredPropertyStar = st.selectbox("Preferred Property Star", [3, 4, 5])
# ---------------------------------------------------------
# INTERACTION INFORMATION
# ---------------------------------------------------------
# Keep section expanded by default - so it is visible when we open
with st.expander("๐ฃ๏ธ 3. Interaction Details", expanded=True):
col1, col2, col3, col4, col5 = st.columns(5)
with col1:
TypeofContact = st.selectbox("Type of Contact", TypeofContact_vals)
with col2:
ProductPitched = st.selectbox("Product Pitched", ProductPitched_vals)
with col3:
DurationOfPitch = st.number_input("Pitch Duration (minutes)", 0, 200, 10)
with col4:
NumberOfFollowups = st.number_input("Number of Follow-ups", 0, 50, 1)
with col5:
PitchSatisfactionScore = st.selectbox("Pitch Satisfaction Score", [5, 4, 3, 2, 1])
# --------------------------
# Prepare input data frame
# ------------------------
input_data = {
"Age": Age,
"TypeofContact": TypeofContact,
"CityTier": CityTier,
"DurationOfPitch": DurationOfPitch,
"Occupation": Occupation,
"Gender": Gender,
"NumberOfPersonVisiting": NumberOfPersonVisiting,
"NumberOfFollowups": NumberOfFollowups,
"ProductPitched": ProductPitched,
"PreferredPropertyStar": PreferredPropertyStar,
"MaritalStatus": MaritalStatus,
"NumberOfTrips": NumberOfTrips,
"Passport": Passport,
"PitchSatisfactionScore": PitchSatisfactionScore,
"OwnCar": OwnCar,
"NumberOfChildrenVisiting": NumberOfChildrenVisiting,
"Designation": Designation,
"MonthlyIncome": MonthlyIncome
}
input_df = pd.DataFrame([input_data])
# ---------------------------------------------------------
# PREDICT BUTTON
# ---------------------------------------------------------
st.markdown("---")
if st.button("๐ Predict", use_container_width=True):
prediction = model.predict(input_df)[0]
result = "Based on the information provided, the customer is **likely** to purchase the product." if prediction == 1 \
else "Based on the information provided, the customer is **unlikely** to purchase the product."
st.success(result)
# Show the etails of data frame prepared from user input
st.subheader("๐ฆ Input Data Summary")
st.dataframe(input_df)
#st.json(input_df)
|