File size: 3,145 Bytes
5ae877b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
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")