Pijush2023 commited on
Commit
c82efd7
·
verified ·
1 Parent(s): f8395c3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -2
app.py CHANGED
@@ -1343,6 +1343,10 @@ def transcribe_function_whisper(audio):
1343
  full_text = result.get("text", "")
1344
  return full_text
1345
 
 
 
 
 
1346
  with gr.Blocks(theme='Pijush2023/scikit-learn-pijush') as demo:
1347
  with gr.Row():
1348
  with gr.Column():
@@ -1357,14 +1361,17 @@ with gr.Blocks(theme='Pijush2023/scikit-learn-pijush') as demo:
1357
  chat_msg = chat_input.submit(add_message, [chatbot, chat_input], [chatbot, chat_input], api_name="voice_query")
1358
  tts_choice = gr.Radio(label="Select TTS System", choices=["Alpha", "Beta", "Gamma"], value="Alpha")
1359
  retriever_button = gr.Button("Retriever")
 
 
 
 
1360
 
1361
  gr.Markdown("<h1 style='color: red;'>Radar Map</h1>", elem_id="Map-Radar")
1362
  location_output = gr.HTML()
1363
  retriever_button.click(fn=add_message, inputs=[chatbot, chat_input], outputs=[chatbot, chat_input]).then(
1364
  fn=bot, inputs=[chatbot, choice, tts_choice, state], outputs=[chatbot, gr.Audio(interactive=False, autoplay=True)], api_name="Ask_Retriever").then(
1365
  fn=show_map_if_details, inputs=[chatbot, choice], outputs=[location_output, location_output], api_name="map_finder").then(
1366
- fn=clear_state_and_textbox, inputs=[], outputs=[chat_input]
1367
- )
1368
 
1369
  bot_msg = chat_msg.then(bot, [chatbot, choice, tts_choice], [chatbot], api_name="generate_voice_response")
1370
  bot_msg.then(lambda: gr.Textbox(value="", interactive=True, placeholder="Ask Radar!!!...", show_label=False), None, [chat_input])
@@ -1386,6 +1393,9 @@ with gr.Blocks(theme='Pijush2023/scikit-learn-pijush') as demo:
1386
  stream_audio_input = gr.Audio(sources=["microphone"], type='numpy', streaming=True)
1387
  stream_transcription = gr.State(None) # Initialize stream state
1388
  stream_audio_input.change(transcribe_function, inputs=[stream_transcription, stream_audio_input], outputs=[stream_transcription, chat_input])
 
 
 
1389
 
1390
  # with gr.Column():
1391
  # weather_output = gr.HTML(value=fetch_local_weather())
 
1343
  full_text = result.get("text", "")
1344
  return full_text
1345
 
1346
+ # Add a clear function to reset the stream state and chat input
1347
+ def clear_stream_transcription():
1348
+ return None, ""
1349
+
1350
  with gr.Blocks(theme='Pijush2023/scikit-learn-pijush') as demo:
1351
  with gr.Row():
1352
  with gr.Column():
 
1361
  chat_msg = chat_input.submit(add_message, [chatbot, chat_input], [chatbot, chat_input], api_name="voice_query")
1362
  tts_choice = gr.Radio(label="Select TTS System", choices=["Alpha", "Beta", "Gamma"], value="Alpha")
1363
  retriever_button = gr.Button("Retriever")
1364
+
1365
+ # Add the clear button and bind it to the clear function
1366
+ clear_btn = gr.Button("Clear Stream Transcription")
1367
+ clear_btn.click(clear_stream_transcription, outputs=[stream_transcription, chat_input])
1368
 
1369
  gr.Markdown("<h1 style='color: red;'>Radar Map</h1>", elem_id="Map-Radar")
1370
  location_output = gr.HTML()
1371
  retriever_button.click(fn=add_message, inputs=[chatbot, chat_input], outputs=[chatbot, chat_input]).then(
1372
  fn=bot, inputs=[chatbot, choice, tts_choice, state], outputs=[chatbot, gr.Audio(interactive=False, autoplay=True)], api_name="Ask_Retriever").then(
1373
  fn=show_map_if_details, inputs=[chatbot, choice], outputs=[location_output, location_output], api_name="map_finder").then(
1374
+ fn=clear_state_and_textbox, inputs=[], outputs=[chat_input])
 
1375
 
1376
  bot_msg = chat_msg.then(bot, [chatbot, choice, tts_choice], [chatbot], api_name="generate_voice_response")
1377
  bot_msg.then(lambda: gr.Textbox(value="", interactive=True, placeholder="Ask Radar!!!...", show_label=False), None, [chat_input])
 
1393
  stream_audio_input = gr.Audio(sources=["microphone"], type='numpy', streaming=True)
1394
  stream_transcription = gr.State(None) # Initialize stream state
1395
  stream_audio_input.change(transcribe_function, inputs=[stream_transcription, stream_audio_input], outputs=[stream_transcription, chat_input])
1396
+
1397
+
1398
+
1399
 
1400
  # with gr.Column():
1401
  # weather_output = gr.HTML(value=fetch_local_weather())