Spaces:
Sleeping
Sleeping
Update Gradio_UI.py
Browse files- Gradio_UI.py +16 -1
Gradio_UI.py
CHANGED
|
@@ -162,9 +162,24 @@ def stream_to_gradio(
|
|
| 162 |
content=f"**Final answer:**\n{final_answer.to_string()}\n",
|
| 163 |
)
|
| 164 |
elif isinstance(final_answer, AgentImage):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 165 |
yield gr.ChatMessage(
|
| 166 |
role="assistant",
|
| 167 |
-
content={"path":
|
| 168 |
)
|
| 169 |
elif isinstance(final_answer, AgentAudio):
|
| 170 |
yield gr.ChatMessage(
|
|
|
|
| 162 |
content=f"**Final answer:**\n{final_answer.to_string()}\n",
|
| 163 |
)
|
| 164 |
elif isinstance(final_answer, AgentImage):
|
| 165 |
+
img_path = final_answer.to_string()
|
| 166 |
+
|
| 167 |
+
# If the returned string isn't a valid file path, save the image ourselves
|
| 168 |
+
if not isinstance(img_path, str) or not os.path.exists(img_path):
|
| 169 |
+
os.makedirs("generated_images", exist_ok=True)
|
| 170 |
+
img_path = os.path.join("generated_images", "generated_image.png")
|
| 171 |
+
|
| 172 |
+
# Try to save AgentImage.value (usually PIL image)
|
| 173 |
+
try:
|
| 174 |
+
final_answer.value.save(img_path)
|
| 175 |
+
except Exception:
|
| 176 |
+
# Fallback for raw bytes
|
| 177 |
+
with open(img_path, "wb") as f:
|
| 178 |
+
f.write(final_answer.value)
|
| 179 |
+
|
| 180 |
yield gr.ChatMessage(
|
| 181 |
role="assistant",
|
| 182 |
+
content={"path": img_path, "mime_type": "image/png"},
|
| 183 |
)
|
| 184 |
elif isinstance(final_answer, AgentAudio):
|
| 185 |
yield gr.ChatMessage(
|