jcleee commited on
Commit
d6fece8
·
verified ·
1 Parent(s): 0ae5f1c

Update Gradio_UI.py

Browse files
Files changed (1) hide show
  1. 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 # last step returned by agent.run()
157
- final_output = None
158
-
159
- if hasattr(final_step, "tool_calls"):
 
 
 
 
 
 
160
  for call in final_step.tool_calls:
161
  if call.name == "final_answer":
162
- # Prefer the actual output if available, fallback to arguments
163
- final_output = call.output if call.output is not None else call.arguments.get("answer")
 
 
 
 
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)