Datasets:
License:
import os | |
import random | |
import datasets | |
from midi2abc import midi2abc | |
from data import rm_duplicates_in_folder | |
_HOMEPAGE = f"https://huggingface.co/datasets/MuGeminorum/{os.path.basename(__file__).split('.')[0]}" | |
_CITATION = """\ | |
@dataset{genshin_piano, | |
author = {MuGeminorum Studio}, | |
title = {Genshin Piano Songs}, | |
month = {nov}, | |
year = {2023}, | |
publisher = {HF}, | |
version = {1.1}, | |
url = {https://huggingface.co/datasets/MuGeminorum/genshin_piano} | |
} | |
""" | |
_DESCRIPTION = """\ | |
This database contains genshin piano songs downloaded from musescore | |
""" | |
_URL = f"{_HOMEPAGE}/resolve/main/data/dataset.zip" | |
class genshin_piano(datasets.GeneratorBasedBuilder): | |
def _info(self): | |
return datasets.DatasetInfo( | |
features=datasets.Features( | |
{ | |
"midi": datasets.Value("string"), | |
"abc": datasets.Value("string"), | |
"tag": datasets.Value("string") | |
} | |
), | |
supervised_keys=("abc", "tags"), | |
homepage=_HOMEPAGE, | |
license="mit", | |
citation=_CITATION, | |
description=_DESCRIPTION | |
) | |
def _split_generators(self, dl_manager): | |
data_files = dl_manager.download_and_extract(_URL) | |
files = dl_manager.iter_files([data_files]) | |
dataset = [] | |
extract_dir = os.path.dirname(data_files[0]) | |
duplist = rm_duplicates_in_folder(extract_dir) | |
for path in files: | |
if (not path in duplist) and (os.path.basename(path).endswith(".mid")): | |
dataset.append(path) | |
random.shuffle(dataset) | |
# data_count = len(dataset) | |
# p80 = int(data_count * 0.8) | |
# p90 = int(data_count * 0.9) | |
# return [ | |
# datasets.SplitGenerator( | |
# name=datasets.Split.TRAIN, | |
# gen_kwargs={ | |
# "files": dataset[:p80] | |
# } | |
# ), | |
# datasets.SplitGenerator( | |
# name=datasets.Split.VALIDATION, | |
# gen_kwargs={ | |
# "files": dataset[p80:p90] | |
# } | |
# ), | |
# datasets.SplitGenerator( | |
# name=datasets.Split.TEST, | |
# gen_kwargs={ | |
# "files": dataset[p90:] | |
# } | |
# ) | |
# ] | |
return [ | |
datasets.SplitGenerator( | |
name=datasets.Split.TRAIN, | |
gen_kwargs={ | |
"files": dataset | |
} | |
) | |
] | |
def _generate_examples(self, files): | |
for i, path in enumerate(files): | |
yield i, { | |
"midi": path, | |
"abc": midi2abc(path), | |
"tag": os.path.basename(path)[:-4].encode('cp437').decode('gbk') | |
} | |