luyuheng commited on
Commit
5fbc91c
·
verified ·
1 Parent(s): 197613f

Upload 2 files (#1)

Browse files

- Upload 2 files (9517be391e6f4312d2b708c2be54113fb988023c)

Files changed (2) hide show
  1. TGB.zip +3 -0
  2. transferability_gui_benchmark.py +328 -0
TGB.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1cf6fea8d38182eb8d17808eb43108993f104bc1498ebc625f0dd95d940bb440
3
+ size 1380615293
transferability_gui_benchmark.py ADDED
@@ -0,0 +1,328 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ # TODO: Address all TODOs and remove all explanatory comments
15
+ """TODO: Add a description here."""
16
+ import base64
17
+ import csv
18
+ import io
19
+ import json
20
+ import os
21
+ from uu import encode
22
+
23
+ import openpyxl
24
+ import datasets
25
+ from PIL import Image
26
+
27
+ _CITATION = """\
28
+ @InProceedings{huggingface:dataset,
29
+ title = {TransBench: Breaking Barriers for Transferable Graphical User Interface Agents in Dynamic Digital Environments},
30
+ author={Lu, Yuheng and Yu, Qian and Wang, Hongru and Liu, Zeming and Su, Wei and Liu, Yanping and Guo, Yuhang and Liang, Maocheng and Wang, Yunhong and Wang, Haifeng},
31
+ booktitle={Findings of the Association for Computational Linguistics: ACL 2025},
32
+ year={2025}
33
+ }
34
+ """
35
+
36
+ _DESCRIPTION = """\
37
+ This dataset is the supplementary dataset for the paper, generated by an automated pipeline with additional manual quality control.
38
+ """
39
+
40
+ # TODO: Add a link to an official homepage for the dataset here
41
+ _HOMEPAGE = "https://github.com/BUAA-IRIP-LLM/TransBench"
42
+
43
+ # TODO: Add the licence for the dataset here if you can find it
44
+ _LICENSE = ""
45
+
46
+ # TODO: Add link to the official dataset URLs here
47
+ # The HuggingFace Datasets library doesn't host the datasets but only points to the original files.
48
+ # This can be an arbitrary nested dict/list of URLs (see below in `_split_generators` method)
49
+ _URLS = {
50
+ "first_domain": "https://huggingface.co/great-new-dataset-first_domain.zip",
51
+ "second_domain": "https://huggingface.co/great-new-dataset-second_domain.zip",
52
+ }
53
+
54
+
55
+ # TODO: Name of the dataset usually matches the script name with CamelCase instead of snake_case
56
+ class TransferabilityGuiBenchmark(datasets.GeneratorBasedBuilder):
57
+ """This dataset is the supplementary dataset for the paper, generated by an automated pipeline with additional manual quality control.
58
+ It is worth noting that due to the use of an automated annotation pipeline to generate tasks, there may be a few errors. Direct use for training that is sensitive to data quality may lead to abnormal phenomena.
59
+ """
60
+
61
+ VERSION = datasets.Version("1.0.0")
62
+
63
+ # This is an example of a dataset with multiple configurations.
64
+ # If you don't want/need to define several sub-sets in your dataset,
65
+ # just remove the BUILDER_CONFIG_CLASS and the BUILDER_CONFIGS attributes.
66
+
67
+ # If you need to make complex sub-parts in the datasets with configurable options
68
+ # You can create your own builder configuration class to store attribute, inheriting from datasets.BuilderConfig
69
+ # BUILDER_CONFIG_CLASS = MyBuilderConfig
70
+
71
+ # You will be able to load one or the other configurations in the following list with
72
+ # data = datasets.load_dataset('my_dataset', 'first_domain')
73
+ # data = datasets.load_dataset('my_dataset', 'second_domain')
74
+ BUILDER_CONFIGS = [
75
+ datasets.BuilderConfig(name="all", version=VERSION, description="all datapoint of this dataset"),
76
+ datasets.BuilderConfig(name="android_low", version=VERSION,
77
+ description="use android_low_version to train model"),
78
+ datasets.BuilderConfig(name="ios", version=VERSION,
79
+ description="use ios to train model"),
80
+ datasets.BuilderConfig(name="web", version=VERSION,
81
+ description="use ios to train model"),
82
+ datasets.BuilderConfig(name="normal", version=VERSION,
83
+ description="use ramdom 5000 data split to train model"),
84
+ datasets.BuilderConfig(name="app", version=VERSION,
85
+ description="use 2/5 apps in top7 app-type to train model"),
86
+ ]
87
+
88
+ DEFAULT_CONFIG_NAME = "all" # It's not mandatory to have a default configuration. Just use one if it make sense.
89
+
90
+ def _info(self):
91
+ # TODO: This method specifies the datasets.DatasetInfo object which contains informations and typings for the dataset
92
+ # "grounding_instruction", "target_bbox", "screenshot_filename", "platform_type", "app_name", "page_name", "app_version", "app_type"
93
+ # if self.config.name == "all": # This is the name of the configuration selected in BUILDER_CONFIGS above
94
+ # features = datasets.Features(
95
+ # {
96
+ # "grounding_instruction": datasets.Value("string"),
97
+ # "target_bbox": datasets.Array2D(shape=(1, 4), dtype="float32"),
98
+ # "app_type": datasets.Value("string"),
99
+ # "screenshot_png_base64": datasets.Value("string"),
100
+ # "screenshot_path": datasets.Value("string"),
101
+ # "platform_type": datasets.Value("string"),
102
+ # "app_name": datasets.Value("string"),
103
+ # "page_name": datasets.Value("string"),
104
+ # "app_version": datasets.Value("string")
105
+ # # These are the features of your dataset like images, labels ...
106
+ # }
107
+ # )
108
+ # else: # This is an example to show how to have different features for "first_domain" and "second_domain"
109
+ # features = datasets.Features(
110
+ # {
111
+ # "sentence": datasets.Value("string"),
112
+ # "option2": datasets.Value("string"),
113
+ # "second_domain_answer": datasets.Value("string")
114
+ # # These are the features of your dataset like images, labels ...
115
+ # }
116
+ # )
117
+ features = datasets.Features(
118
+ {
119
+ "grounding_instruction": datasets.Value("string"),
120
+ "target_bbox": datasets.Array2D(shape=(1, 4), dtype="float32"),
121
+ "app_type": datasets.Value("string"),
122
+ "screenshot_png_base64": datasets.Value("string"),
123
+ "screenshot_path": datasets.Value("string"),
124
+ "platform_type": datasets.Value("string"),
125
+ "app_name": datasets.Value("string"),
126
+ "page_name": datasets.Value("string"),
127
+ "app_version": datasets.Value("string"),
128
+ "app_version_type" : datasets.Value("string"),
129
+ # These are the features of your dataset like images, labels ...
130
+ }
131
+ )
132
+ return datasets.DatasetInfo(
133
+ # This is the description that will appear on the datasets page.
134
+ description=_DESCRIPTION,
135
+ # This defines the different columns of the dataset and their types
136
+ features=features, # Here we define them above because they are different between the two configurations
137
+ # If there's a common (input, target) tuple from the features, uncomment supervised_keys line below and
138
+ # specify them. They'll be used if as_supervised=True in builder.as_dataset.
139
+ # supervised_keys=("sentence", "label"),
140
+ # Homepage of the dataset for documentation
141
+ homepage=_HOMEPAGE,
142
+ # License for the dataset if available
143
+ license=_LICENSE,
144
+ # Citation for the dataset
145
+ citation=_CITATION,
146
+ )
147
+
148
+ def __check_all_screenshots_exists(self, rootpath: str):
149
+ with open(os.path.join(rootpath, "processed_grounding_data.json"), 'r', encoding='utf-8') as f:
150
+ data = json.load(f)
151
+ for case in data:
152
+ if not os.path.exists(
153
+ os.path.join(rootpath,
154
+ os.path.join("screenshots",
155
+ os.path.join(str(case['platform_type']),
156
+ case['screenshot_filename'])
157
+ )
158
+ )
159
+ ):
160
+ raise Exception(f"{case['screenshot_filename']} is not exist")
161
+
162
+ def _split_generators(self, dl_manager):
163
+ # TODO: This method is tasked with downloading/extracting the data and defining the splits depending on the configuration
164
+ # If several configurations are possible (listed in BUILDER_CONFIGS), the configuration selected by the user is in self.config.name
165
+
166
+ # dl_manager is a datasets.download.DownloadManager that can be used to download and extract URLS
167
+ # It can accept any type or nested list/dict and will give back the same structure with the url replaced with path to local files.
168
+ # By default the archives will be extracted and a path to a cached folder where they are extracted is returned instead of the archive
169
+ # urls = _URLS[self.config.name]
170
+ # data_dir = dl_manager.download_and_extract(urls)
171
+ url = "TGB.zip"
172
+ data_dir = dl_manager.download_and_extract(url)
173
+
174
+ self.__check_all_screenshots_exists(data_dir)
175
+
176
+ return [
177
+ datasets.SplitGenerator(
178
+ name=datasets.Split.TRAIN,
179
+ # These kwargs will be passed to _generate_examples
180
+ gen_kwargs={
181
+ 'data_dir': data_dir,
182
+ "screenshots_path": os.path.join(data_dir, "screenshots"),
183
+ "json_path": os.path.join(data_dir, "processed_grounding_data.json"),
184
+ "split": "train",
185
+ "appinfo": os.path.join(data_dir, "appinfo.xlsx")
186
+ },
187
+ ),
188
+ datasets.SplitGenerator(
189
+ name=datasets.Split.VALIDATION,
190
+ # These kwargs will be passed to _generate_examples
191
+ gen_kwargs={
192
+ 'data_dir': data_dir,
193
+ "screenshots_path": os.path.join(data_dir, "screenshots"),
194
+ "json_path": os.path.join(data_dir, "processed_grounding_data.json"),
195
+ "split": "valid",
196
+ "appinfo": os.path.join(data_dir, "appinfo.xlsx")
197
+ },
198
+ ),
199
+ datasets.SplitGenerator(
200
+ name=datasets.Split.TEST,
201
+ # These kwargs will be passed to _generate_examples
202
+ gen_kwargs={
203
+ 'data_dir': data_dir,
204
+ "screenshots_path": os.path.join(data_dir, "screenshots"),
205
+ "json_path": os.path.join(data_dir, "processed_grounding_data.json"),
206
+ "split": "test",
207
+ "appinfo": os.path.join(data_dir, "appinfo.xlsx")
208
+ },
209
+ ),
210
+ ]
211
+
212
+ def get_app_version_dict(self, datas):
213
+ app_to_versions = {}
214
+ for case in datas:
215
+ appname = case['app_name']
216
+ if appname not in app_to_versions:
217
+ app_to_versions[appname] = set([])
218
+ app_to_versions[appname].add(case['app_version'])
219
+ return app_to_versions
220
+
221
+ def get_lowest_version_set(self, app_to_versions):
222
+ app_version_set = set([])
223
+ for app in app_to_versions:
224
+ _versions = list(app_to_versions[app])
225
+ _versions.sort()
226
+ if len(_versions) < 2:
227
+ continue
228
+ app_version_set.add((app, _versions[0]))
229
+ return app_version_set
230
+
231
+ # method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
232
+ def _generate_examples(self, screenshots_path: str, split, json_path, appinfo, data_dir):
233
+ # TODO: This method handles input defined in _split_generators to yield (key, example) tuples from the dataset.
234
+ # The `key` is for legacy reasons (tfds) and is not important in itself, but must be unique for each example.
235
+ split_file_map = {"all": "",
236
+ "android_low": "split_by_android_low_version.json",
237
+ "ios": "split_by_ios.json",
238
+ "web": "split_by_web.json",
239
+ "normal": "split_normal.json",
240
+ "app": "split_app.json"}
241
+ split_file = split_file_map[self.config.name]
242
+ split_data = {}
243
+ if split_file:
244
+ with open(os.path.join(data_dir, split_file), encoding="utf-8") as f:
245
+ split_data = json.load(f)
246
+ book = openpyxl.load_workbook(appinfo)
247
+ sheet = book["Sheet2"]
248
+ row_idx = 1
249
+ prefix_to_apptype = {}
250
+ while sheet.cell(row=row_idx, column=1).value:
251
+ row_data = []
252
+ col_idx = 1
253
+ while sheet.cell(row=row_idx, column=col_idx).value:
254
+ row_data.append(sheet.cell(row=row_idx, column=col_idx).value)
255
+ col_idx += 1
256
+ prefix_to_apptype[row_data[0]] = row_data[1]
257
+ row_idx += 1
258
+
259
+ with open(json_path, encoding="utf-8") as f:
260
+ datas = json.load(f)
261
+ _datas = [t for t in datas if t['platform_type'] == "android"]
262
+ _app_version_dict = self.get_app_version_dict(_datas)
263
+ app_version_set = self.get_lowest_version_set(_app_version_dict)
264
+ for data in datas:
265
+ if data['platform_type'] == "android" and (data['app_name'], data['app_version']) in app_version_set:
266
+ data['version_type'] = 'low'
267
+ else:
268
+ data['version_type'] = 'high'
269
+ if self.config.name == "all":
270
+ # with open(json_path, encoding="utf-8") as f:
271
+ key = 0
272
+ # datas = json.load(f)
273
+ for data in datas:
274
+ # Yields examples as (key, example) tuples\
275
+ img_path = os.path.join(
276
+ os.path.join(screenshots_path, data['platform_type']), str(data['screenshot_filename'])
277
+ )
278
+ # img = Image.open(
279
+ # img_path
280
+ # )
281
+ # image_data = io.BytesIO()
282
+ # img.save(image_data, format='PNG')
283
+ # image_data_bytes = image_data.getvalue()
284
+ # encoded_png_image = base64.b64encode(image_data_bytes).decode('utf-8')
285
+ encoded_image = ""
286
+ yield key, {
287
+ "grounding_instruction": data["grounding_instruction"],
288
+ "target_bbox": [[float(x) for x in data['target_bbox']]],
289
+ "app_type": prefix_to_apptype[int(data['screenshot_filename'].split('-')[0])],
290
+ "screenshot_png_base64": encoded_image,
291
+ "screenshot_path": img_path,
292
+ "platform_type": data["platform_type"],
293
+ "app_name": data["app_name"],
294
+ "page_name": data["page_name"],
295
+ "app_version": data["app_version"],
296
+ "app_version_type": data["version_type"]
297
+ # These are the features of your dataset like images, labels ...
298
+ }
299
+ key += 1
300
+ else:
301
+ split_idxs = split_data[split]
302
+ split_idxs_set = set(split_idxs)
303
+ # assert same len
304
+ assert len(split_idxs) == len(split_idxs_set)
305
+ # with open(json_path, encoding="utf-8") as f:
306
+ key = 0
307
+ for current_idx in range(len(datas)):
308
+ data = datas[current_idx]
309
+ if current_idx not in split_idxs_set:
310
+ continue
311
+ img_path = os.path.join(
312
+ os.path.join(screenshots_path, data['platform_type']), str(data['screenshot_filename'])
313
+ )
314
+ encoded_image = ""
315
+ yield key, {
316
+ "grounding_instruction": data["grounding_instruction"],
317
+ "target_bbox": [[float(x) for x in data['target_bbox']]],
318
+ "app_type": prefix_to_apptype[int(data['screenshot_filename'].split('-')[0])],
319
+ "screenshot_png_base64": encoded_image,
320
+ "screenshot_path": img_path,
321
+ "platform_type": data["platform_type"],
322
+ "app_name": data["app_name"],
323
+ "page_name": data["page_name"],
324
+ "app_version": data["app_version"],
325
+ "app_version_type": data["version_type"]
326
+ # These are the features of your dataset like images, labels ...
327
+ }
328
+ key += 1