mubashirhussaindev commited on
Commit
4a64a69
·
verified ·
1 Parent(s): ae93618

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +160 -11
app.py CHANGED
@@ -25,6 +25,9 @@ FROM_NAME = "Mubashir Hussain"
25
  # === Excel File ===
26
  EXCEL_FILE = "appointments.xlsx"
27
 
 
 
 
28
  # === Google Calendar Event Link Generator ===
29
  def generate_google_calendar_link(name, email, date_str, time_str, timezone):
30
  try:
@@ -125,42 +128,188 @@ def book_appointment(name, email, date, time, timezone):
125
  )
126
  send_email(email, "✅ Appointment Confirmed", user_msg)
127
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
128
  return (
129
  f"✅ Appointment confirmed for {date} at {time} ({timezone}). "
130
  f"A confirmation email with a Google Calendar link has been sent to {email}.",
131
- []
132
  )
133
 
134
  except pytz.exceptions.UnknownTimeZoneError:
135
- return "Invalid timezone. Please use a valid timezone (e.g., Asia/Karachi).", []
136
  except ValueError:
137
- return "Invalid date/time format. Use YYYY-MM-DD for date and HH:MM for time.", []
138
 
139
  # === Gradio UI ===
140
  with gr.Blocks(theme=gr.themes.Soft(), css="""
141
- .gradio-container { max-width: 600px; margin: auto; font-family: Arial, sans-serif; }
142
- .welcome { text-align: center; font-size: 24px; color: #333; margin-bottom: 20px; }
143
- .gr-button { font-size: 16px; margin: 10px; border-radius: 5px; }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
144
  """) as demo:
145
  gr.Markdown(
146
  """
147
  <div class="welcome">Appointment Booking Bot</div>
148
- Fill out the form below to book an appointment. You'll receive a confirmation email with a link to add the appointment to your Google Calendar, and the details will be logged.
149
  """
150
  )
151
  with gr.Column():
152
  name = gr.Textbox(label="Your Name", placeholder="Enter your name")
153
  email = gr.Textbox(label="Your Email", placeholder="Enter your email")
154
- date = gr.Textbox(label="Date", placeholder="YYYY-MM-DD (e.g., 2025-06-01)")
155
- time = gr.Textbox(label="Time", placeholder="HH:MM (e.g., 14:00)")
156
- timezone = gr.Textbox(label="Timezone", placeholder="e.g., Asia/Karachi")
157
  submit_btn = gr.Button("Book Appointment", variant="primary")
158
  output = gr.Textbox(label="Result", interactive=False)
 
 
 
 
 
 
 
159
 
160
  submit_btn.click(
161
  fn=book_appointment,
162
  inputs=[name, email, date, time, timezone],
163
- outputs=[output]
164
  )
165
 
166
  # Launch the app (Hugging Face Spaces handles server_name and server_port)
 
25
  # === Excel File ===
26
  EXCEL_FILE = "appointments.xlsx"
27
 
28
+ # === Time Slots ===
29
+ TIME_SLOTS = [f"{hour:02d}:00" for hour in range(9, 18)] # 9 AM to 5 PM
30
+
31
  # === Google Calendar Event Link Generator ===
32
  def generate_google_calendar_link(name, email, date_str, time_str, timezone):
33
  try:
 
128
  )
129
  send_email(email, "✅ Appointment Confirmed", user_msg)
130
 
131
+ # Generate a styled chart for confirmation
132
+ chart_data = {
133
+ "type": "bar",
134
+ "data": {
135
+ "labels": [f"{date} {time}"],
136
+ "datasets": [{
137
+ "label": "Appointment",
138
+ "data": [1],
139
+ "backgroundColor": "#1E88E5", # Blue to match UI theme
140
+ "borderColor": "#1565C0",
141
+ "borderWidth": 2
142
+ }]
143
+ },
144
+ "options": {
145
+ "scales": {
146
+ "y": {
147
+ "beginAtZero": True,
148
+ "ticks": {
149
+ "stepSize": 1,
150
+ "color": "#333",
151
+ "font": {
152
+ "family": "Roboto, sans-serif",
153
+ "size": 14
154
+ }
155
+ },
156
+ "title": {
157
+ "display": True,
158
+ "text": "Appointment Confirmed",
159
+ "color": "#333",
160
+ "font": {
161
+ "family": "Roboto, sans-serif",
162
+ "size": 16
163
+ }
164
+ }
165
+ },
166
+ "x": {
167
+ "title": {
168
+ "display": True,
169
+ "text": "Date and Time",
170
+ "color": "#333",
171
+ "font": {
172
+ "family": "Roboto, sans-serif",
173
+ "size": 16
174
+ }
175
+ },
176
+ "ticks": {
177
+ "color": "#333",
178
+ "font": {
179
+ "family": "Roboto, sans-serif",
180
+ "size": 14
181
+ }
182
+ }
183
+ }
184
+ },
185
+ "plugins": {
186
+ "title": {
187
+ "display": True,
188
+ "text": f"Appointment for {name}",
189
+ "color": "#1E88E5",
190
+ "font": {
191
+ "family": "Roboto, sans-serif",
192
+ "size": 18
193
+ }
194
+ }
195
+ }
196
+ }
197
+ }
198
+
199
  return (
200
  f"✅ Appointment confirmed for {date} at {time} ({timezone}). "
201
  f"A confirmation email with a Google Calendar link has been sent to {email}.",
202
+ [chart_data]
203
  )
204
 
205
  except pytz.exceptions.UnknownTimeZoneError:
206
+ return "Invalid timezone. Please select a valid timezone.", []
207
  except ValueError:
208
+ return "Invalid date/time format. Please use the provided date picker and time dropdown.", []
209
 
210
  # === Gradio UI ===
211
  with gr.Blocks(theme=gr.themes.Soft(), css="""
212
+ .gradio-container {
213
+ max-width: 700px;
214
+ margin: auto;
215
+ font-family: 'Roboto', sans-serif;
216
+ background-color: #f5f7fa;
217
+ padding: 20px;
218
+ border-radius: 12px;
219
+ box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
220
+ }
221
+ .welcome {
222
+ text-align: center;
223
+ font-size: 28px;
224
+ color: #1E88E5;
225
+ margin-bottom: 20px;
226
+ font-weight: 700;
227
+ }
228
+ .gr-textbox, .gr-dropdown {
229
+ border-radius: 8px;
230
+ border: 2px solid #E0E0E0;
231
+ padding: 10px;
232
+ font-size: 16px;
233
+ transition: border-color 0.3s ease;
234
+ }
235
+ .gr-textbox:focus, .gr-dropdown:focus {
236
+ border-color: #1E88E5;
237
+ outline: none;
238
+ }
239
+ .gr-button {
240
+ background-color: #1E88E5;
241
+ color: white;
242
+ font-size: 16px;
243
+ font-weight: 600;
244
+ padding: 12px 24px;
245
+ border-radius: 8px;
246
+ border: none;
247
+ transition: background-color 0.3s ease, transform 0.2s ease;
248
+ margin: 20px auto;
249
+ display: block;
250
+ }
251
+ .gr-button:hover {
252
+ background-color: #1565C0;
253
+ transform: translateY(-2px);
254
+ }
255
+ .gr-textbox[label="Result"] {
256
+ background-color: #E8F5E9;
257
+ border-color: #4CAF50;
258
+ color: #2E7D32;
259
+ font-weight: 500;
260
+ padding: 15px;
261
+ border-radius: 8px;
262
+ }
263
+ .gr-column {
264
+ background-color: white;
265
+ padding: 20px;
266
+ border-radius: 10px;
267
+ box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
268
+ }
269
+ .footer {
270
+ text-align: center;
271
+ font-size: 14px;
272
+ color: #666;
273
+ margin-top: 20px;
274
+ }
275
+ @media (max-width: 600px) {
276
+ .gradio-container {
277
+ padding: 10px;
278
+ }
279
+ .welcome {
280
+ font-size: 24px;
281
+ }
282
+ .gr-button {
283
+ padding: 10px 20px;
284
+ }
285
+ }
286
  """) as demo:
287
  gr.Markdown(
288
  """
289
  <div class="welcome">Appointment Booking Bot</div>
290
+ Fill out the form below to book an appointment with Mubashir Hussain. You'll receive a confirmation email with a Google Calendar link, and a chart will confirm your booking.
291
  """
292
  )
293
  with gr.Column():
294
  name = gr.Textbox(label="Your Name", placeholder="Enter your name")
295
  email = gr.Textbox(label="Your Email", placeholder="Enter your email")
296
+ date = gr.Textbox(label="Date", placeholder="YYYY-MM-DD (e.g., 2025-06-01)", type="text")
297
+ time = gr.Dropdown(label="Time", choices=TIME_SLOTS, value="09:00")
298
+ timezone = gr.Dropdown(label="Timezone", choices=pytz.all_timezones, value="Asia/Karachi")
299
  submit_btn = gr.Button("Book Appointment", variant="primary")
300
  output = gr.Textbox(label="Result", interactive=False)
301
+ chart_output = gr.Plot(label="Appointment Confirmation")
302
+
303
+ gr.Markdown(
304
+ """
305
+ <div class="footer">Powered by <a href="https://mubashirdev.com" style="color: #1E88E5; text-decoration: none;">mubashirdev.com</a></div>
306
+ """
307
+ )
308
 
309
  submit_btn.click(
310
  fn=book_appointment,
311
  inputs=[name, email, date, time, timezone],
312
+ outputs=[output, chart_output]
313
  )
314
 
315
  # Launch the app (Hugging Face Spaces handles server_name and server_port)