Datasets:
Download gui_longdep.py from M-Ma/GUI-LongDep: direct link, hf CLI and curl.
- Browser
- Download file 2.59 kB
-
https://huggingface.co/datasets/M-Ma/GUI-LongDep/resolve/main/gui_longdep.py
- Command line
-
hf download hf://datasets/M-Ma/GUI-LongDep/gui_longdep.py
-
curl -L -o gui_longdep.py https://huggingface.co/datasets/M-Ma/GUI-LongDep/resolve/main/gui_longdep.py
2.59 kB
| """Model-independent loader for GUI-LongDep. Standard library only. | |
| from gui_longdep import GUILongDep | |
| bench = GUILongDep(".") # folder of the downloaded dataset | |
| for sample in bench.samples: | |
| task = bench.task(sample) | |
| task["instruction"] # task instruction | |
| task["history"] # steps 0..t-1: {t, image, description, actions, code} | |
| task["screenshot"] # path of the screenshot at step t (to act on) | |
| # ... build your model's prompt, run it, convert its reply to pixel actions ... | |
| Every step of a trajectory stores the upstream action in three model-independent forms: | |
| description natural-language description of the action | |
| actions structured actions with pixel coordinates (schema: README.md) | |
| code the upstream action code as recorded (pyautogui; AgentNet uses 0..1 coordinates) | |
| Turn ``history`` into your model's own prompt format and score its predictions, converted | |
| to pixel actions, with ``score.py``. ``adapters/evocua`` is a complete example. | |
| """ | |
| from __future__ import annotations | |
| import json | |
| from pathlib import Path | |
| def read_jsonl(path: str | Path) -> list[dict]: | |
| with open(path, encoding="utf-8") as fh: | |
| return [json.loads(line) for line in fh if line.strip()] | |
| class GUILongDep: | |
| def __init__(self, root: str | Path = "."): | |
| self.root = Path(root) | |
| self.samples = read_jsonl(self.root / "data/test.jsonl") | |
| self.trajectories = {t["traj_id"]: t for t in read_jsonl(self.root / "data/trajectories.jsonl")} | |
| def steps(self, sample: dict) -> list[dict]: | |
| """Steps 0..t of the sample's trajectory (step t is the one to predict).""" | |
| traj = self.trajectories[sample["traj_id"]] | |
| t = int(sample["step"]) | |
| steps = traj["steps"][: t + 1] | |
| if [s["t"] for s in steps] != list(range(t + 1)): | |
| raise ValueError(f"{sample['sample_id']}: trajectory steps 0..{t} are incomplete") | |
| return steps | |
| def image_path(self, step: dict) -> Path: | |
| return self.root / step["image"] | |
| def task(self, sample: dict) -> dict: | |
| """What a model may see at the sample's step: instruction, steps 0..t-1, screenshot t.""" | |
| traj = self.trajectories[sample["traj_id"]] | |
| steps = self.steps(sample) | |
| return { | |
| "instruction": traj["instruction"], | |
| "width": traj["width"], | |
| "height": traj["height"], | |
| "history": steps[:-1], | |
| "screenshot": self.image_path(steps[-1]), | |
| } | |