Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files
app.py
CHANGED
|
@@ -15,189 +15,157 @@ import joblib
|
|
| 15 |
model_path = hf_hub_download(repo_id="harishsohani/MLOP-Project-Tourism", filename="best_tourism_model.joblib")
|
| 16 |
model = joblib.load(model_path)
|
| 17 |
|
| 18 |
-
# Custom CSS
|
| 19 |
-
st.markdown("""
|
| 20 |
-
<style>
|
| 21 |
-
/* Change size of title */
|
| 22 |
-
h1 {
|
| 23 |
-
font-size: 40px !important;
|
| 24 |
-
color: #00b4d8;
|
| 25 |
-
}
|
| 26 |
-
|
| 27 |
-
/* Change size of header */
|
| 28 |
-
h2 {
|
| 29 |
-
font-size: 28px !important;
|
| 30 |
-
color: #0077b6;
|
| 31 |
-
}
|
| 32 |
-
|
| 33 |
-
/* Change size of subheader */
|
| 34 |
-
h3 {
|
| 35 |
-
font-size: 22px !important;
|
| 36 |
-
}
|
| 37 |
-
</style>
|
| 38 |
-
""", unsafe_allow_html=True)
|
| 39 |
-
|
| 40 |
-
# Streamlit UI for Machine Failure Prediction
|
| 41 |
-
st.title("Tourism App - Input form")
|
| 42 |
-
st.write("""
|
| 43 |
-
This application predicts the likelihood of whether a customer would take the product based on following set of parameters.
|
| 44 |
-
Please provide the following details.
|
| 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 |
-
st.
|
| 79 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
|
| 81 |
-
with
|
| 82 |
-
|
| 83 |
-
|
|
|
|
|
|
|
| 84 |
|
| 85 |
-
|
| 86 |
-
MaritalStatus = st.selectbox("Marital Status", MaritalStatus_vals)
|
| 87 |
-
MonthlyIncome = st.number_input("Monthly Income", min_value=0, value=50000)
|
| 88 |
|
|
|
|
| 89 |
|
| 90 |
|
| 91 |
# ---------------------------------------------------------
|
| 92 |
-
#
|
| 93 |
# ---------------------------------------------------------
|
| 94 |
-
st.
|
| 95 |
-
|
| 96 |
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
|
|
|
| 100 |
|
| 101 |
-
with
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
Passport_display = st.radio("Passport?", ["Yes", "No"])
|
| 105 |
|
| 106 |
-
|
| 107 |
-
OwnCar = 1 if OwnCar_display == "Yes" else 0
|
| 108 |
-
Passport = 1 if Passport_display == "Yes" else 0
|
| 109 |
-
|
| 110 |
-
# ---------------------------------------------------------
|
| 111 |
-
# SECTION 3: Travel & Vacation Behavior
|
| 112 |
-
# ---------------------------------------------------------
|
| 113 |
-
|
| 114 |
-
st.header("3️⃣ Travel & Vacation Behavior")
|
| 115 |
-
col5, col6 = st.columns(2)
|
| 116 |
-
|
| 117 |
-
with col5:
|
| 118 |
-
NumberOfPersonVisiting = st.number_input(
|
| 119 |
-
"Number of Persons Visiting", min_value=1, max_value=10, value=2
|
| 120 |
-
)
|
| 121 |
-
NumberOfChildrenVisiting = st.number_input(
|
| 122 |
-
"Number of Children Visiting", min_value=0, max_value=10, value=0
|
| 123 |
-
)
|
| 124 |
-
|
| 125 |
-
with col6:
|
| 126 |
-
NumberOfTrips = st.number_input(
|
| 127 |
-
"Number of Trips per Year",
|
| 128 |
-
min_value=0,
|
| 129 |
-
max_value=50,
|
| 130 |
-
value=1
|
| 131 |
-
)
|
| 132 |
-
PreferredPropertyStar = st.selectbox(
|
| 133 |
-
"Preferred Property Star", PreferredPropertyStar_vals
|
| 134 |
-
)
|
| 135 |
|
| 136 |
|
| 137 |
# ---------------------------------------------------------
|
| 138 |
-
#
|
| 139 |
# ---------------------------------------------------------
|
|
|
|
|
|
|
| 140 |
|
| 141 |
-
|
| 142 |
-
col7, col8 = st.columns(2)
|
| 143 |
-
|
| 144 |
-
with col7:
|
| 145 |
-
TypeofContact = st.selectbox("Type of Contact", TypeofContact_vals)
|
| 146 |
-
ProductPitched = st.selectbox("Product Pitched", ProductPitched_vals)
|
| 147 |
|
| 148 |
-
with
|
| 149 |
-
|
| 150 |
-
"
|
| 151 |
-
)
|
| 152 |
-
PitchSatisfactionScore = st.selectbox(
|
| 153 |
-
"Pitch Satisfaction Score", sorted(PitchSatisfactionScore_vals)
|
| 154 |
-
)
|
| 155 |
-
NumberOfFollowups = st.number_input(
|
| 156 |
-
"Number of Follow-ups", min_value=0, max_value=20, value=2
|
| 157 |
-
)
|
| 158 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 159 |
|
| 160 |
-
|
| 161 |
-
# Prepare Input for Model
|
| 162 |
-
# ---------------------------------------------------------
|
| 163 |
|
| 164 |
-
|
| 165 |
-
"Age": Age,
|
| 166 |
-
"TypeofContact": TypeofContact,
|
| 167 |
-
"CityTier": CityTier,
|
| 168 |
-
"DurationOfPitch": DurationOfPitch,
|
| 169 |
-
"Occupation": Occupation,
|
| 170 |
-
"Gender": Gender,
|
| 171 |
-
"NumberOfPersonVisiting": NumberOfPersonVisiting,
|
| 172 |
-
"NumberOfFollowups": NumberOfFollowups,
|
| 173 |
-
"ProductPitched": ProductPitched,
|
| 174 |
-
"PreferredPropertyStar": PreferredPropertyStar,
|
| 175 |
-
"MaritalStatus": MaritalStatus,
|
| 176 |
-
"NumberOfTrips": NumberOfTrips,
|
| 177 |
-
"Passport": Passport, # now 0/1
|
| 178 |
-
"PitchSatisfactionScore": PitchSatisfactionScore,
|
| 179 |
-
"OwnCar": OwnCar, # now 0/1
|
| 180 |
-
"NumberOfChildrenVisiting": NumberOfChildrenVisiting,
|
| 181 |
-
"Designation": Designation,
|
| 182 |
-
"MonthlyIncome": MonthlyIncome
|
| 183 |
-
}
|
| 184 |
-
|
| 185 |
-
import_data_df = pd.DataFrame([input_data])
|
| 186 |
-
|
| 187 |
-
# The following code can be enabled to see the etails of data frame prepared from user input
|
| 188 |
-
# This code was used for debugging and now disabled
|
| 189 |
-
## st.subheader("📦 Input Data Summary")
|
| 190 |
-
## st.json(input_data)
|
| 191 |
|
| 192 |
|
| 193 |
# ---------------------------------------------------------
|
| 194 |
-
#
|
| 195 |
# ---------------------------------------------------------
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
model_path = hf_hub_download(repo_id="harishsohani/MLOP-Project-Tourism", filename="best_tourism_model.joblib")
|
| 16 |
model = joblib.load(model_path)
|
| 17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
# ---------------------------------------------------------
|
| 19 |
+
# UI OPTIMIZATION (CSS + Layout Tweaks)
|
| 20 |
# ---------------------------------------------------------
|
| 21 |
+
st.markdown("""
|
| 22 |
+
<style>
|
| 23 |
+
/* Reduce padding at top/bottom */
|
| 24 |
+
.main {
|
| 25 |
+
padding-top: 1rem;
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
/* Card-style containers */
|
| 29 |
+
.card {
|
| 30 |
+
background-color: #f8f9fa;
|
| 31 |
+
padding: 20px;
|
| 32 |
+
border-radius: 12px;
|
| 33 |
+
box-shadow: 0 2px 10px rgba(0,0,0,0.08);
|
| 34 |
+
margin-bottom: 20px;
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
/* Smaller headers */
|
| 38 |
+
h1 { font-size: 32px !important; }
|
| 39 |
+
h2 { font-size: 26px !important; }
|
| 40 |
+
h3 { font-size: 20px !important; }
|
| 41 |
+
|
| 42 |
+
/* Input element spacing */
|
| 43 |
+
.stSelectbox, .stNumberInput, .stTextInput {
|
| 44 |
+
margin-bottom: -10px;
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
/* Prediction box sticky to top-right */
|
| 48 |
+
.sticky {
|
| 49 |
+
position: fixed;
|
| 50 |
+
top: 80px;
|
| 51 |
+
right: 20px;
|
| 52 |
+
width: 300px;
|
| 53 |
+
z-index: 999;
|
| 54 |
+
background-color: white;
|
| 55 |
+
padding: 20px;
|
| 56 |
+
border-radius: 12px;
|
| 57 |
+
box-shadow: 0 2px 12px rgba(0,0,0,0.15);
|
| 58 |
+
}
|
| 59 |
+
</style>
|
| 60 |
+
""", unsafe_allow_html=True)
|
| 61 |
|
| 62 |
# ---------------------------------------------------------
|
| 63 |
+
# PERSONAL INFORMATION
|
| 64 |
# ---------------------------------------------------------
|
| 65 |
+
with st.expander("👤 1. Personal Information", expanded=True):
|
| 66 |
+
st.markdown('<div class="card">', unsafe_allow_html=True)
|
| 67 |
|
| 68 |
+
col1, col2 = st.columns(2)
|
| 69 |
+
with col1:
|
| 70 |
+
Age = st.number_input("Age", 18, 90, 30)
|
| 71 |
+
Gender = st.selectbox("Gender", ["Male", "Female"])
|
| 72 |
+
CityTier_label = st.selectbox("City Tier", ["Tier 1", "Tier 2", "Tier 3"])
|
| 73 |
+
Passport = st.selectbox("Has Passport?", [0, 1])
|
| 74 |
|
| 75 |
+
with col2:
|
| 76 |
+
MaritalStatus = st.selectbox("Marital Status", ["Single", "Married", "Divorced"])
|
| 77 |
+
MonthlyIncome = st.number_input("Monthly Income (₹)", 0, 500000, 50000)
|
| 78 |
+
Occupation = st.selectbox("Occupation", ["Salaried", "Self Employed", "Entrepreneur"])
|
| 79 |
+
OwnCar = st.selectbox("Owns a Car?", [0, 1])
|
| 80 |
|
| 81 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
|
|
|
|
|
|
| 82 |
|
| 83 |
+
CityTier = {"Tier 1": 1, "Tier 2": 2, "Tier 3": 3}[CityTier_label]
|
| 84 |
|
| 85 |
|
| 86 |
# ---------------------------------------------------------
|
| 87 |
+
# TRAVEL INFORMATION
|
| 88 |
# ---------------------------------------------------------
|
| 89 |
+
with st.expander("✈️ 2. Travel Information"):
|
| 90 |
+
st.markdown('<div class="card">', unsafe_allow_html=True)
|
| 91 |
|
| 92 |
+
col1, col2 = st.columns(2)
|
| 93 |
+
with col1:
|
| 94 |
+
NumberOfTrips = st.number_input("Average Trips per Year", 0, 100, 2)
|
| 95 |
+
NumberOfChildrenVisiting = st.number_input("Children (Below 5 years)", 0, 10, 0)
|
| 96 |
|
| 97 |
+
with col2:
|
| 98 |
+
NumberOfPersonVisiting = st.number_input("Total Persons Visiting", 1, 10, 2)
|
| 99 |
+
PreferredPropertyStar = st.selectbox("Preferred Property Star", [1, 2, 3, 4, 5])
|
|
|
|
| 100 |
|
| 101 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
|
| 103 |
|
| 104 |
# ---------------------------------------------------------
|
| 105 |
+
# INTERACTION INFORMATION
|
| 106 |
# ---------------------------------------------------------
|
| 107 |
+
with st.expander("🗣️ 3. Interaction Details"):
|
| 108 |
+
st.markdown('<div class="card">', unsafe_allow_html=True)
|
| 109 |
|
| 110 |
+
col1, col2 = st.columns(2)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 111 |
|
| 112 |
+
with col1:
|
| 113 |
+
DurationOfPitch = st.number_input("Pitch Duration (minutes)", 0, 200, 10)
|
| 114 |
+
NumberOfFollowups = st.number_input("Number of Follow-ups", 0, 20, 1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 115 |
|
| 116 |
+
with col2:
|
| 117 |
+
PitchSatisfactionScore = st.selectbox("Pitch Satisfaction Score", [1, 2, 3, 4, 5])
|
| 118 |
+
ProductPitched = st.selectbox("Product Pitched",
|
| 119 |
+
["Basic", "Standard", "Deluxe", "Luxury"])
|
| 120 |
|
| 121 |
+
TypeofContact = st.selectbox("Type of Contact", ["Company Invited", "Self Inquiry"])
|
|
|
|
|
|
|
| 122 |
|
| 123 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 124 |
|
| 125 |
|
| 126 |
# ---------------------------------------------------------
|
| 127 |
+
# Predict Button
|
| 128 |
# ---------------------------------------------------------
|
| 129 |
+
if st.button("🔮 Predict"):
|
| 130 |
+
input_data = {
|
| 131 |
+
"Age": Age,
|
| 132 |
+
"Gender": Gender,
|
| 133 |
+
"CityTier": CityTier,
|
| 134 |
+
"MaritalStatus": MaritalStatus,
|
| 135 |
+
"MonthlyIncome": MonthlyIncome,
|
| 136 |
+
"Occupation": Occupation,
|
| 137 |
+
"NumberOfTrips": NumberOfTrips,
|
| 138 |
+
"NumberOfAdultsVisiting": NumberOfAdultsVisiting,
|
| 139 |
+
"NumberOfChildrenVisiting": NumberOfChildrenVisiting,
|
| 140 |
+
"PitchDuration": DurationOfPitch,
|
| 141 |
+
"NumberOfFollowups": NumberOfFollowups,
|
| 142 |
+
"PreferredProperty": PreferredProperty,
|
| 143 |
+
"PitchSatisfaction": PitchSatisfaction,
|
| 144 |
+
"ProductPitched": ProductPitched,
|
| 145 |
+
"TourType": TourType,
|
| 146 |
+
"Passport": Passport
|
| 147 |
+
}
|
| 148 |
+
|
| 149 |
+
input_df = pd.DataFrame([input_data])
|
| 150 |
+
|
| 151 |
+
# ---------------------------------------------------------
|
| 152 |
+
# Prediction Button
|
| 153 |
+
# ---------------------------------------------------------
|
| 154 |
+
if st.button("Predict"):
|
| 155 |
+
prediction = model.predict(input_df)[0]
|
| 156 |
+
result = (
|
| 157 |
+
"Customer is likely to purchase the product"
|
| 158 |
+
if prediction == 1 else
|
| 159 |
+
"Customer is unlikely to purchase the product"
|
| 160 |
+
)
|
| 161 |
+
|
| 162 |
+
st.subheader("Prediction Result")
|
| 163 |
+
st.success(f"**{result}**")
|
| 164 |
+
|
| 165 |
+
|
| 166 |
+
'''pred = model.predict(df_input)[0]
|
| 167 |
+
st.markdown(f"""
|
| 168 |
+
<div class="sticky">
|
| 169 |
+
<h2>📈 Prediction: {pred}</h2>
|
| 170 |
+
</div>
|
| 171 |
+
""", unsafe_allow_html=True)'''
|