-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
122 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
browsergym/visualwebarena/src/browsergym/visualwebarena/utils.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import base64 | ||
import io | ||
import PIL.Image | ||
import requests | ||
|
||
|
||
def image_url_to_pil_image(image_url: str) -> str: | ||
if image_url.startswith("http"): | ||
image_data = requests.get(image_url, stream=True).raw | ||
elif image_url.startswith("data:image/png;base64,"): | ||
image_data = base64.b64decode(image_url.removeprefix("data:image/png;base64,")) | ||
elif image_url.startswith("data:image/jpeg;base64,"): | ||
image_data = base64.b64decode(image_url.removeprefix("data:image/jpeg;base64,")) | ||
else: | ||
if image_url.startswith("data:image/"): | ||
raise ValueError(f"Unexpected image encoding: {image_url}") | ||
else: | ||
raise ValueError(f"Unexpected image URL: {image_url}") | ||
img = PIL.Image.open(io.BytesIO(image_data)) | ||
return img |