Fixed indentation
Browse files- Gradio_UI.py +33 -33
Gradio_UI.py
CHANGED
|
@@ -159,39 +159,39 @@ def stream_to_gradio(
|
|
| 159 |
yield message
|
| 160 |
|
| 161 |
# FIX: Process the final answer correctly after the loop
|
| 162 |
-
if final_answer_step:
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
|
| 196 |
|
| 197 |
class GradioUI:
|
|
|
|
| 159 |
yield message
|
| 160 |
|
| 161 |
# FIX: Process the final answer correctly after the loop
|
| 162 |
+
if final_answer_step:
|
| 163 |
+
# Extract the actual value from the FinalAnswerStep object
|
| 164 |
+
final_answer_value = getattr(final_answer_step, 'final_answer', final_answer_step)
|
| 165 |
+
|
| 166 |
+
# Check if the final answer is a string that looks like an image file path
|
| 167 |
+
if isinstance(final_answer_value, str) and final_answer_value.endswith(('.png', '.jpg', '.jpeg', '.gif', '.bmp', '.webp')):
|
| 168 |
+
# It's an image file path, create an AgentImage object
|
| 169 |
+
from smolagents.agent_types import AgentImage
|
| 170 |
+
processed_answer = AgentImage(value=final_answer_value)
|
| 171 |
+
else:
|
| 172 |
+
# Try the default conversion
|
| 173 |
+
processed_answer = handle_agent_output_types(final_answer_value)
|
| 174 |
+
|
| 175 |
+
if isinstance(processed_answer, AgentText):
|
| 176 |
+
yield gr.ChatMessage(
|
| 177 |
+
role="assistant",
|
| 178 |
+
content=f"**Final answer:**\n{processed_answer.to_string()}\n",
|
| 179 |
+
)
|
| 180 |
+
elif isinstance(processed_answer, AgentImage):
|
| 181 |
+
# For images, Gradio needs the file path directly
|
| 182 |
+
image_path = processed_answer.to_string()
|
| 183 |
+
yield gr.ChatMessage(
|
| 184 |
+
role="assistant",
|
| 185 |
+
content={"file": image_path, "alt_text": "Generated image"},
|
| 186 |
+
)
|
| 187 |
+
elif isinstance(processed_answer, AgentAudio):
|
| 188 |
+
yield gr.ChatMessage(
|
| 189 |
+
role="assistant",
|
| 190 |
+
content={"file": processed_answer.to_string(), "alt_text": "Generated audio"},
|
| 191 |
+
)
|
| 192 |
+
else:
|
| 193 |
+
# Fallback for any other type
|
| 194 |
+
yield gr.ChatMessage(role="assistant", content=f"**Final answer:** {str(processed_answer)}")
|
| 195 |
|
| 196 |
|
| 197 |
class GradioUI:
|