Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -307,6 +307,22 @@ def add_message(history, message):
|
|
| 307 |
history.append((message, None))
|
| 308 |
return history, gr.Textbox(value="", interactive=True, placeholder="Enter message or upload file...", show_label=False)
|
| 309 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 310 |
def print_like_dislike(x: gr.LikeData):
|
| 311 |
print(x.index, x.value, x.liked)
|
| 312 |
|
|
@@ -654,6 +670,9 @@ with gr.Blocks(theme='Pijush2023/scikit-learn-pijush') as demo:
|
|
| 654 |
retriver_button.click(fn=add_message, inputs=[chatbot, chat_input], outputs=[chatbot, chat_input]).then(
|
| 655 |
fn=bot, inputs=[chatbot, choice, tts_choice], outputs=[chatbot, gr.Audio(interactive=False, autoplay=True)],api_name="Ask_Retriever")
|
| 656 |
|
|
|
|
|
|
|
|
|
|
| 657 |
bot_msg = chat_msg.then(bot, [chatbot, choice, tts_choice], [chatbot, gr.Audio(interactive=False, autoplay=True)])
|
| 658 |
bot_msg.then(lambda: gr.Textbox(value="", interactive=True, placeholder="Ask Radar!!!...", show_label=False), None, [chat_input])
|
| 659 |
chatbot.like(print_like_dislike, None, None)
|
|
|
|
| 307 |
history.append((message, None))
|
| 308 |
return history, gr.Textbox(value="", interactive=True, placeholder="Enter message or upload file...", show_label=False)
|
| 309 |
|
| 310 |
+
def generate_voice_response(history, tts_choice):
|
| 311 |
+
if not history:
|
| 312 |
+
return None
|
| 313 |
+
|
| 314 |
+
response = history[-1][1]
|
| 315 |
+
with concurrent.futures.ThreadPoolExecutor() as executor:
|
| 316 |
+
if tts_choice == "Eleven Labs":
|
| 317 |
+
audio_future = executor.submit(generate_audio_elevenlabs, response)
|
| 318 |
+
elif tts_choice == "Parler-TTS":
|
| 319 |
+
audio_future = executor.submit(generate_audio_parler_tts, response)
|
| 320 |
+
elif tts_choice == "MARS5":
|
| 321 |
+
audio_future = executor.submit(generate_audio_mars5, response)
|
| 322 |
+
|
| 323 |
+
audio_path = audio_future.result()
|
| 324 |
+
return audio_path
|
| 325 |
+
|
| 326 |
def print_like_dislike(x: gr.LikeData):
|
| 327 |
print(x.index, x.value, x.liked)
|
| 328 |
|
|
|
|
| 670 |
retriver_button.click(fn=add_message, inputs=[chatbot, chat_input], outputs=[chatbot, chat_input]).then(
|
| 671 |
fn=bot, inputs=[chatbot, choice, tts_choice], outputs=[chatbot, gr.Audio(interactive=False, autoplay=True)],api_name="Ask_Retriever")
|
| 672 |
|
| 673 |
+
voice_response_button = gr.Button("Voice Response")
|
| 674 |
+
voice_response_button.click(fn=generate_voice_response, inputs=[chatbot, tts_choice], outputs=[gr.Audio(interactive=False, autoplay=True)])
|
| 675 |
+
|
| 676 |
bot_msg = chat_msg.then(bot, [chatbot, choice, tts_choice], [chatbot, gr.Audio(interactive=False, autoplay=True)])
|
| 677 |
bot_msg.then(lambda: gr.Textbox(value="", interactive=True, placeholder="Ask Radar!!!...", show_label=False), None, [chat_input])
|
| 678 |
chatbot.like(print_like_dislike, None, None)
|