Spaces:
Sleeping
Sleeping
save_temp delete
Browse files- Gradio_UI.py +4 -20
Gradio_UI.py
CHANGED
|
@@ -126,20 +126,6 @@ def pull_messages_from_step(
|
|
| 126 |
yield gr.ChatMessage(role="assistant", content=f"{step_footnote}")
|
| 127 |
yield gr.ChatMessage(role="assistant", content="-----")
|
| 128 |
|
| 129 |
-
def save_agent_image_to_tmp(agent_image):
|
| 130 |
-
"""
|
| 131 |
-
Prend un AgentImage (smolagents), récupère l'image PIL
|
| 132 |
-
et la sauvegarde dans /tmp, puis renvoie le chemin.
|
| 133 |
-
"""
|
| 134 |
-
pil_img = agent_image.to_pil() # ou agent_image.image si l'attribut existe
|
| 135 |
-
|
| 136 |
-
ts = datetime.utcnow().strftime("%Y%m%d_%H%M%S")
|
| 137 |
-
filename = f"agent_image_{ts}.webp"
|
| 138 |
-
filepath = os.path.join("/tmp", filename)
|
| 139 |
-
|
| 140 |
-
pil_img.save(filepath, format="WEBP")
|
| 141 |
-
return filepath
|
| 142 |
-
|
| 143 |
|
| 144 |
def stream_to_gradio(
|
| 145 |
agent,
|
|
@@ -195,11 +181,9 @@ def stream_to_gradio(
|
|
| 195 |
# mais pour l’instant on laisse image_path = None.
|
| 196 |
|
| 197 |
elif isinstance(final_answer, AgentImage):
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
print("DEBUG AgentImage
|
| 201 |
-
# On convertit l'AgentImage en fichier sur disque
|
| 202 |
-
image_path = save_agent_image_to_tmp(final_answer)
|
| 203 |
|
| 204 |
final_message = gr.ChatMessage(
|
| 205 |
role="assistant",
|
|
@@ -207,7 +191,7 @@ def stream_to_gradio(
|
|
| 207 |
)
|
| 208 |
|
| 209 |
yield final_message, image_path
|
| 210 |
-
return
|
| 211 |
|
| 212 |
elif isinstance(final_answer, AgentAudio):
|
| 213 |
final_message = gr.ChatMessage(
|
|
|
|
| 126 |
yield gr.ChatMessage(role="assistant", content=f"{step_footnote}")
|
| 127 |
yield gr.ChatMessage(role="assistant", content="-----")
|
| 128 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 129 |
|
| 130 |
def stream_to_gradio(
|
| 131 |
agent,
|
|
|
|
| 181 |
# mais pour l’instant on laisse image_path = None.
|
| 182 |
|
| 183 |
elif isinstance(final_answer, AgentImage):
|
| 184 |
+
# to_string() renvoie déjà un chemin de fichier image
|
| 185 |
+
image_path = final_answer.to_string()
|
| 186 |
+
print("DEBUG AgentImage path used for gradio:", image_path)
|
|
|
|
|
|
|
| 187 |
|
| 188 |
final_message = gr.ChatMessage(
|
| 189 |
role="assistant",
|
|
|
|
| 191 |
)
|
| 192 |
|
| 193 |
yield final_message, image_path
|
| 194 |
+
return
|
| 195 |
|
| 196 |
elif isinstance(final_answer, AgentAudio):
|
| 197 |
final_message = gr.ChatMessage(
|