gui_grounding_dataset-1k / generate_data.py
ArunKr's picture
Create generate_data.py
5ae877b verified
import json
import random
# Action templates
actions = [
{"instruction": "Open Google homepage.",
"actions": [{"action": "open_url", "value": "https://google.com"}]},
{"instruction": "Search Google for {query}.",
"actions": [{"action": "type", "target": "textarea[name=q]", "value": "{query}"}, {"action": "keypress", "options": {"key": "Enter"}}]},
{"instruction": "Click the {button} button.",
"actions": [{"action": "click", "target": "text={button}"}]},
{"instruction": "Type username {user}.",
"actions": [{"action": "type", "target": "input#username", "value": "{user}"}]},
{"instruction": "Type password {pwd}.",
"actions": [{"action": "type", "target": "input[type=password]", "value": "{pwd}"}]},
{"instruction": "Check the terms box.",
"actions": [{"action": "check", "target": "#terms"}]},
{"instruction": "Upload file {file}.",
"actions": [{"action": "upload", "target": "input[type=file]", "value": "{file}"}]},
{"instruction": "Take screenshot and save as {file}.",
"actions": [{"action": "screenshot", "value": "{file}"}]},
{"instruction": "Scroll {direction}.",
"actions": [{"action": "scroll", "options": {"count": 2, "direction": "{direction}"}}]},
{"instruction": "Accept popup.",
"actions": [{"action": "dialog", "value": "accept"}]},
]
# Variations
queries = ["AI", "Python tutorials", "machine learning", "Playwright automation", "GUI grounding"]
users = ["Arun", "Admin", "TestUser", "Alice", "Bob"]
passwords = ["secret123", "MyPass!", "qwerty", "letmein", "demo@123"]
files = ["resume.pdf", "report.docx", "image.png", "data.csv", "notes.txt"]
directions = ["down", "up"]
buttons = ["Login", "Submit", "Search", "Next", "Confirm"]
dataset = []
for i in range(1000):
template = random.choice(actions)
inst = template["instruction"].format(
query=random.choice(queries),
user=random.choice(users),
pwd=random.choice(passwords),
file=random.choice(files),
direction=random.choice(directions),
button=random.choice(buttons),
)
acts = json.loads(json.dumps(template["actions"])) # deep copy
for a in acts:
if "value" in a:
a["value"] = a["value"].format(
query=random.choice(queries),
user=random.choice(users),
pwd=random.choice(passwords),
file=random.choice(files),
direction=random.choice(directions),
button=random.choice(buttons),
)
if "target" in a and isinstance(a["target"], str):
a["target"] = a["target"].format(
query=random.choice(queries),
user=random.choice(users),
pwd=random.choice(passwords),
file=random.choice(files),
direction=random.choice(directions),
button=random.choice(buttons),
)
dataset.append({"instruction": inst, "actions": acts})
# Save JSONL
with open("gui_grounding_dataset.jsonl", "w") as f:
for row in dataset:
f.write(json.dumps(row) + "\n")