Pijush2023 commited on
Commit
d9dad18
·
verified ·
1 Parent(s): 105fe9d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +109 -108
app.py CHANGED
@@ -764,134 +764,135 @@ def update_images():
764
  def clear_textbox():
765
  return ""
766
 
767
- # with gr.Blocks(theme='Pijush2023/scikit-learn-pijush') as demo:
768
- # with gr.Row():
769
- # with gr.Column():
770
- # state = gr.State()
771
-
772
- # chatbot = gr.Chatbot([], elem_id="RADAR:Channel 94.1", bubble_full_width=False)
773
- # choice = gr.Radio(label="Select Style", choices=["Details", "Conversational"], value="Conversational")
774
-
775
- # gr.Markdown("<h1 style='color: red;'>Talk to RADAR</h1>", elem_id="voice-markdown")
776
-
777
- # chat_input = gr.Textbox(show_copy_button=True, interactive=True, show_label=False, label="ASK Radar !!!", placeholder="After Prompt, click Retriever Only")
778
- # chat_msg = chat_input.submit(add_message, [chatbot, chat_input], [chatbot, chat_input], api_name="voice_query")
779
- # tts_choice = gr.Radio(label="Select TTS System", choices=["Alpha", "Beta", "Gamma"], value="Alpha")
780
- # retriever_button = gr.Button("Retriever")
781
-
782
- # gr.Markdown("<h1 style='color: red;'>Radar Map</h1>", elem_id="Map-Radar")
783
- # location_output = gr.HTML()
784
- # retriever_button.click(fn=add_message, inputs=[chatbot, chat_input], outputs=[chatbot, chat_input]).then(
785
- # fn=bot, inputs=[chatbot, choice, tts_choice, state], outputs=[chatbot, gr.Audio(interactive=False, autoplay=True)], api_name="Ask_Retriever").then(
786
- # fn=show_map_if_details, inputs=[chatbot, choice], outputs=[location_output, location_output], api_name="map_finder").then(
787
- # fn=clear_state_and_textbox, inputs=[], outputs=[chat_input]
788
- # )
789
-
790
- # bot_msg = chat_msg.then(bot, [chatbot, choice, tts_choice], [chatbot], api_name="generate_voice_response")
791
- # bot_msg.then(lambda: gr.Textbox(value="", interactive=True, placeholder="Ask Radar!!!...", show_label=False), None, [chat_input])
792
- # chatbot.like(print_like_dislike, None, None)
793
- # clear_button = gr.Button("Clear")
794
- # clear_button.click(fn=clear_textbox, inputs=[], outputs=[chat_input])
795
-
796
- # # New ASR Component with Whisper
797
- # gr.Markdown("<h2>Hey Radar</h2>")
798
- # audio_input_whisper = gr.Audio(sources=["microphone"], type='numpy')
799
- # transcribe_button_whisper = gr.Button("Transcribe")
800
- # transcribe_button_whisper.click(fn=transcribe_function_whisper, inputs=[audio_input_whisper], outputs=[chat_input], api_name="whisper_asr")
801
-
802
-
803
- # # Streaming ASR component
804
- # gr.Markdown("<h2>Streaming ASR</h2>")
805
- # stream_audio_input = gr.Audio(sources=["microphone"], type='numpy', streaming=True)
806
- # stream_transcription = gr.State(None) # Initialize stream state
807
- # stream_audio_input.change(transcribe_function, inputs=[stream_transcription, stream_audio_input], outputs=[stream_transcription, chat_input],api_name="text_to_voice")
808
-
809
- # # Add the clear button for ASR history
810
- # clear_btn = gr.Button("Clear ASR ")
811
- # # clear_btn.click(lambda: [None, ""], outputs=[stream_transcription, chat_input])
812
- # clear_button.click(lambda:[None,None] ,outputs=[chat_input, state])
813
-
814
- # # with gr.Column():
815
- # # weather_output = gr.HTML(value=fetch_local_weather())
816
- # # news_output = gr.HTML(value=fetch_local_news())
817
- # # news_output = gr.HTML(value=fetch_local_events())
818
-
819
- # with gr.Column():
820
- # image_output_1 = gr.Image(value=generate_image(hardcoded_prompt_1), width=400, height=400)
821
- # image_output_2 = gr.Image(value=generate_image(hardcoded_prompt_2), width=400, height=400)
822
- # image_output_3 = gr.Image(value=generate_image(hardcoded_prompt_3), width=400, height=400)
823
-
824
- # refresh_button = gr.Button("Refresh Images")
825
- # refresh_button.click(fn=update_images, inputs=None, outputs=[image_output_1, image_output_2, image_output_3])
826
- # # location_output = gr.HTML()
827
- # bot_msg.then(show_map_if_details, [chatbot, choice], [location_output, location_output], api_name="map_finder")
828
-
829
- # demo.queue()
830
- # demo.launch(share=True)
831
-
832
  with gr.Blocks(theme='Pijush2023/scikit-learn-pijush') as demo:
833
  with gr.Row():
834
  with gr.Column():
835
  state = gr.State()
836
-
837
  chatbot = gr.Chatbot([], elem_id="RADAR:Channel 94.1", bubble_full_width=False)
838
  choice = gr.Radio(label="Select Style", choices=["Details", "Conversational"], value="Conversational")
839
-
840
  gr.Markdown("<h1 style='color: red;'>Talk to RADAR</h1>", elem_id="voice-markdown")
841
-
842
- chat_input = gr.Textbox(show_copy_button=True, interactive=True, show_label=False, label="ASK Radar !!!", placeholder="After Prompt,click Retriever Only")
 
843
  tts_choice = gr.Radio(label="Select TTS System", choices=["Alpha", "Beta", "Gamma"], value="Alpha")
844
  retriever_button = gr.Button("Retriever")
845
-
846
- clear_button = gr.Button("Clear")
847
- clear_button.click(lambda:[None,None] ,outputs=[chat_input, state])
848
-
849
  gr.Markdown("<h1 style='color: red;'>Radar Map</h1>", elem_id="Map-Radar")
850
  location_output = gr.HTML()
 
 
 
 
 
 
851
 
852
- # Define a single audio component
853
- audio_output = gr.Audio(interactive=False, autoplay=True)
854
-
855
- def stop_audio():
856
- audio_output.stop()
857
- return None
858
-
859
- # Define the sequence of actions for the "Retriever" button
860
- retriever_sequence = (
861
- retriever_button.click(fn=stop_audio, inputs=[], outputs=[audio_output],api_name="Ask_Retriever")
862
- .then(fn=add_message, inputs=[chatbot, chat_input], outputs=[chatbot, chat_input],api_name="voice_query")
863
- .then(fn=bot, inputs=[chatbot, choice, tts_choice], outputs=[chatbot, audio_output],api_name="generate_voice_response" )
864
- .then(fn=show_map_if_details, inputs=[chatbot, choice], outputs=[location_output, location_output], api_name="map_finder")
865
- .then(fn=clear_textbox, inputs=[], outputs=[chat_input])
866
- )
867
-
868
- # Link the "Enter" key (submit event) to the same sequence of actions
869
- chat_input.submit(fn=stop_audio, inputs=[], outputs=[audio_output])
870
- chat_input.submit(fn=add_message, inputs=[chatbot, chat_input], outputs=[chatbot, chat_input],api_name="voice_query").then(
871
- fn=bot, inputs=[chatbot, choice, tts_choice], outputs=[chatbot, audio_output], api_name="generate_voice_response"
872
- ).then(
873
- fn=show_map_if_details, inputs=[chatbot, choice], outputs=[location_output, location_output], api_name="map_finder"
874
- ).then(
875
- fn=clear_textbox, inputs=[], outputs=[chat_input]
876
- )
877
-
878
- audio_input = gr.Audio(sources=["microphone"], streaming=True, type='numpy', every=0.1)
879
- audio_input.stream(transcribe_function, inputs=[state, audio_input], outputs=[state, chat_input], api_name="voice_query_to_text")
880
-
881
- with gr.Column():
882
- weather_output = gr.HTML(value=fetch_local_weather())
883
- news_output = gr.HTML(value=fetch_local_news())
884
- events_output = gr.HTML(value=fetch_local_events())
885
 
 
 
 
 
 
886
  with gr.Column():
887
  image_output_1 = gr.Image(value=generate_image(hardcoded_prompt_1), width=400, height=400)
888
  image_output_2 = gr.Image(value=generate_image(hardcoded_prompt_2), width=400, height=400)
889
  image_output_3 = gr.Image(value=generate_image(hardcoded_prompt_3), width=400, height=400)
890
 
891
  refresh_button = gr.Button("Refresh Images")
892
- refresh_button.click(fn=update_images, inputs=None, outputs=[image_output_1, image_output_2, image_output_3], api_name="update_images")
893
-
 
 
894
  demo.queue()
895
  demo.launch(share=True)
896
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
897
 
 
764
  def clear_textbox():
765
  return ""
766
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
767
  with gr.Blocks(theme='Pijush2023/scikit-learn-pijush') as demo:
768
  with gr.Row():
769
  with gr.Column():
770
  state = gr.State()
771
+
772
  chatbot = gr.Chatbot([], elem_id="RADAR:Channel 94.1", bubble_full_width=False)
773
  choice = gr.Radio(label="Select Style", choices=["Details", "Conversational"], value="Conversational")
774
+
775
  gr.Markdown("<h1 style='color: red;'>Talk to RADAR</h1>", elem_id="voice-markdown")
776
+
777
+ chat_input = gr.Textbox(show_copy_button=True, interactive=True, show_label=False, label="ASK Radar !!!", placeholder="After Prompt, click Retriever Only")
778
+ chat_msg = chat_input.submit(add_message, [chatbot, chat_input], [chatbot, chat_input], api_name="voice_query")
779
  tts_choice = gr.Radio(label="Select TTS System", choices=["Alpha", "Beta", "Gamma"], value="Alpha")
780
  retriever_button = gr.Button("Retriever")
781
+
 
 
 
782
  gr.Markdown("<h1 style='color: red;'>Radar Map</h1>", elem_id="Map-Radar")
783
  location_output = gr.HTML()
784
+ retriever_button.click(fn=add_message, inputs=[chatbot, chat_input], outputs=[chatbot, chat_input]).then(
785
+ fn=bot, inputs=[chatbot, choice, tts_choice, state], outputs=[chatbot, gr.Audio(interactive=False, autoplay=True)], api_name="Ask_Retriever").then(
786
+ fn=show_map_if_details, inputs=[chatbot, choice], outputs=[location_output, location_output], api_name="map_finder").then(
787
+ fn=clear_textbox,inputs=[],outputs=[chat_input]
788
+ )
789
+ # fn=clear_state_and_textbox, inputs=[], outputs=[chat_input]
790
 
791
+ bot_msg = chat_msg.then(bot, [chatbot, choice, tts_choice], [chatbot], api_name="generate_voice_response")
792
+ bot_msg.then(lambda: gr.Textbox(value="", interactive=True, placeholder="Ask Radar!!!...", show_label=False), None, [chat_input])
793
+ chatbot.like(print_like_dislike, None, None)
794
+ clear_button = gr.Button("Clear")
795
+ clear_button.click(fn=clear_textbox, inputs=[], outputs=[chat_input])
796
+
797
+ # New ASR Component with Whisper
798
+ gr.Markdown("<h2>Hey Radar</h2>")
799
+ audio_input_whisper = gr.Audio(sources=["microphone"], type='numpy')
800
+ transcribe_button_whisper = gr.Button("Transcribe")
801
+ transcribe_button_whisper.click(fn=transcribe_function_whisper, inputs=[audio_input_whisper], outputs=[chat_input], api_name="whisper_asr")
802
+
803
+
804
+ # Streaming ASR component
805
+ gr.Markdown("<h2>Streaming ASR</h2>")
806
+ stream_audio_input = gr.Audio(sources=["microphone"], type='numpy', streaming=True)
807
+ stream_transcription = gr.State(None) # Initialize stream state
808
+ stream_audio_input.change(transcribe_function, inputs=[stream_transcription, stream_audio_input], outputs=[stream_transcription, chat_input],api_name="text_to_voice")
809
+
810
+ # Add the clear button for ASR history
811
+ clear_btn = gr.Button("Clear ASR ")
812
+ # clear_btn.click(lambda: [None, ""], outputs=[stream_transcription, chat_input])
813
+ clear_button.click(lambda:[None,None] ,outputs=[chat_input, state])
 
 
 
 
 
 
 
 
 
 
814
 
815
+ # with gr.Column():
816
+ # weather_output = gr.HTML(value=fetch_local_weather())
817
+ # news_output = gr.HTML(value=fetch_local_news())
818
+ # news_output = gr.HTML(value=fetch_local_events())
819
+
820
  with gr.Column():
821
  image_output_1 = gr.Image(value=generate_image(hardcoded_prompt_1), width=400, height=400)
822
  image_output_2 = gr.Image(value=generate_image(hardcoded_prompt_2), width=400, height=400)
823
  image_output_3 = gr.Image(value=generate_image(hardcoded_prompt_3), width=400, height=400)
824
 
825
  refresh_button = gr.Button("Refresh Images")
826
+ refresh_button.click(fn=update_images, inputs=None, outputs=[image_output_1, image_output_2, image_output_3])
827
+ # location_output = gr.HTML()
828
+ bot_msg.then(show_map_if_details, [chatbot, choice], [location_output, location_output], api_name="map_finder")
829
+
830
  demo.queue()
831
  demo.launch(share=True)
832
 
833
+ # with gr.Blocks(theme='Pijush2023/scikit-learn-pijush') as demo:
834
+ # with gr.Row():
835
+ # with gr.Column():
836
+ # state = gr.State()
837
+
838
+ # chatbot = gr.Chatbot([], elem_id="RADAR:Channel 94.1", bubble_full_width=False)
839
+ # choice = gr.Radio(label="Select Style", choices=["Details", "Conversational"], value="Conversational")
840
+
841
+ # gr.Markdown("<h1 style='color: red;'>Talk to RADAR</h1>", elem_id="voice-markdown")
842
+
843
+ # chat_input = gr.Textbox(show_copy_button=True, interactive=True, show_label=False, label="ASK Radar !!!", placeholder="After Prompt,click Retriever Only")
844
+ # tts_choice = gr.Radio(label="Select TTS System", choices=["Alpha", "Beta", "Gamma"], value="Alpha")
845
+ # retriever_button = gr.Button("Retriever")
846
+
847
+ # clear_button = gr.Button("Clear")
848
+ # clear_button.click(lambda:[None,None] ,outputs=[chat_input, state])
849
+
850
+ # gr.Markdown("<h1 style='color: red;'>Radar Map</h1>", elem_id="Map-Radar")
851
+ # location_output = gr.HTML()
852
+
853
+ # # Define a single audio component
854
+ # audio_output = gr.Audio(interactive=False, autoplay=True)
855
+
856
+ # def stop_audio():
857
+ # audio_output.stop()
858
+ # return None
859
+
860
+ # # Define the sequence of actions for the "Retriever" button
861
+ # retriever_sequence = (
862
+ # retriever_button.click(fn=stop_audio, inputs=[], outputs=[audio_output],api_name="Ask_Retriever")
863
+ # .then(fn=add_message, inputs=[chatbot, chat_input], outputs=[chatbot, chat_input],api_name="voice_query")
864
+ # .then(fn=bot, inputs=[chatbot, choice, tts_choice], outputs=[chatbot, audio_output],api_name="generate_voice_response" )
865
+ # .then(fn=show_map_if_details, inputs=[chatbot, choice], outputs=[location_output, location_output], api_name="map_finder")
866
+ # .then(fn=clear_textbox, inputs=[], outputs=[chat_input])
867
+ # )
868
+
869
+ # # Link the "Enter" key (submit event) to the same sequence of actions
870
+ # chat_input.submit(fn=stop_audio, inputs=[], outputs=[audio_output])
871
+ # chat_input.submit(fn=add_message, inputs=[chatbot, chat_input], outputs=[chatbot, chat_input],api_name="voice_query").then(
872
+ # fn=bot, inputs=[chatbot, choice, tts_choice], outputs=[chatbot, audio_output], api_name="generate_voice_response"
873
+ # ).then(
874
+ # fn=show_map_if_details, inputs=[chatbot, choice], outputs=[location_output, location_output], api_name="map_finder"
875
+ # ).then(
876
+ # fn=clear_textbox, inputs=[], outputs=[chat_input]
877
+ # )
878
+
879
+ # audio_input = gr.Audio(sources=["microphone"], streaming=True, type='numpy', every=0.1)
880
+ # audio_input.stream(transcribe_function, inputs=[state, audio_input], outputs=[state, chat_input], api_name="voice_query_to_text")
881
+
882
+ # with gr.Column():
883
+ # weather_output = gr.HTML(value=fetch_local_weather())
884
+ # news_output = gr.HTML(value=fetch_local_news())
885
+ # events_output = gr.HTML(value=fetch_local_events())
886
+
887
+ # with gr.Column():
888
+ # image_output_1 = gr.Image(value=generate_image(hardcoded_prompt_1), width=400, height=400)
889
+ # image_output_2 = gr.Image(value=generate_image(hardcoded_prompt_2), width=400, height=400)
890
+ # image_output_3 = gr.Image(value=generate_image(hardcoded_prompt_3), width=400, height=400)
891
+
892
+ # refresh_button = gr.Button("Refresh Images")
893
+ # refresh_button.click(fn=update_images, inputs=None, outputs=[image_output_1, image_output_2, image_output_3], api_name="update_images")
894
+
895
+ # demo.queue()
896
+ # demo.launch(share=True)
897
+
898