import os import datasets from datasets import DownloadManager, DatasetInfo _DESCRIPTION = """\ FBAnimeHQ is a dataset with high-quality full-body anime girl images in a resolution of 1024 × 512. """ _HOMEPAGE = "https://huggingface.co/datasets/skytnt/fbanimehq" _URL_BASE = "https://huggingface.co/datasets/skytnt/fbanimehq/resolve/main/data/" _EXTENSION = [".png", ".jpg"] _URLS_HQ = [f"{_URL_BASE}fbanimehq-{i:02d}.zip" for i in range(12)] _URLS_SMALL = [ # _URL_BASE + "fbanimesmall.zip", ] class FBAnimeHQConfig(datasets.BuilderConfig): def __init__(self, urls, **kwargs): super(FBAnimeHQConfig, self).__init__(**kwargs) self.urls = urls class FBAnimeHQ(datasets.GeneratorBasedBuilder): BUILDER_CONFIGS = [ FBAnimeHQConfig(name="hq", urls=_URLS_HQ), FBAnimeHQConfig(name="small", urls=_URLS_SMALL) ] def _info(self) -> DatasetInfo: return datasets.DatasetInfo( description=_DESCRIPTION, features=datasets.Features( { "image": datasets.Image(), } ), supervised_keys=None, homepage=_HOMEPAGE, citation="", ) def _split_generators(self, dl_manager: DownloadManager): dirs = dl_manager.download_and_extract(self.config.urls) return [datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"dirs": dirs})] def _generate_examples(self, dirs): for path in dirs: all_fnames = {os.path.relpath(os.path.join(root, fname), start=path) for root, _dirs, files in os.walk(path) for fname in files} image_fnames = sorted(fname for fname in all_fnames if os.path.splitext(fname)[1].lower() in _EXTENSION) for image_fname in image_fnames: yield image_fname, {"image": os.path.join(path, image_fname)}