harishsohani commited on
Commit
87c753b
·
verified ·
1 Parent(s): b29c4c3

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +114 -108
app.py CHANGED
@@ -15,6 +15,12 @@ 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
 
19
  # ---------------------------------------------------------
20
  # Define Unique Values for each column
@@ -24,7 +30,7 @@ TypeofContact_vals = ['Self Enquiry', 'Company Invited']
24
 
25
  Occupation_vals = ['Salaried', 'Free Lancer', 'Small Business', 'Large Business']
26
 
27
- Gender_vals = ['Female', 'Male', 'Fe Male'] # You may want to fix "Fe Male"
28
 
29
  ProductPitched_vals = ['Deluxe', 'Basic', 'Standard', 'Super Deluxe', 'King']
30
 
@@ -32,6 +38,8 @@ MaritalStatus_vals = ['Single', 'Divorced', 'Married', 'Unmarried']
32
 
33
  Designation_vals = ['Manager', 'Executive', 'Senior Manager', 'AVP', 'VP']
34
 
 
 
35
  CityTier_vals = [1, 2, 3]
36
 
37
  PreferredPropertyStar_vals = [3.0, 4.0, 5.0]
@@ -41,135 +49,133 @@ NumberOfTrips_vals = [1, 2, 7, 5, 6, 3, 4, 19, 21, 8, 20, 22]
41
  PitchSatisfactionScore_vals = [1, 2, 3, 4, 5]
42
 
43
 
 
 
 
44
 
45
- st.set_page_config(page_title="Tourism App – Input Form", layout="wide")
46
-
47
- # ----- COMPACT CSS -----
48
- st.markdown("""
49
- <style>
50
- .card {
51
- background-color: #ffffff;
52
- padding: 15px;
53
- border-radius: 12px;
54
- box-shadow: 0 2px 8px rgba(0,0,0,0.06);
55
- margin-bottom: 12px;
56
- }
57
-
58
- .section-title {
59
- font-size: 20px;
60
- font-weight: 700;
61
- margin-bottom: 6px;
62
- color: #1a73e8;
63
- }
64
-
65
- h1 {
66
- font-size: 26px !important;
67
- margin-bottom: 8px;
68
- }
69
-
70
- label, .stSelectbox label, .stNumberInput label {
71
- font-size: 14px !important;
72
- font-weight: 600 !important;
73
- }
74
 
75
- .stButton > button {
76
- background-color: #1a73e8;
77
- color: white;
78
- padding: 10px 20px;
79
- font-size: 16px;
80
- width: 40%;
81
- border-radius: 8px;
82
- }
83
 
84
- .result-box {
85
- padding: 10px;
86
- background-color: #e8f4ff;
87
- border-left: 4px solid #1a73e8;
88
- font-size: 16px;
89
- border-radius: 6px;
90
- margin-top: 10px;
91
- }
92
- </style>
93
- """, unsafe_allow_html=True)
94
 
95
- # ---- TITLE ----
96
- st.markdown("<h1 style='text-align:center;'>🏖️ Tourism App – Customer Input</h1>", unsafe_allow_html=True)
97
 
98
 
99
- # -----------------------
100
- # LAYOUT (2-COLUMN PAGE)
101
- # -----------------------
102
- left, right = st.columns(2)
103
-
104
 
105
- # ===== LEFT SIDE =====
106
- with left:
 
107
 
108
- # ---- Personal Information ----
109
- st.markdown("<div class='card'>", unsafe_allow_html=True)
110
- st.markdown("<div class='section-title'>1️⃣ Personal Information</div>", unsafe_allow_html=True)
 
111
 
112
- col1, col2 = st.columns(2)
113
- with col1:
114
- Age = st.number_input("Age", 0, 120, 30)
115
- MonthlyIncome = st.number_input("Monthly Income", 0, 500000, 50000)
116
- with col2:
117
- Gender = st.selectbox("Gender", ["Male", "Female"])
118
- MaritalStatus = st.selectbox("Marital Status", ["Single", "Married", "Divorced"])
119
 
120
- st.markdown("</div>", unsafe_allow_html=True)
 
 
121
 
122
- # ---- Customer Profile ----
123
- st.markdown("<div class='card'>", unsafe_allow_html=True)
124
- st.markdown("<div class='section-title'>2️⃣ Customer Profile</div>", unsafe_allow_html=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
125
 
126
- col1, col2 = st.columns(2)
127
- with col1:
128
- Occupation = st.selectbox("Occupation", ["Salaried", "Business", "Retired"])
129
- Designation = st.selectbox("Designation", ["Executive", "Manager", "Senior Manager"])
130
- with col2:
131
- CityTier_display = st.selectbox("City Tier", ["Tier 1", "Tier 2", "Tier 3"])
132
- Passport_display = st.selectbox("Passport", ["Yes", "No"])
133
 
134
- st.markdown("</div>", unsafe_allow_html=True)
 
 
135
 
 
 
136
 
137
- # ===== RIGHT SIDE =====
138
- with right:
 
139
 
140
- # ---- Travel Behavior ----
141
- st.markdown("<div class='card'>", unsafe_allow_html=True)
142
- st.markdown("<div class='section-title'>3️⃣ Travel Behavior</div>", unsafe_allow_html=True)
 
 
 
 
 
 
 
143
 
144
- col1, col2 = st.columns(2)
145
- with col1:
146
- NumberOfTrips = st.number_input("Travel Persons", 1, 10, 2)
147
- NumberOfChildrenVisiting = st.number_input("Children", 0, 10, 0)
148
- with col2:
149
- duration = st.number_input("Trip Days", 1, 60, 5)
150
- property_type = st.selectbox("Preferred Stay", ["Hotel", "Resort", "Homestay"])
151
 
152
- st.markdown("</div>", unsafe_allow_html=True)
 
 
153
 
154
- # ---- Sales Details ----
155
- st.markdown("<div class='card'>", unsafe_allow_html=True)
156
- st.markdown("<div class='section-title'>4️⃣ Sales Interaction</div>", unsafe_allow_html=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
157
 
158
- col1, col2 = st.columns(2)
159
- with col1:
160
- ProductPitched = st.selectbox("Product Pitched", ["Basic", "Standard", "Premium"])
161
- with col2:
162
- DurationOfPitch = st.number_input("Pitch Duration (min)", 0, 120, 30)
163
 
164
- st.markdown("</div>", unsafe_allow_html=True)
 
 
 
165
 
166
 
167
- # ===== PREDICT BUTTON CENTERED =====
168
- st.write("")
169
- btn_col = st.columns([3, 2, 3]) # center alignment
170
 
171
- with btn_col[1]:
172
- predict = st.button("🔮 Predict", use_container_width=True)
173
 
174
- #if predict:
175
- # st.markdown("<div class='result-box'>Prediction output goes here.</div>", unsafe_allow_html=True)
 
 
 
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
+ # Streamlit UI for Machine Failure Prediction
19
+ st.title("Tourism App - Input form for Prediction")
20
+ st.write("""
21
+ This application predicts the likelihood of whether a customer would take the product based on following set of parameters.
22
+ Please provide the following details.
23
+ """)
24
 
25
  # ---------------------------------------------------------
26
  # Define Unique Values for each column
 
30
 
31
  Occupation_vals = ['Salaried', 'Free Lancer', 'Small Business', 'Large Business']
32
 
33
+ Gender_vals = ['Female', 'Male']
34
 
35
  ProductPitched_vals = ['Deluxe', 'Basic', 'Standard', 'Super Deluxe', 'King']
36
 
 
38
 
39
  Designation_vals = ['Manager', 'Executive', 'Senior Manager', 'AVP', 'VP']
40
 
41
+ CityType = [ "Tier 1", "Tier 2", "Tier3"]
42
+
43
  CityTier_vals = [1, 2, 3]
44
 
45
  PreferredPropertyStar_vals = [3.0, 4.0, 5.0]
 
49
  PitchSatisfactionScore_vals = [1, 2, 3, 4, 5]
50
 
51
 
52
+ # ---------------------------------------------------------
53
+ # SECTION 1: Personal Information
54
+ # ---------------------------------------------------------
55
 
56
+ st.header("1️⃣ Personal Information")
57
+ col1, col2 = st.columns(2)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58
 
59
+ with col1:
60
+ Age = st.number_input("Age", min_value=1, max_value=100, value=30)
61
+ Gender = st.selectbox("Gender", Gender_vals)
 
 
 
 
 
62
 
63
+ with col2:
64
+ MaritalStatus = st.selectbox("Marital Status", MaritalStatus_vals)
65
+ MonthlyIncome = st.number_input("Monthly Income", min_value=0, value=50000)
 
 
 
 
 
 
 
66
 
 
 
67
 
68
 
69
+ # ---------------------------------------------------------
70
+ # Section 2: Customer Profile
71
+ # ---------------------------------------------------------
72
+ st.header("2️⃣ Customer Background & Profile")
73
+ col3, col4 = st.columns(2)
74
 
75
+ with col3:
76
+ Occupation = st.selectbox("Occupation", Occupation_vals)
77
+ Designation = st.selectbox("Designation", Designation_vals)
78
 
79
+ with col4:
80
+ CityTier = st.selectbox("City Tier", sorted(CityTier_vals))
81
+ OwnCar_display = st.radio("Own Car?", ["Yes", "No"])
82
+ Passport_display = st.radio("Passport?", ["Yes", "No"])
83
 
84
+ # Convert Yes/No → 1/0
85
+ OwnCar = 1 if OwnCar_display == "Yes" else 0
86
+ Passport = 1 if Passport_display == "Yes" else 0
 
 
 
 
87
 
88
+ # ---------------------------------------------------------
89
+ # SECTION 3: Travel & Vacation Behavior
90
+ # ---------------------------------------------------------
91
 
92
+ st.header("3️⃣ Travel & Vacation Behavior")
93
+ col5, col6 = st.columns(2)
94
+
95
+ with col5:
96
+ NumberOfPersonVisiting = st.number_input(
97
+ "Number of Persons Visiting", min_value=1, max_value=10, value=2
98
+ )
99
+ NumberOfChildrenVisiting = st.number_input(
100
+ "Number of Children Visiting", min_value=0, max_value=10, value=0
101
+ )
102
+
103
+ with col6:
104
+ NumberOfTrips = st.number_input(
105
+ "Number of Trips per Year",
106
+ min_value=0,
107
+ max_value=50,
108
+ value=1
109
+ )
110
+ PreferredPropertyStar = st.selectbox(
111
+ "Preferred Property Star", PreferredPropertyStar_vals
112
+ )
113
 
 
 
 
 
 
 
 
114
 
115
+ # ---------------------------------------------------------
116
+ # SECTION 4: Sales Interaction Details
117
+ # ---------------------------------------------------------
118
 
119
+ st.header("4️⃣ Sales Interaction Details")
120
+ col7, col8 = st.columns(2)
121
 
122
+ with col7:
123
+ TypeofContact = st.selectbox("Type of Contact", TypeofContact_vals)
124
+ ProductPitched = st.selectbox("Product Pitched", ProductPitched_vals)
125
 
126
+ with col8:
127
+ DurationOfPitch = st.number_input(
128
+ "Duration of Pitch (minutes)", min_value=0.0, max_value=60.0, value=10.0
129
+ )
130
+ PitchSatisfactionScore = st.selectbox(
131
+ "Pitch Satisfaction Score", sorted(PitchSatisfactionScore_vals)
132
+ )
133
+ NumberOfFollowups = st.number_input(
134
+ "Number of Follow-ups", min_value=0, max_value=20, value=2
135
+ )
136
 
 
 
 
 
 
 
 
137
 
138
+ # ---------------------------------------------------------
139
+ # Prepare Input for Model
140
+ # ---------------------------------------------------------
141
 
142
+ input_data = {
143
+ "Age": Age,
144
+ "TypeofContact": TypeofContact,
145
+ "CityTier": CityTier,
146
+ "DurationOfPitch": DurationOfPitch,
147
+ "Occupation": Occupation,
148
+ "Gender": Gender,
149
+ "NumberOfPersonVisiting": NumberOfPersonVisiting,
150
+ "NumberOfFollowups": NumberOfFollowups,
151
+ "ProductPitched": ProductPitched,
152
+ "PreferredPropertyStar": PreferredPropertyStar,
153
+ "MaritalStatus": MaritalStatus,
154
+ "NumberOfTrips": NumberOfTrips,
155
+ "Passport": Passport, # now 0/1
156
+ "PitchSatisfactionScore": PitchSatisfactionScore,
157
+ "OwnCar": OwnCar, # now 0/1
158
+ "NumberOfChildrenVisiting": NumberOfChildrenVisiting,
159
+ "Designation": Designation,
160
+ "MonthlyIncome": MonthlyIncome
161
+ }
162
 
163
+ import_data_df = pd.DataFrame([input_data])
 
 
 
 
164
 
165
+ # The following code can be enabled to see the etails of data frame prepared from user input
166
+ # This code was used for debugging and now disabled
167
+ ## st.subheader("📦 Input Data Summary")
168
+ ## st.json(input_data)
169
 
170
 
171
+ # ---------------------------------------------------------
172
+ # Prediction Button
173
+ # ---------------------------------------------------------
174
 
175
+ if st.button("Predict"):
176
+ st.success("Prediction logic goes here (connect your model).")
177
 
178
+ prediction = model.predict(import_data_df)[0]
179
+ result = "Customer is likely to Take Product" if prediction == 1 else "Customer will not Take the Product"
180
+ st.subheader("Prediction Result:")
181
+ st.success(f"Prediction as per Model: **{result}**")