Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -107,11 +107,11 @@ def save_screenshot(memory_step: ActionStep, agent: CodeAgent) -> Image.Image:
|
|
107 |
image.save(screenshot_path)
|
108 |
logger.info(f"Saved screenshot to: {screenshot_path}")
|
109 |
# Update observations
|
110 |
-
url_info = f"Current url: {driver.current_url}"
|
111 |
memory_step.observations = (
|
112 |
url_info if memory_step.observations is None else memory_step.observations + "\n" + url_info
|
113 |
)
|
114 |
-
memory_step.observations_images =
|
115 |
return image
|
116 |
|
117 |
# Initialize model and agent
|
@@ -175,12 +175,17 @@ def run_agent_chat(user_input: str, history: list):
|
|
175 |
search_request = f"Please go to {url}. {request}"
|
176 |
agent_output = agent.run(search_request + helium_instructions)
|
177 |
|
178 |
-
# Collect the latest screenshot
|
179 |
latest_screenshot = None
|
180 |
for step in reversed(agent.memory.steps):
|
181 |
-
if isinstance(step, ActionStep) and step.
|
182 |
-
|
183 |
-
|
|
|
|
|
|
|
|
|
|
|
184 |
|
185 |
# Format output for chatbot
|
186 |
output = f"**Agent Output:**\n{agent_output}"
|
|
|
107 |
image.save(screenshot_path)
|
108 |
logger.info(f"Saved screenshot to: {screenshot_path}")
|
109 |
# Update observations
|
110 |
+
url_info = f"Current url: {driver.current_url}\nScreenshot saved at: {screenshot_path}"
|
111 |
memory_step.observations = (
|
112 |
url_info if memory_step.observations is None else memory_step.observations + "\n" + url_info
|
113 |
)
|
114 |
+
memory_step.observations_images = image
|
115 |
return image
|
116 |
|
117 |
# Initialize model and agent
|
|
|
175 |
search_request = f"Please go to {url}. {request}"
|
176 |
agent_output = agent.run(search_request + helium_instructions)
|
177 |
|
178 |
+
# Collect the latest screenshot path from observations
|
179 |
latest_screenshot = None
|
180 |
for step in reversed(agent.memory.steps):
|
181 |
+
if isinstance(step, ActionStep) and step.observations:
|
182 |
+
# Extract screenshot path from observations
|
183 |
+
for line in step.observations.split("\n"):
|
184 |
+
if line.startswith("Screenshot saved at:"):
|
185 |
+
latest_screenshot = line.replace("Screenshot saved at: ", "").strip()
|
186 |
+
break
|
187 |
+
if latest_screenshot:
|
188 |
+
break
|
189 |
|
190 |
# Format output for chatbot
|
191 |
output = f"**Agent Output:**\n{agent_output}"
|