MuGeminorum Studio
commited on
Commit
•
587f196
1
Parent(s):
5f571fc
Delete genshin_piano.py
Browse files- genshin_piano.py +0 -130
genshin_piano.py
DELETED
@@ -1,130 +0,0 @@
|
|
1 |
-
import os
|
2 |
-
import shutil
|
3 |
-
import random
|
4 |
-
import hashlib
|
5 |
-
import datasets
|
6 |
-
from midi2abc import midi2abc
|
7 |
-
|
8 |
-
|
9 |
-
_HOMEPAGE = f"https://huggingface.co/datasets/MuGeminorum/{os.path.basename(__file__).split('.')[0]}"
|
10 |
-
|
11 |
-
_CITATION = """\
|
12 |
-
@dataset{genshin_piano,
|
13 |
-
author = {MuGeminorum Studio},
|
14 |
-
title = {Genshin Piano Songs},
|
15 |
-
month = {nov},
|
16 |
-
year = {2023},
|
17 |
-
publisher = {HF},
|
18 |
-
version = {1.1},
|
19 |
-
url = {https://huggingface.co/datasets/MuGeminorum/genshin_piano}
|
20 |
-
}
|
21 |
-
"""
|
22 |
-
|
23 |
-
_DESCRIPTION = """\
|
24 |
-
This database contains genshin piano songs downloaded from musescore
|
25 |
-
"""
|
26 |
-
|
27 |
-
_URL = f"{_HOMEPAGE}/resolve/main/data/dataset.zip"
|
28 |
-
|
29 |
-
|
30 |
-
def calculate_hash(file_path):
|
31 |
-
# 计算文件的哈希值
|
32 |
-
with open(file_path, 'rb') as midi_file:
|
33 |
-
content = midi_file.read()
|
34 |
-
return hashlib.md5(content).hexdigest()
|
35 |
-
|
36 |
-
|
37 |
-
def rm_duplicates_in_folder(input_folder):
|
38 |
-
# 用于存储文件哈希值的字典
|
39 |
-
hash_dict = {}
|
40 |
-
duplist = []
|
41 |
-
# 遍历输入文件夹
|
42 |
-
for root, _, files in os.walk(input_folder):
|
43 |
-
for file in files:
|
44 |
-
file_path = os.path.join(root, file)
|
45 |
-
file_hash = calculate_hash(file_path)
|
46 |
-
|
47 |
-
# 检查文件哈希值是否已存在
|
48 |
-
if file_hash in hash_dict:
|
49 |
-
print(f"Duplicates found: {file}")
|
50 |
-
# 将重复文件直接删除
|
51 |
-
duplist.append(file_path)
|
52 |
-
shutil.rmtree(file_path)
|
53 |
-
else:
|
54 |
-
# 存储文件哈希值
|
55 |
-
hash_dict[file_hash] = file_path
|
56 |
-
|
57 |
-
return duplist
|
58 |
-
|
59 |
-
|
60 |
-
class genshin_piano(datasets.GeneratorBasedBuilder):
|
61 |
-
def _info(self):
|
62 |
-
return datasets.DatasetInfo(
|
63 |
-
features=datasets.Features(
|
64 |
-
{
|
65 |
-
"midi": datasets.Value("string"),
|
66 |
-
"abc": datasets.Value("string"),
|
67 |
-
"tag": datasets.Value("string")
|
68 |
-
}
|
69 |
-
),
|
70 |
-
supervised_keys=("abc", "tags"),
|
71 |
-
homepage=_HOMEPAGE,
|
72 |
-
license="mit",
|
73 |
-
citation=_CITATION,
|
74 |
-
description=_DESCRIPTION
|
75 |
-
)
|
76 |
-
|
77 |
-
def _split_generators(self, dl_manager):
|
78 |
-
data_files = dl_manager.download_and_extract(_URL)
|
79 |
-
files = dl_manager.iter_files([data_files])
|
80 |
-
dataset = []
|
81 |
-
|
82 |
-
extract_dir = data_files + '\\dataset'
|
83 |
-
duplist = rm_duplicates_in_folder(extract_dir)
|
84 |
-
|
85 |
-
for path in files:
|
86 |
-
if (not path in duplist) and (os.path.basename(path).endswith(".mid")):
|
87 |
-
dataset.append(path)
|
88 |
-
|
89 |
-
random.shuffle(dataset)
|
90 |
-
# data_count = len(dataset)
|
91 |
-
# p80 = int(data_count * 0.8)
|
92 |
-
# p90 = int(data_count * 0.9)
|
93 |
-
|
94 |
-
# return [
|
95 |
-
# datasets.SplitGenerator(
|
96 |
-
# name=datasets.Split.TRAIN,
|
97 |
-
# gen_kwargs={
|
98 |
-
# "files": dataset[:p80]
|
99 |
-
# }
|
100 |
-
# ),
|
101 |
-
# datasets.SplitGenerator(
|
102 |
-
# name=datasets.Split.VALIDATION,
|
103 |
-
# gen_kwargs={
|
104 |
-
# "files": dataset[p80:p90]
|
105 |
-
# }
|
106 |
-
# ),
|
107 |
-
# datasets.SplitGenerator(
|
108 |
-
# name=datasets.Split.TEST,
|
109 |
-
# gen_kwargs={
|
110 |
-
# "files": dataset[p90:]
|
111 |
-
# }
|
112 |
-
# )
|
113 |
-
# ]
|
114 |
-
|
115 |
-
return [
|
116 |
-
datasets.SplitGenerator(
|
117 |
-
name=datasets.Split.TRAIN,
|
118 |
-
gen_kwargs={
|
119 |
-
"files": dataset
|
120 |
-
}
|
121 |
-
)
|
122 |
-
]
|
123 |
-
|
124 |
-
def _generate_examples(self, files):
|
125 |
-
for i, path in enumerate(files):
|
126 |
-
yield i, {
|
127 |
-
"midi": path,
|
128 |
-
"abc": midi2abc(path),
|
129 |
-
"tag": os.path.basename(path)[:-4].encode('cp437').decode('gbk')
|
130 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|