Pijush2023 commited on
Commit
f92e3ac
·
verified ·
1 Parent(s): b652e4e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -1
app.py CHANGED
@@ -317,7 +317,21 @@ def add_message(history, message):
317
  history.append((message, None))
318
  return history, gr.Textbox(value="", interactive=True, placeholder="Enter message or upload file...", show_label=False)
319
 
 
 
 
 
 
 
320
 
 
 
 
 
 
 
 
 
321
 
322
 
323
 
@@ -670,6 +684,7 @@ with gr.Blocks(theme='Pijush2023/scikit-learn-pijush') as demo:
670
  chat_msg = chat_input.submit(add_message, [chatbot, chat_input], [chatbot, chat_input], api_name="voice_query")
671
  tts_choice = gr.Radio(label="Select TTS System", choices=["Alpha", "Beta", "Gamma"], value="Alpha")
672
  retriver_button = gr.Button("Retriever")
 
673
  gr.Markdown("<h1 style='color: red;'>Radar Map</h1>", elem_id="Map-Radar")
674
  location_output = gr.HTML()
675
  retriver_button.click(fn=add_message, inputs=[chatbot, chat_input], outputs=[chatbot, chat_input]).then(
@@ -684,7 +699,7 @@ with gr.Blocks(theme='Pijush2023/scikit-learn-pijush') as demo:
684
 
685
  audio_input = gr.Audio(sources=["microphone"], streaming=True, type='numpy')
686
  audio_input.stream(transcribe_function, inputs=[state, audio_input], outputs=[state, chat_input], api_name="voice_query_to_text")
687
-
688
 
689
  with gr.Column():
690
  weather_output = gr.HTML(value=fetch_local_weather())
 
317
  history.append((message, None))
318
  return history, gr.Textbox(value="", interactive=True, placeholder="Enter message or upload file...", show_label=False)
319
 
320
+ def process_single_audio_chunk(state):
321
+ audio_chunk = state[-1] if state else None
322
+ if audio_chunk:
323
+ stream, full_text, result = transcribe_function(None, audio_chunk)
324
+ return full_text
325
+ return ""
326
 
327
+ def handle_single_chunk(history, choice, tts_choice, state):
328
+ full_text = process_single_audio_chunk(state)
329
+ if full_text:
330
+ history.append((full_text, None))
331
+ response, addresses = generate_answer(full_text, choice)
332
+ history[-1][1] = response
333
+ return history, None
334
+ return history, None
335
 
336
 
337
 
 
684
  chat_msg = chat_input.submit(add_message, [chatbot, chat_input], [chatbot, chat_input], api_name="voice_query")
685
  tts_choice = gr.Radio(label="Select TTS System", choices=["Alpha", "Beta", "Gamma"], value="Alpha")
686
  retriver_button = gr.Button("Retriever")
687
+ single_chunk_button = gr.Button("Process Single Chunk")
688
  gr.Markdown("<h1 style='color: red;'>Radar Map</h1>", elem_id="Map-Radar")
689
  location_output = gr.HTML()
690
  retriver_button.click(fn=add_message, inputs=[chatbot, chat_input], outputs=[chatbot, chat_input]).then(
 
699
 
700
  audio_input = gr.Audio(sources=["microphone"], streaming=True, type='numpy')
701
  audio_input.stream(transcribe_function, inputs=[state, audio_input], outputs=[state, chat_input], api_name="voice_query_to_text")
702
+ single_chunk_button.click(fn=handle_single_chunk, inputs=[chatbot, choice, tts_choice, state], outputs=[chatbot],api_name="single_chunk")
703
 
704
  with gr.Column():
705
  weather_output = gr.HTML(value=fetch_local_weather())