Spaces:
Build error
Build error
Update Gradio_UI.py
Browse files- Gradio_UI.py +7 -13
Gradio_UI.py
CHANGED
|
@@ -194,22 +194,16 @@ def stream_to_gradio(
|
|
| 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":
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 211 |
)
|
| 212 |
-
|
| 213 |
else:
|
| 214 |
yield gr.ChatMessage(role="assistant", content=f"**Final answer:** {str(final_answer)}")
|
| 215 |
|
|
|
|
| 194 |
content={"path": final_answer.to_string(), "mime_type": "image/png"},
|
| 195 |
)
|
| 196 |
elif isinstance(final_answer, AgentAudio):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 197 |
yield gr.ChatMessage(
|
| 198 |
role="assistant",
|
| 199 |
+
content={"path": final_answer.to_string(), "mime_type": "audio/mpeg"},
|
| 200 |
+
)
|
| 201 |
+
elif isinstance(final_answer, str) and final_answer.strip().startswith("/tmp/"):
|
| 202 |
+
# Fallback: if the final answer is a string that is a file path, treat it as audio.
|
| 203 |
+
yield gr.ChatMessage(
|
| 204 |
+
role="assistant",
|
| 205 |
+
content={"path": final_answer.strip(), "mime_type": "audio/mpeg"},
|
| 206 |
)
|
|
|
|
| 207 |
else:
|
| 208 |
yield gr.ChatMessage(role="assistant", content=f"**Final answer:** {str(final_answer)}")
|
| 209 |
|