|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| """TODO: Add a description here."""
|
| import base64
|
| import csv
|
| import io
|
| import json
|
| import os
|
| from uu import encode
|
|
|
| import openpyxl
|
| import datasets
|
| from PIL import Image
|
|
|
| _CITATION = """\
|
| @InProceedings{huggingface:dataset,
|
| title = {TransBench: Breaking Barriers for Transferable Graphical User Interface Agents in Dynamic Digital Environments},
|
| 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},
|
| booktitle={Findings of the Association for Computational Linguistics: ACL 2025},
|
| year={2025}
|
| }
|
| """
|
|
|
| _DESCRIPTION = """\
|
| This dataset is the supplementary dataset for the paper, generated by an automated pipeline with additional manual quality control.
|
| """
|
|
|
|
|
| _HOMEPAGE = "https://github.com/BUAA-IRIP-LLM/TransBench"
|
|
|
|
|
| _LICENSE = ""
|
|
|
|
|
|
|
|
|
| _URLS = {
|
| "first_domain": "https://huggingface.co/great-new-dataset-first_domain.zip",
|
| "second_domain": "https://huggingface.co/great-new-dataset-second_domain.zip",
|
| }
|
|
|
|
|
|
|
| class TransferabilityGuiBenchmark(datasets.GeneratorBasedBuilder):
|
| """This dataset is the supplementary dataset for the paper, generated by an automated pipeline with additional manual quality control.
|
| 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.
|
| """
|
|
|
| VERSION = datasets.Version("1.0.0")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| BUILDER_CONFIGS = [
|
| datasets.BuilderConfig(name="all", version=VERSION, description="all datapoint of this dataset"),
|
| datasets.BuilderConfig(name="android_low", version=VERSION,
|
| description="use android_low_version to train model"),
|
| datasets.BuilderConfig(name="ios", version=VERSION,
|
| description="use ios to train model"),
|
| datasets.BuilderConfig(name="web", version=VERSION,
|
| description="use ios to train model"),
|
| datasets.BuilderConfig(name="normal", version=VERSION,
|
| description="use ramdom 5000 data split to train model"),
|
| datasets.BuilderConfig(name="app", version=VERSION,
|
| description="use 2/5 apps in top7 app-type to train model"),
|
| ]
|
|
|
| DEFAULT_CONFIG_NAME = "all"
|
|
|
| def _info(self):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| features = datasets.Features(
|
| {
|
| "grounding_instruction": datasets.Value("string"),
|
| "target_bbox": datasets.Array2D(shape=(1, 4), dtype="float32"),
|
| "app_type": datasets.Value("string"),
|
| "screenshot_png_base64": datasets.Value("string"),
|
| "screenshot_path": datasets.Value("string"),
|
| "platform_type": datasets.Value("string"),
|
| "app_name": datasets.Value("string"),
|
| "page_name": datasets.Value("string"),
|
| "app_version": datasets.Value("string"),
|
| "app_version_type" : datasets.Value("string"),
|
|
|
| }
|
| )
|
| return datasets.DatasetInfo(
|
|
|
| description=_DESCRIPTION,
|
|
|
| features=features,
|
|
|
|
|
|
|
|
|
| homepage=_HOMEPAGE,
|
|
|
| license=_LICENSE,
|
|
|
| citation=_CITATION,
|
| )
|
|
|
| def __check_all_screenshots_exists(self, rootpath: str):
|
| with open(os.path.join(rootpath, "processed_grounding_data.json"), 'r', encoding='utf-8') as f:
|
| data = json.load(f)
|
| for case in data:
|
| if not os.path.exists(
|
| os.path.join(rootpath,
|
| os.path.join("screenshots",
|
| os.path.join(str(case['platform_type']),
|
| case['screenshot_filename'])
|
| )
|
| )
|
| ):
|
| raise Exception(f"{case['screenshot_filename']} is not exist")
|
|
|
| def _split_generators(self, dl_manager):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| url = "TGB.zip"
|
| data_dir = dl_manager.download_and_extract(url)
|
|
|
| self.__check_all_screenshots_exists(data_dir)
|
|
|
| return [
|
| datasets.SplitGenerator(
|
| name=datasets.Split.TRAIN,
|
|
|
| gen_kwargs={
|
| 'data_dir': data_dir,
|
| "screenshots_path": os.path.join(data_dir, "screenshots"),
|
| "json_path": os.path.join(data_dir, "processed_grounding_data.json"),
|
| "split": "train",
|
| "appinfo": os.path.join(data_dir, "appinfo.xlsx")
|
| },
|
| ),
|
| datasets.SplitGenerator(
|
| name=datasets.Split.VALIDATION,
|
|
|
| gen_kwargs={
|
| 'data_dir': data_dir,
|
| "screenshots_path": os.path.join(data_dir, "screenshots"),
|
| "json_path": os.path.join(data_dir, "processed_grounding_data.json"),
|
| "split": "valid",
|
| "appinfo": os.path.join(data_dir, "appinfo.xlsx")
|
| },
|
| ),
|
| datasets.SplitGenerator(
|
| name=datasets.Split.TEST,
|
|
|
| gen_kwargs={
|
| 'data_dir': data_dir,
|
| "screenshots_path": os.path.join(data_dir, "screenshots"),
|
| "json_path": os.path.join(data_dir, "processed_grounding_data.json"),
|
| "split": "test",
|
| "appinfo": os.path.join(data_dir, "appinfo.xlsx")
|
| },
|
| ),
|
| ]
|
|
|
| def get_app_version_dict(self, datas):
|
| app_to_versions = {}
|
| for case in datas:
|
| appname = case['app_name']
|
| if appname not in app_to_versions:
|
| app_to_versions[appname] = set([])
|
| app_to_versions[appname].add(case['app_version'])
|
| return app_to_versions
|
|
|
| def get_lowest_version_set(self, app_to_versions):
|
| app_version_set = set([])
|
| for app in app_to_versions:
|
| _versions = list(app_to_versions[app])
|
| _versions.sort()
|
| if len(_versions) < 2:
|
| continue
|
| app_version_set.add((app, _versions[0]))
|
| return app_version_set
|
|
|
|
|
| def _generate_examples(self, screenshots_path: str, split, json_path, appinfo, data_dir):
|
|
|
|
|
| split_file_map = {"all": "",
|
| "android_low": "split_by_android_low_version.json",
|
| "ios": "split_by_ios.json",
|
| "web": "split_by_web.json",
|
| "normal": "split_normal.json",
|
| "app": "split_app.json"}
|
| split_file = split_file_map[self.config.name]
|
| split_data = {}
|
| if split_file:
|
| with open(os.path.join(data_dir, split_file), encoding="utf-8") as f:
|
| split_data = json.load(f)
|
| book = openpyxl.load_workbook(appinfo)
|
| sheet = book["Sheet2"]
|
| row_idx = 1
|
| prefix_to_apptype = {}
|
| while sheet.cell(row=row_idx, column=1).value:
|
| row_data = []
|
| col_idx = 1
|
| while sheet.cell(row=row_idx, column=col_idx).value:
|
| row_data.append(sheet.cell(row=row_idx, column=col_idx).value)
|
| col_idx += 1
|
| prefix_to_apptype[row_data[0]] = row_data[1]
|
| row_idx += 1
|
|
|
| with open(json_path, encoding="utf-8") as f:
|
| datas = json.load(f)
|
| _datas = [t for t in datas if t['platform_type'] == "android"]
|
| _app_version_dict = self.get_app_version_dict(_datas)
|
| app_version_set = self.get_lowest_version_set(_app_version_dict)
|
| for data in datas:
|
| if data['platform_type'] == "android" and (data['app_name'], data['app_version']) in app_version_set:
|
| data['version_type'] = 'low'
|
| else:
|
| data['version_type'] = 'high'
|
| if self.config.name == "all":
|
|
|
| key = 0
|
|
|
| for data in datas:
|
|
|
| img_path = os.path.join(
|
| os.path.join(screenshots_path, data['platform_type']), str(data['screenshot_filename'])
|
| )
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| encoded_image = ""
|
| yield key, {
|
| "grounding_instruction": data["grounding_instruction"],
|
| "target_bbox": [[float(x) for x in data['target_bbox']]],
|
| "app_type": prefix_to_apptype[int(data['screenshot_filename'].split('-')[0])],
|
| "screenshot_png_base64": encoded_image,
|
| "screenshot_path": img_path,
|
| "platform_type": data["platform_type"],
|
| "app_name": data["app_name"],
|
| "page_name": data["page_name"],
|
| "app_version": data["app_version"],
|
| "app_version_type": data["version_type"]
|
|
|
| }
|
| key += 1
|
| else:
|
| split_idxs = split_data[split]
|
| split_idxs_set = set(split_idxs)
|
|
|
| assert len(split_idxs) == len(split_idxs_set)
|
|
|
| key = 0
|
| for current_idx in range(len(datas)):
|
| data = datas[current_idx]
|
| if current_idx not in split_idxs_set:
|
| continue
|
| img_path = os.path.join(
|
| os.path.join(screenshots_path, data['platform_type']), str(data['screenshot_filename'])
|
| )
|
| encoded_image = ""
|
| yield key, {
|
| "grounding_instruction": data["grounding_instruction"],
|
| "target_bbox": [[float(x) for x in data['target_bbox']]],
|
| "app_type": prefix_to_apptype[int(data['screenshot_filename'].split('-')[0])],
|
| "screenshot_png_base64": encoded_image,
|
| "screenshot_path": img_path,
|
| "platform_type": data["platform_type"],
|
| "app_name": data["app_name"],
|
| "page_name": data["page_name"],
|
| "app_version": data["app_version"],
|
| "app_version_type": data["version_type"]
|
|
|
| }
|
| key += 1
|
|
|