Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -142,27 +142,16 @@ def bot(history, choice):
|
|
142 |
return history
|
143 |
response, addresses = generate_answer(history[-1][0], choice)
|
144 |
history[-1][1] = ""
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
|
|
|
|
|
|
150 |
|
151 |
-
audio_chunks = split_audio(temp_audio_path, len(response))
|
152 |
|
153 |
-
for idx, character in enumerate(response):
|
154 |
-
history[-1][1] += character
|
155 |
-
if idx < len(audio_chunks):
|
156 |
-
audio_segments.append(audio_chunks[idx])
|
157 |
-
yield history, audio_segments
|
158 |
-
|
159 |
-
def split_audio(audio_path, num_chunks):
|
160 |
-
from pydub import AudioSegment
|
161 |
-
audio = AudioSegment.from_file(audio_path)
|
162 |
-
chunk_length = len(audio) / num_chunks
|
163 |
-
chunks = [audio[i * chunk_length:(i + 1) * chunk_length] for i in range(num_chunks)]
|
164 |
-
return chunks
|
165 |
-
|
166 |
def add_message(history, message):
|
167 |
history.append((message, None))
|
168 |
return history, gr.Textbox(value="", interactive=True, placeholder="Enter message or upload file...", show_label=False)
|
@@ -622,7 +611,7 @@ with gr.Blocks(theme='rawrsor1/Everforest') as demo:
|
|
622 |
|
623 |
chat_input = gr.Textbox(show_copy_button=True, interactive=True, show_label=False, label="Transcription")
|
624 |
chat_msg = chat_input.submit(add_message, [chatbot, chat_input], [chatbot, chat_input])
|
625 |
-
bot_msg = chat_msg.then(bot, [chatbot, choice], chatbot,
|
626 |
bot_msg.then(lambda: gr.Textbox(value="", interactive=True, placeholder="Enter message or upload file...", show_label=False), None, [chat_input])
|
627 |
chatbot.like(print_like_dislike, None, None)
|
628 |
clear_button = gr.Button("Clear")
|
|
|
142 |
return history
|
143 |
response, addresses = generate_answer(history[-1][0], choice)
|
144 |
history[-1][1] = ""
|
145 |
+
|
146 |
+
# Generate audio for the entire response
|
147 |
+
audio_path = generate_audio_elevenlabs(response)
|
148 |
+
|
149 |
+
for character in response:
|
150 |
+
history[-1][1] += character
|
151 |
+
time.sleep(0.05) # Adjust the speed of text appearance
|
152 |
+
yield history, audio_path
|
153 |
|
|
|
154 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
155 |
def add_message(history, message):
|
156 |
history.append((message, None))
|
157 |
return history, gr.Textbox(value="", interactive=True, placeholder="Enter message or upload file...", show_label=False)
|
|
|
611 |
|
612 |
chat_input = gr.Textbox(show_copy_button=True, interactive=True, show_label=False, label="Transcription")
|
613 |
chat_msg = chat_input.submit(add_message, [chatbot, chat_input], [chatbot, chat_input])
|
614 |
+
bot_msg = chat_msg.then(bot, [chatbot, choice], [chatbot, gr.Audio()])
|
615 |
bot_msg.then(lambda: gr.Textbox(value="", interactive=True, placeholder="Enter message or upload file...", show_label=False), None, [chat_input])
|
616 |
chatbot.like(print_like_dislike, None, None)
|
617 |
clear_button = gr.Button("Clear")
|