nmr-workbench-large-v2 / load_example.py
priyanshu-harshbodhi's picture
Upload verified synthetic NMR dataset and evidence (part 3)
c4d5de9 verified
Raw History Blame Contribute Delete
1.37 kB
"""Offline loader and model-neutral conversation adapter; no model download."""
import json
from pathlib import Path
from datasets import load_dataset
def to_messages(row):
instructions = ('Operate NMRium from the screenshot. Output one JSON action. '
'Allowed types: click, drag, scroll, key, text, wait, finish. '
'Coordinates are viewport pixels, width 1440, height 1000, scale 1. '
'click: x,y,optional button; drag: from/to x,y and steps; '
'scroll: x,y,delta_x,delta_y; key: key; text: text; wait: ms; '
'finish has no arguments. The keyboard platform is macOS.')
prompt = row['instruction'] + '\nPrevious actions: ' + row['previous_actions_json']
return [
{'role':'system','content':instructions},
{'role':'user','content':[{'type':'image','image':row['image']},{'type':'text','text':prompt}]},
{'role':'assistant','content':row['action_json']},
]
if __name__ == '__main__':
root=Path(__file__).resolve().parent
data=load_dataset('parquet',data_files={'development':str(root/'data/sft-*.parquet')},split='development')
for row in data:
assert row['image'].size==(1440,1000)
assert isinstance(json.loads(row['action_json']),dict)
to_messages(row)
print(f'Loaded and decoded all {len(data)} SFT images; conversation conversion passed.')