Spaces:
Sleeping
Sleeping
Update Gradio_UI.py
Browse files- 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 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 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
|