Pijush2023 commited on
Commit
5b88da1
·
verified ·
1 Parent(s): 40ede2f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -39
app.py CHANGED
@@ -146,24 +146,6 @@ def extract_location_from_response(response):
146
  # return history, addresses
147
 
148
 
149
- # def bot(history, choice):
150
- # if not history:
151
- # return history
152
- # response, addresses = generate_answer(history[-1][0], choice)
153
- # history[-1][1] = ""
154
-
155
- # # Generate audio for the entire response in a separate thread
156
- # with concurrent.futures.ThreadPoolExecutor() as executor:
157
- # audio_future = executor.submit(generate_audio_elevenlabs, response)
158
-
159
- # for character in response:
160
- # history[-1][1] += character
161
- # time.sleep(0.05) # Adjust the speed of text appearance
162
- # yield history, None
163
-
164
- # audio_path = audio_future.result()
165
- # yield history, audio_path
166
-
167
  def bot(history, choice):
168
  if not history:
169
  return history
@@ -180,7 +162,8 @@ def bot(history, choice):
180
  yield history, None
181
 
182
  audio_path = audio_future.result()
183
- yield history, audio_path, addresses
 
184
 
185
  def add_message(history, message):
186
  history.append((message, None))
@@ -507,37 +490,32 @@ def transcribe_function(stream, new_chunk):
507
  return stream, full_text, result
508
 
509
 
510
- # def update_map_with_response(history):
511
- # if not history:
512
- # return ""
513
- # response = history[-1][1]
514
- # addresses = extract_addresses(response)
515
- # return generate_map(addresses)
516
-
517
-
518
- def update_map_with_response(history, addresses):
519
- if not addresses:
520
  return ""
 
 
521
  return generate_map(addresses)
522
 
523
 
 
524
  def clear_textbox():
525
  return ""
526
 
527
- # def show_map_if_details(history,choice):
528
- # if choice in ["Details", "Conversational"]:
529
- # return gr.update(visible=True), update_map_with_response(history)
530
- # else:
531
- # return gr.update(visible(False), "")
532
-
533
- def show_map_if_details(history, choice):
534
  if choice in ["Details", "Conversational"]:
535
- addresses = history[-1][2] if len(history[-1]) > 2 else []
536
- map_html = update_map_with_response(history, addresses)
537
- return gr.update(visible=True), map_html
538
  else:
539
  return gr.update(visible(False), "")
540
 
 
 
 
 
 
 
 
 
541
 
542
  def generate_audio_elevenlabs(text):
543
  XI_API_KEY = os.environ['ELEVENLABS_API']
 
146
  # return history, addresses
147
 
148
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
149
  def bot(history, choice):
150
  if not history:
151
  return history
 
162
  yield history, None
163
 
164
  audio_path = audio_future.result()
165
+ yield history, audio_path
166
+
167
 
168
  def add_message(history, message):
169
  history.append((message, None))
 
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
 
501
+
502
  def clear_textbox():
503
  return ""
504
 
505
+ def show_map_if_details(history,choice):
 
 
 
 
 
 
506
  if choice in ["Details", "Conversational"]:
507
+ return gr.update(visible=True), update_map_with_response(history)
 
 
508
  else:
509
  return gr.update(visible(False), "")
510
 
511
+ # def show_map_if_details(history, choice):
512
+ # if choice in ["Details", "Conversational"]:
513
+ # addresses = history[-1][2] if len(history[-1]) > 2 else []
514
+ # map_html = update_map_with_response(history, addresses)
515
+ # return gr.update(visible=True), map_html
516
+ # else:
517
+ # return gr.update(visible(False), "")
518
+
519
 
520
  def generate_audio_elevenlabs(text):
521
  XI_API_KEY = os.environ['ELEVENLABS_API']