Pijush2023 commited on
Commit
ab83f08
·
verified ·
1 Parent(s): 075192f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +85 -10
app.py CHANGED
@@ -245,20 +245,95 @@ def fetch_local_news():
245
  def fetch_local_events():
246
  api_key = os.environ['SERP_API']
247
  url = f'https://serpapi.com/search.json?engine=google_events&q=Events+in+Omaha&hl=en&gl=us&api_key={api_key}'
248
-
249
  response = requests.get(url)
250
- if response.status_code == 200:
251
  events_results = response.json().get("events_results", [])
252
- events_text = "<h2>Local Events </h2>"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
253
  for index, event in enumerate(events_results):
254
  title = event.get("title", "No title")
255
  date = event.get("date", "No date")
256
  location = event.get("address", "No location")
257
  link = event.get("link", "#")
258
- events_text += f"<p>{index + 1}. {title}<br> Date: {date}<br> Location: {location}<br> <a href='{link}' target='_blank'>Link :</a> <br>"
259
- return events_text
 
 
 
 
 
260
  else:
261
- return "Failed to fetch local events"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
262
 
263
  # Function to fetch local weather
264
  def fetch_local_weather():
@@ -390,8 +465,8 @@ with gr.Blocks(theme='rawrsor1/Everforest') as demo:
390
  # with gr.Column():
391
  # weather_output = gr.HTML(value=fetch_local_weather())
392
 
393
- # with gr.Column():
394
- # news_output = gr.HTML(value=fetch_local_news())
395
 
396
  def setup_ui():
397
  state = gr.State()
@@ -425,8 +500,8 @@ with gr.Blocks(theme='rawrsor1/Everforest') as demo:
425
  audio_output = gr.Audio()
426
  #bot_msg.then(generate_audio_elevenlabs, chatbot, audio_output)
427
  bot_msg_audio = bot_msg.then(lambda history: generate_audio_elevenlabs(history[-1][1]), chatbot, audio_output)
428
- # with gr.Column():
429
- # news_output = gr.HTML(value=fetch_local_events())
430
 
431
  setup_ui()
432
 
 
245
  def fetch_local_events():
246
  api_key = os.environ['SERP_API']
247
  url = f'https://serpapi.com/search.json?engine=google_events&q=Events+in+Omaha&hl=en&gl=us&api_key={api_key}'
248
+
249
  response = requests.get(url)
250
+ if response.status_code == 200):
251
  events_results = response.json().get("events_results", [])
252
+ events_html = """
253
+ <h2 style="font-family: 'Georgia', serif; color: #4CAF50; background-color: #f8f8f8; padding: 10px; border-radius: 10px;">Local Events</h2>
254
+ <style>
255
+ .event-item {
256
+ font-family: 'Verdana', sans-serif;
257
+ color: #333;
258
+ background-color: #f0f8ff;
259
+ margin-bottom: 15px;
260
+ padding: 10px;
261
+ border: 1px solid #ddd;
262
+ border-radius: 5px;
263
+ transition: box-shadow 0.3s ease, background-color 0.3s ease;
264
+ font-weight: bold;
265
+ }
266
+ .event-item:hover {
267
+ box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
268
+ background-color: #e6f7ff;
269
+ }
270
+ .event-item a {
271
+ color: #1E90FF;
272
+ text-decoration: none;
273
+ font-weight: bold;
274
+ }
275
+ .event-item a:hover {
276
+ text-decoration: underline;
277
+ }
278
+ .event-preview {
279
+ position: absolute;
280
+ display: none;
281
+ border: 1px solid #ccc;
282
+ border-radius: 5px;
283
+ box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
284
+ background-color: white;
285
+ z-index: 1000;
286
+ max-width: 300px;
287
+ padding: 10px;
288
+ font-family: 'Verdana', sans-serif;
289
+ color: #333;
290
+ }
291
+ </style>
292
+ <script>
293
+ function showPreview(event, previewContent) {
294
+ var previewBox = document.getElementById('event-preview');
295
+ previewBox.innerHTML = previewContent;
296
+ previewBox.style.left = event.pageX + 'px';
297
+ previewBox.style.top = event.pageY + 'px';
298
+ previewBox.style.display = 'block';
299
+ }
300
+ function hidePreview() {
301
+ var previewBox = document.getElementById('event-preview');
302
+ previewBox.style.display = 'none';
303
+ }
304
+ </script>
305
+ <div id="event-preview" class="event-preview"></div>
306
+ """
307
  for index, event in enumerate(events_results):
308
  title = event.get("title", "No title")
309
  date = event.get("date", "No date")
310
  location = event.get("address", "No location")
311
  link = event.get("link", "#")
312
+ events_html += f"""
313
+ <div class="event-item" onmouseover="showPreview(event, 'Date: {date}<br>Location: {location}')" onmouseout="hidePreview()">
314
+ <a href='{link}' target='_blank'>{index + 1}. {title}</a>
315
+ <p>Date: {date}<br>Location: {location}</p>
316
+ </div>
317
+ """
318
+ return events_html
319
  else:
320
+ return "<p>Failed to fetch local events</p>"
321
+
322
+
323
+
324
+ # response = requests.get(url)
325
+ # if response.status_code == 200:
326
+ # events_results = response.json().get("events_results", [])
327
+ # events_text = "<h2>Local Events </h2>"
328
+ # for index, event in enumerate(events_results):
329
+ # title = event.get("title", "No title")
330
+ # date = event.get("date", "No date")
331
+ # location = event.get("address", "No location")
332
+ # link = event.get("link", "#")
333
+ # events_text += f"<p>{index + 1}. {title}<br> Date: {date}<br> Location: {location}<br> <a href='{link}' target='_blank'>Link :</a> <br>"
334
+ # return events_text
335
+ # else:
336
+ # return "Failed to fetch local events"
337
 
338
  # Function to fetch local weather
339
  def fetch_local_weather():
 
465
  # with gr.Column():
466
  # weather_output = gr.HTML(value=fetch_local_weather())
467
 
468
+ with gr.Column():
469
+ news_output = gr.HTML(value=fetch_local_news())
470
 
471
  def setup_ui():
472
  state = gr.State()
 
500
  audio_output = gr.Audio()
501
  #bot_msg.then(generate_audio_elevenlabs, chatbot, audio_output)
502
  bot_msg_audio = bot_msg.then(lambda history: generate_audio_elevenlabs(history[-1][1]), chatbot, audio_output)
503
+ with gr.Column():
504
+ news_output = gr.HTML(value=fetch_local_events())
505
 
506
  setup_ui()
507