Pijush2023 commited on
Commit
12acd01
·
verified ·
1 Parent(s): 89d5fdd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -91
app.py CHANGED
@@ -364,90 +364,6 @@ def fetch_local_events():
364
  else:
365
  return "<p>Failed to fetch local events</p>"
366
 
367
- # def fetch_local_weather():
368
- # try:
369
- # api_key = os.environ['WEATHER_API']
370
- # url = f'https://weather.visualcrossing.com/VisualCrossingWebServices/rest/services/timeline/omaha?unitGroup=metric&include=events%2Calerts%2Chours%2Cdays%2Ccurrent&key={api_key}'
371
- # response = requests.get(url)
372
- # response.raise_for_status()
373
- # jsonData = response.json()
374
-
375
- # current_conditions = jsonData.get("currentConditions", {})
376
- # temp = current_conditions.get("temp", "N/A")
377
- # condition = current_conditions.get("conditions", "N/A")
378
- # humidity = current_conditions.get("humidity", "N/A")
379
-
380
- # weather_html = f"""
381
- # <div class="weather-theme">
382
- # <h2 style="font-family: 'Georgia', serif; color: #4CAF50; background-color: #f8f8f8; padding: 10px; border-radius: 10px;">Local Weather</h2>
383
- # <div class="weather-content">
384
- # <div class="weather-icon">
385
- # <img src="https://www.weatherbit.io/static/img/icons/{get_weather_icon(condition)}.png" alt="{condition}" style="width: 100px; height: 100px;">
386
- # </div>
387
- # <div class="weather-details">
388
- # <p style="font-family: 'Verdana', sans-serif; color: #333; font-size: 1.2em;">Temperature: {temp}°C</p>
389
- # <p style="font-family: 'Verdana', sans-serif; color: #333; font-size: 1.2em;">Condition: {condition}</p>
390
- # <p style="font-family: 'Verdana', sans-serif; color: #333; font-size: 1.2em;">Humidity: {humidity}%</p>
391
- # </div>
392
- # </div>
393
- # </div>
394
- # <style>
395
- # .weather-theme {{
396
- # animation: backgroundAnimation 10s infinite alternate;
397
- # border: 1px solid #ddd;
398
- # border-radius: 10px;
399
- # padding: 10px;
400
- # margin-bottom: 15px;
401
- # background: linear-gradient(45deg, #ffcc33, #ff6666, #ffcc33, #ff6666);
402
- # background-size: 400% 400%;
403
- # box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
404
- # transition: box-shadow 0.3s ease, background-color 0.3s ease;
405
- # }}
406
- # .weather-theme:hover {{
407
- # box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2);
408
- # background-position: 100% 100%;
409
- # }}
410
- # @keyframes backgroundAnimation {{
411
- # 0% {{ background-position: 0% 50%; }}
412
- # 100% {{ background-position: 100% 50%; }}
413
- # }}
414
- # .weather-content {{
415
- # display: flex;
416
- # align-items: center;
417
- # }}
418
- # .weather-icon {{
419
- # flex: 1;
420
- # }}
421
- # .weather-details {{
422
- # flex: 3;
423
- # }}
424
- # </style>
425
- # """
426
- # return weather_html
427
- # except requests.exceptions.RequestException as e:
428
- # return f"<p>Failed to fetch local weather: {e}</p>"
429
-
430
- # def get_weather_icon(condition):
431
- # condition_map = {
432
- # "Clear": "c01d",
433
- # "Partly Cloudy": "c02d",
434
- # "Cloudy": "c03d",
435
- # "Overcast": "c04d",
436
- # "Mist": "a01d",
437
- # "Patchy rain possible": "r01d",
438
- # "Light rain": "r02d",
439
- # "Moderate rain": "r03d",
440
- # "Heavy rain": "r04d",
441
- # "Snow": "s01d",
442
- # "Thunderstorm": "t01d",
443
- # "Fog": "a05d",
444
- # }
445
- # return condition_map.get(condition, "c04d")
446
-
447
-
448
- import os
449
- import requests
450
-
451
  def fetch_local_weather():
452
  try:
453
  api_key = os.environ['WEATHER_API']
@@ -574,21 +490,33 @@ def transcribe_function(stream, new_chunk):
574
  return stream, full_text, result
575
 
576
 
577
- def update_map_with_response(history):
578
- if not history:
 
 
 
 
 
 
 
579
  return ""
580
- response = history[-1][1]
581
- addresses = extract_addresses(response)
582
  return generate_map(addresses)
583
 
584
  def clear_textbox():
585
  return ""
586
 
587
- def show_map_if_details(history,choice):
 
 
 
 
 
 
588
  if choice in ["Details", "Conversational"]:
589
- return gr.update(visible=True), update_map_with_response(history)
 
590
  else:
591
- return gr.update(visible(False), "")
592
 
593
  def generate_audio_elevenlabs(text):
594
  XI_API_KEY = os.environ['ELEVENLABS_API']
 
364
  else:
365
  return "<p>Failed to fetch local events</p>"
366
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
367
  def fetch_local_weather():
368
  try:
369
  api_key = os.environ['WEATHER_API']
 
490
  return stream, full_text, result
491
 
492
 
493
+ # def update_map_with_response(history):
494
+ # if not history:
495
+ # return ""
496
+ # response = history[-1][1]
497
+ # addresses = extract_addresses(response)
498
+ # return generate_map(addresses)
499
+
500
+ def update_map_with_response(history, addresses):
501
+ if not addresses:
502
  return ""
 
 
503
  return generate_map(addresses)
504
 
505
  def clear_textbox():
506
  return ""
507
 
508
+ # def show_map_if_details(history,choice):
509
+ # if choice in ["Details", "Conversational"]:
510
+ # return gr.update(visible=True), update_map_with_response(history)
511
+ # else:
512
+ # return gr.update(visible(False), "")
513
+
514
+ def show_map_if_details(history, choice):
515
  if choice in ["Details", "Conversational"]:
516
+ map_html = update_map_with_response(history, history[-1][2])
517
+ return gr.update(visible=True), map_html
518
  else:
519
+ return gr.update(visible=False), ""
520
 
521
  def generate_audio_elevenlabs(text):
522
  XI_API_KEY = os.environ['ELEVENLABS_API']