Firoj112 commited on
Commit
1af9db9
·
verified ·
1 Parent(s): 80e17c9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -6
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 = screenshot_path
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.observations_images:
182
- latest_screenshot = step.observations_images
183
- break
 
 
 
 
 
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}"