|
|
|
|
|
"""Loading script for Teyvat.""" |
|
|
|
import re |
|
import numpy as np |
|
import pandas as pd |
|
|
|
from json import load, dump |
|
from os.path import join, basename |
|
from huggingface_hub import hf_hub_url |
|
|
|
import datasets |
|
|
|
|
|
_DESCRIPTION = """ |
|
Teyvat is the first small-scale text-to-image prompt dataset for Genshin impact. |
|
""" |
|
|
|
_LICENSE = "CC0 1.0" |
|
_VERSION = datasets.Version("0.0.1") |
|
|
|
|
|
|
|
|
|
|
|
_URLS = {"data" :hf_hub_url( |
|
repo_id = "Fazzie/Teyvat", |
|
filename = "data.zip", |
|
repo_type = "dataset", |
|
), |
|
"metadata" :hf_hub_url( |
|
repo_id = "Fazzie/Teyvat", |
|
filename = "metadata.json", |
|
repo_type = "dataset", |
|
) |
|
} |
|
|
|
|
|
class Teyvat(datasets.GeneratorBasedBuilder): |
|
"""Teyvat is the first small-scale text-to-image prompt dataset for Genshin impact""" |
|
|
|
|
|
def _info(self): |
|
"""Specify the information of Teyvat.""" |
|
|
|
|
|
features = datasets.Features( |
|
{ |
|
"image": datasets.Image(), |
|
"text": datasets.Value("string"), |
|
}, |
|
) |
|
|
|
return datasets.DatasetInfo( |
|
description=_DESCRIPTION, |
|
features=features, |
|
supervised_keys=None, |
|
license=_LICENSE, |
|
version=_VERSION |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
urls = _URLS |
|
|
|
|
|
data_path = dl_manager.download_and_extract(urls["data"]) |
|
meta_data_path = dl_manager.download(urls["metadata"]) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return [ |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TRAIN, |
|
|
|
gen_kwargs={ |
|
"data_path": data_path, |
|
"meta_data_path": meta_data_path |
|
}, |
|
), |
|
] |
|
|
|
def _generate_examples(self, data_path, meta_data_path): |
|
|
|
|
|
|
|
|
|
|
|
|
|
print("Loading metadata...", meta_data_path) |
|
data = load(open(meta_data_path, "r", encoding="utf8")) |
|
|
|
for image in data: |
|
image_path = join(data_path, "data", image["file_name"]) |
|
text = image["text"] |
|
|
|
|
|
|
|
yield image_path, { |
|
"image": { |
|
"path": image_path, |
|
"bytes": open(image_path, "rb").read(), |
|
}, |
|
"text": text, |
|
} |