Pijush2023 commited on
Commit
709dafc
·
verified ·
1 Parent(s): 622ab15

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +82 -11
app.py CHANGED
@@ -1345,6 +1345,76 @@ def transcribe_function_whisper(audio):
1345
 
1346
 
1347
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1348
  with gr.Blocks(theme='Pijush2023/scikit-learn-pijush') as demo:
1349
  with gr.Row():
1350
  with gr.Column():
@@ -1359,15 +1429,14 @@ with gr.Blocks(theme='Pijush2023/scikit-learn-pijush') as demo:
1359
  chat_msg = chat_input.submit(add_message, [chatbot, chat_input], [chatbot, chat_input], api_name="voice_query")
1360
  tts_choice = gr.Radio(label="Select TTS System", choices=["Alpha", "Beta", "Gamma"], value="Alpha")
1361
  retriever_button = gr.Button("Retriever")
1362
-
1363
-
1364
 
1365
  gr.Markdown("<h1 style='color: red;'>Radar Map</h1>", elem_id="Map-Radar")
1366
  location_output = gr.HTML()
1367
  retriever_button.click(fn=add_message, inputs=[chatbot, chat_input], outputs=[chatbot, chat_input]).then(
1368
  fn=bot, inputs=[chatbot, choice, tts_choice, state], outputs=[chatbot, gr.Audio(interactive=False, autoplay=True)], api_name="Ask_Retriever").then(
1369
  fn=show_map_if_details, inputs=[chatbot, choice], outputs=[location_output, location_output], api_name="map_finder").then(
1370
- fn=clear_state_and_textbox, inputs=[], outputs=[chat_input])
 
1371
 
1372
  bot_msg = chat_msg.then(bot, [chatbot, choice, tts_choice], [chatbot], api_name="generate_voice_response")
1373
  bot_msg.then(lambda: gr.Textbox(value="", interactive=True, placeholder="Ask Radar!!!...", show_label=False), None, [chat_input])
@@ -1380,19 +1449,23 @@ with gr.Blocks(theme='Pijush2023/scikit-learn-pijush') as demo:
1380
  gr.Markdown("<h2>Hey Radar</h2>")
1381
  audio_input = gr.Audio(sources=["microphone"], type='numpy')
1382
  transcribe_button = gr.Button("Transcribe")
1383
- transcribe_button.click(fn=transcribe_and_update_textbox, inputs=[audio_input], outputs=[chat_input],api_name="voice_to_text")
1384
 
1385
-
 
 
 
 
1386
 
1387
  # Streaming ASR component
1388
- gr.Markdown("<h2>Hey Radar ASR</h2>")
1389
  stream_audio_input = gr.Audio(sources=["microphone"], type='numpy', streaming=True)
1390
  stream_transcription = gr.State(None) # Initialize stream state
1391
  stream_audio_input.change(transcribe_function, inputs=[stream_transcription, stream_audio_input], outputs=[stream_transcription, chat_input])
1392
 
1393
- clear_btn.click(lambda: [None, 0], outputs=[None, 0])
1394
-
1395
-
1396
 
1397
  # with gr.Column():
1398
  # weather_output = gr.HTML(value=fetch_local_weather())
@@ -1413,5 +1486,3 @@ demo.queue()
1413
  demo.launch(share=True)
1414
 
1415
 
1416
-
1417
-
 
1345
 
1346
 
1347
 
1348
+ # with gr.Blocks(theme='Pijush2023/scikit-learn-pijush') as demo:
1349
+ # with gr.Row():
1350
+ # with gr.Column():
1351
+ # state = gr.State()
1352
+
1353
+ # chatbot = gr.Chatbot([], elem_id="RADAR:Channel 94.1", bubble_full_width=False)
1354
+ # choice = gr.Radio(label="Select Style", choices=["Details", "Conversational"], value="Conversational")
1355
+
1356
+ # gr.Markdown("<h1 style='color: red;'>Talk to RADAR</h1>", elem_id="voice-markdown")
1357
+
1358
+ # chat_input = gr.Textbox(show_copy_button=True, interactive=True, show_label=False, label="ASK Radar !!!", placeholder="After Prompt, click Retriever Only")
1359
+ # chat_msg = chat_input.submit(add_message, [chatbot, chat_input], [chatbot, chat_input], api_name="voice_query")
1360
+ # tts_choice = gr.Radio(label="Select TTS System", choices=["Alpha", "Beta", "Gamma"], value="Alpha")
1361
+ # retriever_button = gr.Button("Retriever")
1362
+
1363
+
1364
+
1365
+ # gr.Markdown("<h1 style='color: red;'>Radar Map</h1>", elem_id="Map-Radar")
1366
+ # location_output = gr.HTML()
1367
+ # retriever_button.click(fn=add_message, inputs=[chatbot, chat_input], outputs=[chatbot, chat_input]).then(
1368
+ # fn=bot, inputs=[chatbot, choice, tts_choice, state], outputs=[chatbot, gr.Audio(interactive=False, autoplay=True)], api_name="Ask_Retriever").then(
1369
+ # fn=show_map_if_details, inputs=[chatbot, choice], outputs=[location_output, location_output], api_name="map_finder").then(
1370
+ # fn=clear_state_and_textbox, inputs=[], outputs=[chat_input])
1371
+
1372
+ # bot_msg = chat_msg.then(bot, [chatbot, choice, tts_choice], [chatbot], api_name="generate_voice_response")
1373
+ # bot_msg.then(lambda: gr.Textbox(value="", interactive=True, placeholder="Ask Radar!!!...", show_label=False), None, [chat_input])
1374
+ # chatbot.like(print_like_dislike, None, None)
1375
+ # clear_button = gr.Button("Clear")
1376
+ # clear_button.click(fn=clear_textbox, inputs=None, outputs=chat_input)
1377
+
1378
+ # # Recorder section
1379
+
1380
+ # gr.Markdown("<h2>Hey Radar</h2>")
1381
+ # audio_input = gr.Audio(sources=["microphone"], type='numpy')
1382
+ # transcribe_button = gr.Button("Transcribe")
1383
+ # transcribe_button.click(fn=transcribe_and_update_textbox, inputs=[audio_input], outputs=[chat_input],api_name="voice_to_text")
1384
+
1385
+
1386
+
1387
+ # # Streaming ASR component
1388
+ # gr.Markdown("<h2>Hey Radar ASR</h2>")
1389
+ # stream_audio_input = gr.Audio(sources=["microphone"], type='numpy', streaming=True)
1390
+ # stream_transcription = gr.State(None) # Initialize stream state
1391
+ # stream_audio_input.change(transcribe_function, inputs=[stream_transcription, stream_audio_input], outputs=[stream_transcription, chat_input])
1392
+
1393
+
1394
+
1395
+
1396
+
1397
+ # # with gr.Column():
1398
+ # # weather_output = gr.HTML(value=fetch_local_weather())
1399
+ # # news_output = gr.HTML(value=fetch_local_news())
1400
+ # # news_output = gr.HTML(value=fetch_local_events())
1401
+
1402
+ # with gr.Column():
1403
+ # image_output_1 = gr.Image(value=generate_image(hardcoded_prompt_1), width=400, height=400)
1404
+ # image_output_2 = gr.Image(value=generate_image(hardcoded_prompt_2), width=400, height=400)
1405
+ # image_output_3 = gr.Image(value=generate_image(hardcoded_prompt_3), width=400, height=400)
1406
+
1407
+ # refresh_button = gr.Button("Refresh Images")
1408
+ # refresh_button.click(fn=update_images, inputs=None, outputs=[image_output_1, image_output_2, image_output_3])
1409
+ # # location_output = gr.HTML()
1410
+ # bot_msg.then(show_map_if_details, [chatbot, choice], [location_output, location_output], api_name="map_finder")
1411
+
1412
+ # demo.queue()
1413
+ # demo.launch(share=True)
1414
+
1415
+ def clear_stream_transcription():
1416
+ return None, ""
1417
+
1418
  with gr.Blocks(theme='Pijush2023/scikit-learn-pijush') as demo:
1419
  with gr.Row():
1420
  with gr.Column():
 
1429
  chat_msg = chat_input.submit(add_message, [chatbot, chat_input], [chatbot, chat_input], api_name="voice_query")
1430
  tts_choice = gr.Radio(label="Select TTS System", choices=["Alpha", "Beta", "Gamma"], value="Alpha")
1431
  retriever_button = gr.Button("Retriever")
 
 
1432
 
1433
  gr.Markdown("<h1 style='color: red;'>Radar Map</h1>", elem_id="Map-Radar")
1434
  location_output = gr.HTML()
1435
  retriever_button.click(fn=add_message, inputs=[chatbot, chat_input], outputs=[chatbot, chat_input]).then(
1436
  fn=bot, inputs=[chatbot, choice, tts_choice, state], outputs=[chatbot, gr.Audio(interactive=False, autoplay=True)], api_name="Ask_Retriever").then(
1437
  fn=show_map_if_details, inputs=[chatbot, choice], outputs=[location_output, location_output], api_name="map_finder").then(
1438
+ fn=clear_state_and_textbox, inputs=[], outputs=[chat_input]
1439
+ )
1440
 
1441
  bot_msg = chat_msg.then(bot, [chatbot, choice, tts_choice], [chatbot], api_name="generate_voice_response")
1442
  bot_msg.then(lambda: gr.Textbox(value="", interactive=True, placeholder="Ask Radar!!!...", show_label=False), None, [chat_input])
 
1449
  gr.Markdown("<h2>Hey Radar</h2>")
1450
  audio_input = gr.Audio(sources=["microphone"], type='numpy')
1451
  transcribe_button = gr.Button("Transcribe")
1452
+ transcribe_button.click(fn=transcribe_and_update_textbox, inputs=[audio_input], outputs=[chat_input], api_name="voice_to_text")
1453
 
1454
+ # New ASR Component with Whisper
1455
+ gr.Markdown("<h2>Whisper ASR</h2>")
1456
+ audio_input_whisper = gr.Audio(sources=["microphone"], type='numpy')
1457
+ transcribe_button_whisper = gr.Button("Transcribe with Whisper")
1458
+ transcribe_button_whisper.click(fn=transcribe_function_whisper, inputs=[audio_input_whisper], outputs=[chat_input], api_name="whisper_asr")
1459
 
1460
  # Streaming ASR component
1461
+ gr.Markdown("<h2>Streaming ASR</h2>")
1462
  stream_audio_input = gr.Audio(sources=["microphone"], type='numpy', streaming=True)
1463
  stream_transcription = gr.State(None) # Initialize stream state
1464
  stream_audio_input.change(transcribe_function, inputs=[stream_transcription, stream_audio_input], outputs=[stream_transcription, chat_input])
1465
 
1466
+ # Add the clear button for ASR history
1467
+ clear_btn = gr.Button("Clear ASR History")
1468
+ clear_btn.click(lambda: [None, ""], outputs=[stream_transcription, chat_input])
1469
 
1470
  # with gr.Column():
1471
  # weather_output = gr.HTML(value=fetch_local_weather())
 
1486
  demo.launch(share=True)
1487
 
1488