Spaces:
Sleeping
Sleeping
Update Gradio_UI.py
Browse files- Gradio_UI.py +37 -6
Gradio_UI.py
CHANGED
|
@@ -153,16 +153,47 @@ def stream_to_gradio(
|
|
| 153 |
):
|
| 154 |
yield message
|
| 155 |
|
| 156 |
-
final_step = step_log #
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 160 |
for call in final_step.tool_calls:
|
| 161 |
if call.name == "final_answer":
|
| 162 |
-
|
| 163 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 164 |
break
|
| 165 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 166 |
|
| 167 |
|
| 168 |
final_output = handle_agent_output_types(final_output)
|
|
|
|
| 153 |
):
|
| 154 |
yield message
|
| 155 |
|
| 156 |
+
final_step = step_log # Final ActionStep
|
| 157 |
+
|
| 158 |
+
# Debugging tool calls to inspect final_answer structure
|
| 159 |
+
print("DEBUG TOOL CALLS:", final_step.tool_calls)
|
| 160 |
+
|
| 161 |
+
# Attempt to get the direct tool_output
|
| 162 |
+
final_output = getattr(final_step, "tool_output", None)
|
| 163 |
+
|
| 164 |
+
# Fallback if tool_output is missing
|
| 165 |
+
if not final_output and getattr(final_step, "tool_calls", None):
|
| 166 |
for call in final_step.tool_calls:
|
| 167 |
if call.name == "final_answer":
|
| 168 |
+
print("DEBUG FINAL ANSWER TOOL CALL:", call)
|
| 169 |
+
# Try the `output` field if present (some agents set this explicitly)
|
| 170 |
+
final_output = getattr(call, "output", None)
|
| 171 |
+
if final_output is None:
|
| 172 |
+
# Fallback to arguments dict
|
| 173 |
+
final_output = call.arguments.get("answer")
|
| 174 |
break
|
| 175 |
|
| 176 |
+
final_output = handle_agent_output_types(final_output)
|
| 177 |
+
|
| 178 |
+
if isinstance(final_output, AgentText):
|
| 179 |
+
yield gr.ChatMessage(
|
| 180 |
+
role="assistant",
|
| 181 |
+
content=final_output.to_string().strip(),
|
| 182 |
+
)
|
| 183 |
+
elif isinstance(final_output, AgentImage):
|
| 184 |
+
yield gr.ChatMessage(
|
| 185 |
+
role="assistant",
|
| 186 |
+
content={"path": final_output.to_string(), "mime_type": "image/png"},
|
| 187 |
+
)
|
| 188 |
+
elif isinstance(final_output, AgentAudio):
|
| 189 |
+
yield gr.ChatMessage(
|
| 190 |
+
role="assistant",
|
| 191 |
+
content={"path": final_output.to_string(), "mime_type": "audio/wav"},
|
| 192 |
+
)
|
| 193 |
+
else:
|
| 194 |
+
yield gr.ChatMessage(role="assistant", content=str(final_output).strip())
|
| 195 |
+
|
| 196 |
+
|
| 197 |
|
| 198 |
|
| 199 |
final_output = handle_agent_output_types(final_output)
|