Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfixes #50

Merged
merged 2 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions core/src/browsergym/core/action/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ def get_elem_by_bid(
frame_bid = bid[:i] # bid of the next frame to select
frame_elem = current_frame.get_by_test_id(frame_bid)
if not frame_elem.count():
raise ValueError(f'could not find element with bid "{frame_bid}"')
raise ValueError(f'Could not find element with bid "{bid}"')
if scroll_into_view:
frame_elem.scroll_into_view_if_needed(timeout=500)
current_frame = frame_elem.frame_locator(":scope")

# finally, we should have selected the frame where the target element is
elem = current_frame.get_by_test_id(bid)
if not elem.count():
raise ValueError(f'Could not find element with bid "{bid}".')
raise ValueError(f'Could not find element with bid "{bid}"')
if scroll_into_view:
elem.scroll_into_view_if_needed(timeout=500)
return elem
Expand Down
25 changes: 17 additions & 8 deletions core/src/browsergym/utils/obs.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import ast
import logging
import numpy as np
import PIL.Image
import PIL.ImageDraw
Expand All @@ -12,6 +13,8 @@
from browsergym.core.constants import BROWSERGYM_VISIBILITY_ATTRIBUTE as VIS_ATTR
from browsergym.core.constants import BROWSERGYM_SETOFMARKS_ATTRIBUTE as SOM_ATTR

logger = logging.getLogger(__name__)

IGNORED_AXTREE_ROLES = ["LineBreak"]

IGNORED_AXTREE_PROPERTIES = (
Expand Down Expand Up @@ -460,16 +463,22 @@ def linedashed(draw: PIL.ImageDraw.Draw, x0, y0, x1, y1, fill, width, dashlen=4,
for bid, properties in extra_properties.items():
if properties["set_of_marks"] and properties["bbox"]:
x, y, width, height = properties["bbox"]
x0, y0 = x, y
x1, y1 = x + width, y + height

# skip small boxes
area = (x1 - x0) * (y1 - y0)
if area < 20:
logger.warning(
f'som overlay: skipping bid "{bid}" due to bbox too small (area={area})'
)
continue

# draw bounding box with dashed lines
linedashed(draw, x, y, x + width, y, fill=(0, 0, 0, 255), width=linewidth)
linedashed(
draw, x + width, y, x + width, y + height, fill=(0, 0, 0, 255), width=linewidth
)
linedashed(
draw, x, y + height, x + width, y + height, fill=(0, 0, 0, 255), width=linewidth
)
linedashed(draw, x, y, x, y + height, fill=(0, 0, 0, 255), width=linewidth)
linedashed(draw, x0, y0, x1, y0, fill=(0, 0, 0, 255), width=linewidth)
linedashed(draw, x1, y0, x1, y1, fill=(0, 0, 0, 255), width=linewidth)
linedashed(draw, x1, y1, x0, y1, fill=(0, 0, 0, 255), width=linewidth)
linedashed(draw, x0, y1, x0, y0, fill=(0, 0, 0, 255), width=linewidth)

# get text box size (left, top, right, bottom)
tag_box = font.getbbox(
Expand Down