Spaces:
Build error
Build error
Update Gradio_UI.py
Browse files- Gradio_UI.py +13 -8
Gradio_UI.py
CHANGED
|
@@ -194,16 +194,21 @@ def stream_to_gradio(
|
|
| 194 |
content={"path": final_answer.to_string(), "mime_type": "image/png"},
|
| 195 |
)
|
| 196 |
elif isinstance(final_answer, AgentAudio):
|
| 197 |
-
#
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 202 |
yield gr.ChatMessage(
|
| 203 |
role="assistant",
|
| 204 |
-
content={"path":
|
| 205 |
)
|
| 206 |
-
print("DEBUG AgentAudio attributes:", vars(final_answer))
|
| 207 |
|
| 208 |
else:
|
| 209 |
yield gr.ChatMessage(role="assistant", content=f"**Final answer:** {str(final_answer)}")
|
|
@@ -353,7 +358,7 @@ class GradioUI:
|
|
| 353 |
)
|
| 354 |
|
| 355 |
# NEW: Add a dedicated audio player component below the chatbot.
|
| 356 |
-
audio_player = gr.Audio(label="Audio Pronunciation", type="
|
| 357 |
|
| 358 |
if self.file_upload_folder is not None:
|
| 359 |
upload_file = gr.File(label="Upload a file")
|
|
|
|
| 194 |
content={"path": final_answer.to_string(), "mime_type": "image/png"},
|
| 195 |
)
|
| 196 |
elif isinstance(final_answer, AgentAudio):
|
| 197 |
+
# Get the file path from the AgentAudio object (assuming it returns a string path)
|
| 198 |
+
local_path = final_answer.to_string() # e.g. "/tmp/response.mp3"
|
| 199 |
+
|
| 200 |
+
# Define a public folder to serve audio files
|
| 201 |
+
public_folder = "public_audio"
|
| 202 |
+
os.makedirs(public_folder, exist_ok=True)
|
| 203 |
+
|
| 204 |
+
# Copy the file from /tmp to the public folder
|
| 205 |
+
public_path = os.path.join(public_folder, os.path.basename(local_path))
|
| 206 |
+
shutil.copy(local_path, public_path)
|
| 207 |
+
|
| 208 |
yield gr.ChatMessage(
|
| 209 |
role="assistant",
|
| 210 |
+
content={"path": public_path, "mime_type": "audio/mpeg"},
|
| 211 |
)
|
|
|
|
| 212 |
|
| 213 |
else:
|
| 214 |
yield gr.ChatMessage(role="assistant", content=f"**Final answer:** {str(final_answer)}")
|
|
|
|
| 358 |
)
|
| 359 |
|
| 360 |
# NEW: Add a dedicated audio player component below the chatbot.
|
| 361 |
+
audio_player = gr.Audio(label="Audio Pronunciation", type="filepath")
|
| 362 |
|
| 363 |
if self.file_upload_folder is not None:
|
| 364 |
upload_file = gr.File(label="Upload a file")
|