Download examples/loader.py from windjj/datumwell-embodiedtrace: direct link, hf CLI and curl.
- Browser
- Download file 1.26 kB
-
https://huggingface.co/datasets/windjj/datumwell-embodiedtrace/resolve/main/examples/loader.py
- Command line
-
hf download hf://datasets/windjj/datumwell-embodiedtrace/examples/loader.py
-
curl -L -o loader.py https://huggingface.co/datasets/windjj/datumwell-embodiedtrace/resolve/main/examples/loader.py
1.26 kB
| """Portable local EmbodiedTrace loader. Python standard library only.""" | |
| import json | |
| from pathlib import Path | |
| from zipfile import ZipFile | |
| SPLITS=('train','validation','test') | |
| def iter_decisions(root, split='train'): | |
| if split not in SPLITS:raise ValueError(f'split must be one of {SPLITS}') | |
| with (Path(root)/'data'/f'{split}.jsonl').open(encoding='utf-8') as source: | |
| for line in source: | |
| if line.strip():yield json.loads(line) | |
| def extract_media(root, kind='images'): | |
| if kind not in ('images','videos'):raise ValueError('kind must be images or videos') | |
| root=Path(root).resolve() | |
| with ZipFile(root/'media'/f'{kind}.zip') as archive: | |
| for name in archive.namelist(): | |
| target=(root/name).resolve() | |
| if not target.is_relative_to(root):raise ValueError('Unsafe archive path') | |
| archive.extractall(root) | |
| return root/kind | |
| if __name__=='__main__': | |
| import argparse | |
| parser=argparse.ArgumentParser();parser.add_argument('root');parser.add_argument('--split',default='train');args=parser.parse_args() | |
| row=next(iter_decisions(args.root,args.split));print(json.dumps({'episode':row['episode_id'],'subgoal':row['generated_annotation']['subgoal']['title'],'action':row['action']},indent=2)) | |