harishsohani commited on
Commit
43415ae
·
verified ·
1 Parent(s): 5e7395a

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +81 -95
app.py CHANGED
@@ -11,11 +11,74 @@ from huggingface_hub import hf_hub_download
11
  # library to load model
12
  import joblib
13
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
  # Download and load the model
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
  # Define predefines set values for each input applicable
 
 
19
  TypeofContact_vals = ['Self Enquiry', 'Company Invited']
20
 
21
  Occupation_vals = ['Salaried', 'Free Lancer', 'Small Business', 'Large Business']
@@ -38,89 +101,29 @@ NumberOfTrips_vals = [1, 2, 7, 5, 6, 3, 4, 19, 21, 8, 20, 22]
38
 
39
  PitchSatisfactionScore_vals = [1, 2, 3, 4, 5]
40
 
41
- # ---------------------------------------------------------
42
- # UI OPTIMIZATION (CSS + Layout Tweaks)
43
- # ---------------------------------------------------------
44
- st.markdown("""
45
- <style>
46
- /* Reduce padding at top/bottom */
47
- .main {
48
- padding-top: 1rem;
49
- }
50
-
51
- /* Card-style containers */
52
- .card {
53
- background-color: #f8f9fa;
54
- padding: 20px;
55
- border-radius: 12px;
56
- box-shadow: 0 2px 10px rgba(0,0,0,0.08);
57
- margin-bottom: 20px;
58
- }
59
-
60
- /* Smaller headers */
61
- h1 { font-size: 32px !important; }
62
- h2 { font-size: 26px !important; }
63
- h3 { font-size: 20px !important; }
64
-
65
- /* Input element spacing */
66
- .stSelectbox, .stNumberInput, .stTextInput {
67
- margin-bottom: -10px;
68
- }
69
-
70
- /* Prediction box sticky to top-right */
71
- .sticky {
72
- position: fixed;
73
- top: 80px;
74
- right: 20px;
75
- width: 300px;
76
- z-index: 999;
77
- background-color: white;
78
- padding: 20px;
79
- border-radius: 12px;
80
- box-shadow: 0 2px 12px rgba(0,0,0,0.15);
81
- }
82
- </style>
83
- """, unsafe_allow_html=True)
84
-
85
- # Streamlit UI for Machine Failure Prediction
86
- st.title("Tourism App - Input form for Predection")
87
- st.write("""
88
- This application predicts the likelihood of whether a customer would take the product based on following set of parameters.
89
- Please provide the following details.
90
- """)
91
 
92
 
93
  # ---------------------------------------------------------
94
  # PERSONAL INFORMATION
95
  # ---------------------------------------------------------
96
  with st.expander("👤 1. Personal and Professional Information", expanded=True):
97
- #st.markdown('<div class="card">', unsafe_allow_html=True)
98
- st.markdown('</div>', unsafe_allow_html=True)
99
 
100
- col1, col2, col3 = st.columns(3)
 
101
  with col1:
102
  Age = st.number_input("Age", 18, 90, 30)
103
  Gender = st.selectbox("Gender", Gender_vals)
104
  MaritalStatus = st.selectbox("Marital Status", MaritalStatus_vals)
 
105
 
106
  with col2:
107
  CityTier_label = st.selectbox("City Tier", CityType)
108
- #OwnCar = st.selectbox("Owns a Car?", [0, 1])
109
- #Passport = st.selectbox("Has Passport?", [0, 1])
110
  OwnCar_display = st.radio("Own Car?", ["Yes", "No"])
111
  Passport_display = st.radio("Has Passport?", ["Yes", "No"])
112
-
113
- with col3:
114
  Occupation = st.selectbox("Occupation", Occupation_vals)
115
  Designation = st.selectbox("Designation", Designation_vals)
116
- MonthlyIncome = st.number_input("Monthly Income (₹)", 0, 500000, 50000)
117
-
118
- st.markdown('</div>', unsafe_allow_html=True)
119
 
120
- #convert City Tier to numeric
121
  CityTier = {"Tier 1": 1, "Tier 2": 2, "Tier 3": 3}[CityTier_label]
122
-
123
- # Convert Yes/No → 1/0
124
  OwnCar = 1 if OwnCar_display == "Yes" else 0
125
  Passport = 1 if Passport_display == "Yes" else 0
126
 
@@ -128,44 +131,37 @@ Passport = 1 if Passport_display == "Yes" else 0
128
  # ---------------------------------------------------------
129
  # TRAVEL INFORMATION
130
  # ---------------------------------------------------------
131
- with st.expander("✈️ 2. Travel Information"):
132
- #st.markdown('<div class="card">', unsafe_allow_html=True)
133
- st.markdown('</div>', unsafe_allow_html=True)
134
 
135
  col1, col2 = st.columns(2)
 
136
  with col1:
137
  NumberOfTrips = st.number_input("Average Trips per Year", 0, 100, 2)
138
- NumberOfChildrenVisiting = st.number_input("Children (Below 5 years)", 0, 10, 0)
139
 
140
  with col2:
141
  NumberOfPersonVisiting = st.number_input("Total Persons Visiting", 1, 10, 2)
142
  PreferredPropertyStar = st.selectbox("Preferred Property Star", [1, 2, 3, 4, 5])
143
 
144
- st.markdown('</div>', unsafe_allow_html=True)
145
 
146
 
147
  # ---------------------------------------------------------
148
  # INTERACTION INFORMATION
149
  # ---------------------------------------------------------
150
- with st.expander("🗣️ 3. Interaction Details"):
151
- #st.markdown('<div class="card">', unsafe_allow_html=True)
152
- st.markdown('</div>', unsafe_allow_html=True)
153
 
154
- col1, col2, col3 = st.columns(3)
155
 
156
  with col1:
157
- TypeofContact = st.selectbox("Type of Contact", ["Company Invited", "Self Inquiry"])
158
  ProductPitched = st.selectbox("Product Pitched", ProductPitched_vals)
159
 
160
-
161
  with col2:
162
  DurationOfPitch = st.number_input("Pitch Duration (minutes)", 0, 200, 10)
163
  NumberOfFollowups = st.number_input("Number of Follow-ups", 0, 50, 1)
164
-
165
- with col3:
166
  PitchSatisfactionScore = st.selectbox("Pitch Satisfaction Score", [1, 2, 3, 4, 5])
167
 
168
- st.markdown('</div>', unsafe_allow_html=True)
169
 
170
  # --------------------------
171
  # Prepare input data frame
@@ -195,23 +191,13 @@ input_df = pd.DataFrame([input_data])
195
 
196
 
197
  # ---------------------------------------------------------
198
- # Predict Button
199
  # ---------------------------------------------------------
200
- if st.button("Predict"):
201
- prediction = model.predict(input_df)[0]
202
- result = (
203
- "Customer is likely to purchase the product"
204
- if prediction == 1 else
205
- "Customer is unlikely to purchase the product"
206
- )
207
-
208
- st.subheader("Prediction Result")
209
- st.success(f"**{result}**")
210
 
 
 
 
211
 
212
- '''pred = model.predict(df_input)[0]
213
- st.markdown(f"""
214
- <div class="sticky">
215
- <h2>📈 Prediction: {pred}</h2>
216
- </div>
217
- """, unsafe_allow_html=True)'''
 
11
  # library to load model
12
  import joblib
13
 
14
+
15
+
16
+
17
+ # ---------------------------------------------------------
18
+ # PAGE CONFIG
19
+ # ---------------------------------------------------------
20
+ st.set_page_config(
21
+ page_title="Tourism Prediction App",
22
+ layout="wide"
23
+ )
24
+ # Streamlit UI for Machine Failure Prediction
25
+ #st.title("Tourism App - Input form for Predection")
26
+ st.write("""
27
+ This application predicts the likelihood of whether a customer would take the product based on following set of parameters.
28
+ Please provide the following details.
29
+ """)
30
+
31
+
32
+
33
+ # ---------------------------------------------------------
34
+ # LIGHT CSS OPTIMIZATION
35
+ # ---------------------------------------------------------
36
+ st.markdown("""
37
+ <style>
38
+ /* Reduce page padding */
39
+ .block-container {
40
+ padding-top: 1rem;
41
+ padding-bottom: 1rem;
42
+ padding-left: 2rem;
43
+ padding-right: 2rem;
44
+ }
45
+
46
+ /* Reduce vertical gaps between widgets */
47
+ div[data-testid="stVerticalBlock"] {
48
+ row-gap: 0.5rem;
49
+ }
50
+
51
+ /* Tighter expander headers */
52
+ .streamlit-expanderHeader {
53
+ font-size: 1rem;
54
+ padding: 0.4rem 0.5rem;
55
+ }
56
+ </style>
57
+ """, unsafe_allow_html=True)
58
+
59
+
60
  # Download and load the model
61
+ model_path = hf_hub_download(
62
+ repo_id="harishsohani/MLOP-Project-Tourism",
63
+ filename="best_tourism_model.joblib"
64
+ )
65
  model = joblib.load(model_path)
66
 
67
+
68
+ # ---------------------------------------------------------
69
+ # TITLE
70
+ # ---------------------------------------------------------
71
+ st.title("🏖️ Tourism Purchase Prediction App")
72
+ st.write("Fill in the details below and click **Predict** to see if the customer is likely to purchase the product.")
73
+
74
+
75
+
76
+ # ---------------------------------------------------------
77
+ # DROPDOWN VALUES
78
+ #
79
  # Define predefines set values for each input applicable
80
+ # These are used to show pick list
81
+ # ---------------------------------------------------------
82
  TypeofContact_vals = ['Self Enquiry', 'Company Invited']
83
 
84
  Occupation_vals = ['Salaried', 'Free Lancer', 'Small Business', 'Large Business']
 
101
 
102
  PitchSatisfactionScore_vals = [1, 2, 3, 4, 5]
103
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
104
 
105
 
106
  # ---------------------------------------------------------
107
  # PERSONAL INFORMATION
108
  # ---------------------------------------------------------
109
  with st.expander("👤 1. Personal and Professional Information", expanded=True):
 
 
110
 
111
+ col1, col2 = st.columns(2)
112
+
113
  with col1:
114
  Age = st.number_input("Age", 18, 90, 30)
115
  Gender = st.selectbox("Gender", Gender_vals)
116
  MaritalStatus = st.selectbox("Marital Status", MaritalStatus_vals)
117
+ MonthlyIncome = st.number_input("Monthly Income (₹)", 0, 500000, 50000)
118
 
119
  with col2:
120
  CityTier_label = st.selectbox("City Tier", CityType)
 
 
121
  OwnCar_display = st.radio("Own Car?", ["Yes", "No"])
122
  Passport_display = st.radio("Has Passport?", ["Yes", "No"])
 
 
123
  Occupation = st.selectbox("Occupation", Occupation_vals)
124
  Designation = st.selectbox("Designation", Designation_vals)
 
 
 
125
 
 
126
  CityTier = {"Tier 1": 1, "Tier 2": 2, "Tier 3": 3}[CityTier_label]
 
 
127
  OwnCar = 1 if OwnCar_display == "Yes" else 0
128
  Passport = 1 if Passport_display == "Yes" else 0
129
 
 
131
  # ---------------------------------------------------------
132
  # TRAVEL INFORMATION
133
  # ---------------------------------------------------------
134
+ with st.expander("✈️ 2. Travel Information", expanded=False):
 
 
135
 
136
  col1, col2 = st.columns(2)
137
+
138
  with col1:
139
  NumberOfTrips = st.number_input("Average Trips per Year", 0, 100, 2)
140
+ NumberOfChildrenVisiting = st.number_input("Children (Below 5 yrs)", 0, 10, 0)
141
 
142
  with col2:
143
  NumberOfPersonVisiting = st.number_input("Total Persons Visiting", 1, 10, 2)
144
  PreferredPropertyStar = st.selectbox("Preferred Property Star", [1, 2, 3, 4, 5])
145
 
 
146
 
147
 
148
  # ---------------------------------------------------------
149
  # INTERACTION INFORMATION
150
  # ---------------------------------------------------------
151
+ with st.expander("🗣️ 3. Interaction Details", expanded=False):
 
 
152
 
153
+ col1, col2 = st.columns(2)
154
 
155
  with col1:
156
+ TypeofContact = st.selectbox("Type of Contact", TypeofContact_vals)
157
  ProductPitched = st.selectbox("Product Pitched", ProductPitched_vals)
158
 
 
159
  with col2:
160
  DurationOfPitch = st.number_input("Pitch Duration (minutes)", 0, 200, 10)
161
  NumberOfFollowups = st.number_input("Number of Follow-ups", 0, 50, 1)
 
 
162
  PitchSatisfactionScore = st.selectbox("Pitch Satisfaction Score", [1, 2, 3, 4, 5])
163
 
164
+
165
 
166
  # --------------------------
167
  # Prepare input data frame
 
191
 
192
 
193
  # ---------------------------------------------------------
194
+ # PREDICT BUTTON
195
  # ---------------------------------------------------------
196
+ st.markdown("---")
197
+ if st.button("🔍 Predict", use_container_width=True):
 
 
 
 
 
 
 
 
198
 
199
+ prediction = model.predict(input_df)[0]
200
+ result = "Customer is **likely** to purchase the product." if prediction == 1 \
201
+ else "Customer is **unlikely** to purchase the product."
202
 
203
+ st.success(result)