Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -318,27 +318,6 @@ def generate_answer(message, choice):
|
|
318 |
addresses = extract_addresses(response['output'])
|
319 |
return response['output'], addresses
|
320 |
|
321 |
-
# def bot(history, choice, tts_choice, state):
|
322 |
-
# if not history:
|
323 |
-
# return history
|
324 |
-
# response, addresses = generate_answer(history[-1][0], choice)
|
325 |
-
# history[-1][1] = ""
|
326 |
-
|
327 |
-
# with concurrent.futures.ThreadPoolExecutor() as executor:
|
328 |
-
# if tts_choice == "Alpha":
|
329 |
-
# audio_future = executor.submit(generate_audio_elevenlabs, response)
|
330 |
-
# elif tts_choice == "Beta":
|
331 |
-
# audio_future = executor.submit(generate_audio_parler_tts, response)
|
332 |
-
# elif tts_choice == "Gamma":
|
333 |
-
# audio_future = executor.submit(generate_audio_mars5, response)
|
334 |
-
|
335 |
-
# for character in response:
|
336 |
-
# history[-1][1] += character
|
337 |
-
# time.sleep(0.05)
|
338 |
-
# yield history, None
|
339 |
-
|
340 |
-
# audio_path = audio_future.result()
|
341 |
-
# yield history, audio_path
|
342 |
|
343 |
def bot(history, choice, tts_choice):
|
344 |
if not history:
|
@@ -539,35 +518,6 @@ def show_map_if_details(history, choice):
|
|
539 |
else:
|
540 |
return gr.update(visible=False), ""
|
541 |
|
542 |
-
# def generate_audio_elevenlabs(text):
|
543 |
-
# XI_API_KEY = os.environ['ELEVENLABS_API']
|
544 |
-
# VOICE_ID = 'd9MIrwLnvDeH7aZb61E9'
|
545 |
-
# tts_url = f"https://api.elevenlabs.io/v1/text-to-speech/{VOICE_ID}/stream"
|
546 |
-
# headers = {
|
547 |
-
# "Accept": "application/json",
|
548 |
-
# "xi-api-key": XI_API_KEY
|
549 |
-
# }
|
550 |
-
# data = {
|
551 |
-
# "text": str(text),
|
552 |
-
# "model_id": "eleven_multilingual_v2",
|
553 |
-
# "voice_settings": {
|
554 |
-
# "stability": 1.0,
|
555 |
-
# "similarity_boost": 0.0,
|
556 |
-
# "style": 0.60,
|
557 |
-
# "use_speaker_boost": False
|
558 |
-
# }
|
559 |
-
# }
|
560 |
-
# response = requests.post(tts_url, headers=headers, json=data, stream=True)
|
561 |
-
# if response.ok:
|
562 |
-
# with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as f:
|
563 |
-
# for chunk in response.iter_content(chunk_size=1024):
|
564 |
-
# f.write(chunk)
|
565 |
-
# temp_audio_path = f.name
|
566 |
-
# logging.debug(f"Audio saved to {temp_audio_path}")
|
567 |
-
# return temp_audio_path
|
568 |
-
# else:
|
569 |
-
# logging.error(f"Error generating audio: {response.text}")
|
570 |
-
# return None
|
571 |
|
572 |
def generate_audio_elevenlabs(text):
|
573 |
XI_API_KEY = os.environ['ELEVENLABS_API']
|
@@ -764,135 +714,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_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 |
-
#
|
854 |
-
#
|
855 |
-
|
856 |
-
#
|
857 |
-
#
|
858 |
-
|
859 |
-
|
860 |
-
#
|
861 |
-
#
|
862 |
-
#
|
863 |
-
#
|
864 |
-
|
865 |
-
|
866 |
-
#
|
867 |
-
# )
|
868 |
-
|
869 |
-
#
|
870 |
-
#
|
871 |
-
|
872 |
-
#
|
873 |
-
#
|
874 |
-
#
|
875 |
-
#
|
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]
|
894 |
-
|
|
|
|
|
895 |
# demo.queue()
|
896 |
# demo.launch(share=True)
|
897 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
898 |
|
|
|
318 |
addresses = extract_addresses(response['output'])
|
319 |
return response['output'], addresses
|
320 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
321 |
|
322 |
def bot(history, choice, tts_choice):
|
323 |
if not history:
|
|
|
518 |
else:
|
519 |
return gr.update(visible=False), ""
|
520 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
521 |
|
522 |
def generate_audio_elevenlabs(text):
|
523 |
XI_API_KEY = os.environ['ELEVENLABS_API']
|
|
|
714 |
def clear_textbox():
|
715 |
return ""
|
716 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
717 |
# with gr.Blocks(theme='Pijush2023/scikit-learn-pijush') as demo:
|
718 |
# with gr.Row():
|
719 |
# with gr.Column():
|
720 |
# state = gr.State()
|
721 |
+
|
722 |
# chatbot = gr.Chatbot([], elem_id="RADAR:Channel 94.1", bubble_full_width=False)
|
723 |
# choice = gr.Radio(label="Select Style", choices=["Details", "Conversational"], value="Conversational")
|
724 |
+
|
725 |
# gr.Markdown("<h1 style='color: red;'>Talk to RADAR</h1>", elem_id="voice-markdown")
|
726 |
+
|
727 |
+
# chat_input = gr.Textbox(show_copy_button=True, interactive=True, show_label=False, label="ASK Radar !!!", placeholder="After Prompt, click Retriever Only")
|
728 |
+
# chat_msg = chat_input.submit(add_message, [chatbot, chat_input], [chatbot, chat_input], api_name="voice_query")
|
729 |
# tts_choice = gr.Radio(label="Select TTS System", choices=["Alpha", "Beta", "Gamma"], value="Alpha")
|
730 |
# retriever_button = gr.Button("Retriever")
|
731 |
+
|
|
|
|
|
|
|
732 |
# gr.Markdown("<h1 style='color: red;'>Radar Map</h1>", elem_id="Map-Radar")
|
733 |
# location_output = gr.HTML()
|
734 |
+
# retriever_button.click(fn=add_message, inputs=[chatbot, chat_input], outputs=[chatbot, chat_input]).then(
|
735 |
+
# fn=bot, inputs=[chatbot, choice, tts_choice, state], outputs=[chatbot, gr.Audio(interactive=False, autoplay=True)], api_name="Ask_Retriever").then(
|
736 |
+
# fn=show_map_if_details, inputs=[chatbot, choice], outputs=[location_output, location_output], api_name="map_finder").then(
|
737 |
+
# fn=clear_textbox,inputs=[],outputs=[chat_input]
|
738 |
+
# )
|
739 |
+
# # fn=clear_state_and_textbox, inputs=[], outputs=[chat_input]
|
740 |
|
741 |
+
# bot_msg = chat_msg.then(bot, [chatbot, choice, tts_choice], [chatbot], api_name="generate_voice_response")
|
742 |
+
# bot_msg.then(lambda: gr.Textbox(value="", interactive=True, placeholder="Ask Radar!!!...", show_label=False), None, [chat_input])
|
743 |
+
# chatbot.like(print_like_dislike, None, None)
|
744 |
+
# clear_button = gr.Button("Clear")
|
745 |
+
# clear_button.click(fn=clear_textbox, inputs=[], outputs=[chat_input])
|
746 |
+
|
747 |
+
# # New ASR Component with Whisper
|
748 |
+
# gr.Markdown("<h2>Hey Radar</h2>")
|
749 |
+
# audio_input_whisper = gr.Audio(sources=["microphone"], type='numpy')
|
750 |
+
# transcribe_button_whisper = gr.Button("Transcribe")
|
751 |
+
# transcribe_button_whisper.click(fn=transcribe_function_whisper, inputs=[audio_input_whisper], outputs=[chat_input], api_name="whisper_asr")
|
752 |
+
|
753 |
+
|
754 |
+
# # Streaming ASR component
|
755 |
+
# gr.Markdown("<h2>Streaming ASR</h2>")
|
756 |
+
# stream_audio_input = gr.Audio(sources=["microphone"], type='numpy', streaming=True)
|
757 |
+
# stream_transcription = gr.State(None) # Initialize stream state
|
758 |
+
# stream_audio_input.change(transcribe_function, inputs=[stream_transcription, stream_audio_input], outputs=[stream_transcription, chat_input],api_name="text_to_voice")
|
759 |
+
|
760 |
+
# # Add the clear button for ASR history
|
761 |
+
# clear_btn = gr.Button("Clear ASR ")
|
762 |
+
# # clear_btn.click(lambda: [None, ""], outputs=[stream_transcription, chat_input])
|
763 |
+
# clear_button.click(lambda:[None,None] ,outputs=[chat_input, state])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
764 |
|
765 |
+
# # with gr.Column():
|
766 |
+
# # weather_output = gr.HTML(value=fetch_local_weather())
|
767 |
+
# # news_output = gr.HTML(value=fetch_local_news())
|
768 |
+
# # news_output = gr.HTML(value=fetch_local_events())
|
769 |
+
|
770 |
# with gr.Column():
|
771 |
# image_output_1 = gr.Image(value=generate_image(hardcoded_prompt_1), width=400, height=400)
|
772 |
# image_output_2 = gr.Image(value=generate_image(hardcoded_prompt_2), width=400, height=400)
|
773 |
# image_output_3 = gr.Image(value=generate_image(hardcoded_prompt_3), width=400, height=400)
|
774 |
|
775 |
# refresh_button = gr.Button("Refresh Images")
|
776 |
+
# refresh_button.click(fn=update_images, inputs=None, outputs=[image_output_1, image_output_2, image_output_3])
|
777 |
+
# # location_output = gr.HTML()
|
778 |
+
# bot_msg.then(show_map_if_details, [chatbot, choice], [location_output, location_output], api_name="map_finder")
|
779 |
+
|
780 |
# demo.queue()
|
781 |
# demo.launch(share=True)
|
782 |
|
783 |
+
with gr.Blocks(theme='Pijush2023/scikit-learn-pijush') as demo:
|
784 |
+
with gr.Row():
|
785 |
+
with gr.Column():
|
786 |
+
state = gr.State()
|
787 |
+
|
788 |
+
chatbot = gr.Chatbot([], elem_id="RADAR:Channel 94.1", bubble_full_width=False)
|
789 |
+
choice = gr.Radio(label="Select Style", choices=["Details", "Conversational"], value="Conversational")
|
790 |
+
|
791 |
+
gr.Markdown("<h1 style='color: red;'>Talk to RADAR</h1>", elem_id="voice-markdown")
|
792 |
+
|
793 |
+
chat_input = gr.Textbox(show_copy_button=True, interactive=True, show_label=False, label="ASK Radar !!!", placeholder="After Prompt,click Retriever Only")
|
794 |
+
tts_choice = gr.Radio(label="Select TTS System", choices=["Alpha", "Beta", "Gamma"], value="Alpha")
|
795 |
+
retriever_button = gr.Button("Retriever")
|
796 |
+
|
797 |
+
clear_button = gr.Button("Clear")
|
798 |
+
clear_button.click(lambda:[None,None] ,outputs=[chat_input, state])
|
799 |
+
|
800 |
+
gr.Markdown("<h1 style='color: red;'>Radar Map</h1>", elem_id="Map-Radar")
|
801 |
+
location_output = gr.HTML()
|
802 |
+
|
803 |
+
# Define a single audio component
|
804 |
+
audio_output = gr.Audio(interactive=False, autoplay=True)
|
805 |
+
|
806 |
+
def stop_audio():
|
807 |
+
audio_output.stop()
|
808 |
+
return None
|
809 |
+
|
810 |
+
# Define the sequence of actions for the "Retriever" button
|
811 |
+
retriever_sequence = (
|
812 |
+
retriever_button.click(fn=stop_audio, inputs=[], outputs=[audio_output],api_name="Ask_Retriever")
|
813 |
+
.then(fn=add_message, inputs=[chatbot, chat_input], outputs=[chatbot, chat_input],api_name="voice_query")
|
814 |
+
.then(fn=bot, inputs=[chatbot, choice, tts_choice], outputs=[chatbot, audio_output],api_name="generate_voice_response" )
|
815 |
+
.then(fn=show_map_if_details, inputs=[chatbot, choice], outputs=[location_output, location_output], api_name="map_finder")
|
816 |
+
.then(fn=clear_textbox, inputs=[], outputs=[chat_input])
|
817 |
+
)
|
818 |
+
|
819 |
+
# Link the "Enter" key (submit event) to the same sequence of actions
|
820 |
+
chat_input.submit(fn=stop_audio, inputs=[], outputs=[audio_output])
|
821 |
+
chat_input.submit(fn=add_message, inputs=[chatbot, chat_input], outputs=[chatbot, chat_input],api_name="voice_query").then(
|
822 |
+
fn=bot, inputs=[chatbot, choice, tts_choice], outputs=[chatbot, audio_output], api_name="generate_voice_response"
|
823 |
+
).then(
|
824 |
+
fn=show_map_if_details, inputs=[chatbot, choice], outputs=[location_output, location_output], api_name="map_finder"
|
825 |
+
).then(
|
826 |
+
fn=clear_textbox, inputs=[], outputs=[chat_input]
|
827 |
+
)
|
828 |
+
|
829 |
+
audio_input = gr.Audio(sources=["microphone"], streaming=True, type='numpy', every=0.1)
|
830 |
+
audio_input.stream(transcribe_function, inputs=[state, audio_input], outputs=[state, chat_input], api_name="voice_query_to_text")
|
831 |
+
|
832 |
+
with gr.Column():
|
833 |
+
weather_output = gr.HTML(value=fetch_local_weather())
|
834 |
+
news_output = gr.HTML(value=fetch_local_news())
|
835 |
+
events_output = gr.HTML(value=fetch_local_events())
|
836 |
+
|
837 |
+
with gr.Column():
|
838 |
+
image_output_1 = gr.Image(value=generate_image(hardcoded_prompt_1), width=400, height=400)
|
839 |
+
image_output_2 = gr.Image(value=generate_image(hardcoded_prompt_2), width=400, height=400)
|
840 |
+
image_output_3 = gr.Image(value=generate_image(hardcoded_prompt_3), width=400, height=400)
|
841 |
+
|
842 |
+
refresh_button = gr.Button("Refresh Images")
|
843 |
+
refresh_button.click(fn=update_images, inputs=None, outputs=[image_output_1, image_output_2, image_output_3], api_name="update_image")
|
844 |
+
|
845 |
+
demo.queue()
|
846 |
+
demo.launch(share=True)
|
847 |
+
|
848 |
|