forked from nottelabs/notte
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix merging-pipe only increasing bug (nottelabs#31)
- Loading branch information
1 parent
9246c97
commit 6f57367
Showing
17 changed files
with
349 additions
and
191 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
from dataclasses import dataclass | ||
from typing import Any | ||
|
||
from PIL import Image | ||
from typing_extensions import override | ||
|
||
from notte.actions.space import ActionSpace | ||
from notte.utils import image | ||
|
||
|
||
@dataclass | ||
class Observation: | ||
_url: str | ||
_space: ActionSpace | ||
_screenshot: bytes | None = None | ||
|
||
@property | ||
def url(self) -> str: | ||
return self._url | ||
|
||
@property | ||
def clean_url(self) -> str: | ||
# remove anything after ? i.. ?tfs=CBwQARooEgoyMDI0LTEyLTAzagwIAh | ||
return self.url.split("?")[0] | ||
|
||
@property | ||
def space(self) -> ActionSpace: | ||
return self._space | ||
|
||
@property | ||
def screenshot(self) -> bytes | None: | ||
return self._screenshot | ||
|
||
def display_screenshot(self) -> Image.Image | None: | ||
if self.screenshot is None: | ||
return None | ||
return image.image_from_bytes(self.screenshot) | ||
|
||
@staticmethod | ||
def from_json(json: dict[str, Any]) -> "Observation": | ||
url: str | None = json.get("url", None) | ||
if not isinstance(url, str): | ||
raise ValueError("url must be a string") | ||
screenshot: bytes | None = json.get("screenshot", None) | ||
space: ActionSpace | None = json.get("space", None) | ||
if not isinstance(space, dict): | ||
raise ValueError("space must be a dictionary") | ||
return Observation( | ||
_url=url, | ||
_screenshot=screenshot, | ||
_space=ActionSpace.from_json(space), | ||
) | ||
|
||
|
||
@dataclass | ||
class PreObservation(Observation): | ||
_space: ActionSpace | None = None # type: ignore | ||
|
||
@override | ||
@property | ||
def space(self) -> ActionSpace: | ||
raise ValueError("space is not available for pre-observations") |
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
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
Oops, something went wrong.