agarwalamit081 commited on
Commit
a2227b6
·
verified ·
1 Parent(s): c23f2b2

Update Gradio_UI.py

Browse files
Files changed (1) hide show
  1. Gradio_UI.py +16 -10
Gradio_UI.py CHANGED
@@ -137,17 +137,23 @@ def stream_to_gradio(
137
  final = handle_agent_output_types(step_log)
138
  if isinstance(final, AgentText):
139
  content = final.to_string()
140
- yield gr.ChatMessage(
141
- role="assistant",
142
- content=content,
143
- metadata={"react": True, "status": "done"}
144
- )
145
  else:
146
- yield gr.ChatMessage(
147
- role="assistant",
148
- content=f"**Final Answer:** {str(final)}",
149
- metadata={"status": "done"}
150
- )
 
 
 
 
 
 
 
 
 
 
 
151
 
152
  except Exception as e:
153
  # Handle errors gracefully
 
137
  final = handle_agent_output_types(step_log)
138
  if isinstance(final, AgentText):
139
  content = final.to_string()
 
 
 
 
 
140
  else:
141
+ # Extract the actual content from the final answer
142
+ content = str(final)
143
+ # Remove the wrapper if it exists (e.g., "FinalAnswerStep(final_answer='...')")
144
+ if "final_answer=" in content:
145
+ import re
146
+ match = re.search(r"final_answer=['\"](.+)['\"]", content, re.DOTALL)
147
+ if match:
148
+ content = match.group(1)
149
+ # Unescape newlines and other escape sequences
150
+ content = content.encode().decode('unicode_escape')
151
+
152
+ yield gr.ChatMessage(
153
+ role="assistant",
154
+ content=content,
155
+ metadata={"status": "done"}
156
+ )
157
 
158
  except Exception as e:
159
  # Handle errors gracefully