Spaces:
Build error
Build error
Update Gradio_UI.py
Browse files- Gradio_UI.py +6 -3
Gradio_UI.py
CHANGED
|
@@ -187,7 +187,8 @@ def stream_to_gradio(
|
|
| 187 |
elif isinstance(final_answer, AgentAudio):
|
| 188 |
yield gr.ChatMessage(
|
| 189 |
role="assistant",
|
| 190 |
-
content={"path": final_answer.to_string(), "mime_type": "audio/mpeg"},
|
|
|
|
| 191 |
)
|
| 192 |
else:
|
| 193 |
yield gr.ChatMessage(role="assistant", content=f"**Final answer:** {str(final_answer)}")
|
|
@@ -297,6 +298,8 @@ class GradioUI:
|
|
| 297 |
def launch(self, **kwargs):
|
| 298 |
import gradio as gr
|
| 299 |
|
|
|
|
|
|
|
| 300 |
# NEW: Add a helper function to extract audio file path from stored messages
|
| 301 |
def extract_audio(messages):
|
| 302 |
# Iterate backwards over messages until we find one with audio content.
|
|
@@ -310,7 +313,7 @@ class GradioUI:
|
|
| 310 |
if isinstance(msg.content, dict):
|
| 311 |
mime = msg.content.get("mime_type", "")
|
| 312 |
if mime.startswith("audio"):
|
| 313 |
-
return msg.content.get("
|
| 314 |
return None
|
| 315 |
|
| 316 |
with gr.Blocks(fill_height=True) as demo:
|
|
@@ -328,7 +331,7 @@ class GradioUI:
|
|
| 328 |
)
|
| 329 |
|
| 330 |
# NEW: Add a dedicated audio player component below the chatbot.
|
| 331 |
-
audio_player = gr.Audio(label="Audio Pronunciation", type="
|
| 332 |
|
| 333 |
if self.file_upload_folder is not None:
|
| 334 |
upload_file = gr.File(label="Upload a file")
|
|
|
|
| 187 |
elif isinstance(final_answer, AgentAudio):
|
| 188 |
yield gr.ChatMessage(
|
| 189 |
role="assistant",
|
| 190 |
+
#content={"path": final_answer.to_string(), "mime_type": "audio/mpeg"},
|
| 191 |
+
content={"data": final_answer.value, "mime_type": "audio/mpeg"},
|
| 192 |
)
|
| 193 |
else:
|
| 194 |
yield gr.ChatMessage(role="assistant", content=f"**Final answer:** {str(final_answer)}")
|
|
|
|
| 298 |
def launch(self, **kwargs):
|
| 299 |
import gradio as gr
|
| 300 |
|
| 301 |
+
|
| 302 |
+
|
| 303 |
# NEW: Add a helper function to extract audio file path from stored messages
|
| 304 |
def extract_audio(messages):
|
| 305 |
# Iterate backwards over messages until we find one with audio content.
|
|
|
|
| 313 |
if isinstance(msg.content, dict):
|
| 314 |
mime = msg.content.get("mime_type", "")
|
| 315 |
if mime.startswith("audio"):
|
| 316 |
+
return msg.content.get("data")
|
| 317 |
return None
|
| 318 |
|
| 319 |
with gr.Blocks(fill_height=True) as demo:
|
|
|
|
| 331 |
)
|
| 332 |
|
| 333 |
# NEW: Add a dedicated audio player component below the chatbot.
|
| 334 |
+
audio_player = gr.Audio(label="Audio Pronunciation", type="bytes")
|
| 335 |
|
| 336 |
if self.file_upload_folder is not None:
|
| 337 |
upload_file = gr.File(label="Upload a file")
|