Datasets:
Update create_hf_dataset.py script to work with the new version
Browse files- create_hf_dataset.py +35 -13
create_hf_dataset.py
CHANGED
@@ -1,26 +1,48 @@
|
|
1 |
from pathlib import Path
|
2 |
import shutil
|
|
|
3 |
|
4 |
import datasets
|
5 |
|
6 |
|
|
|
|
|
|
|
7 |
def main():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
datasets.disable_caching()
|
9 |
|
10 |
-
# Divide the MP3 files by language. Hugging Face requires each subset and its metadadta to be in
|
11 |
-
# a separate directory. However, for backwards compatibility, we also want to keep the top-level
|
12 |
-
# "audio" directory and replace the MP3 files with symlinks into the subsets.
|
13 |
subsets_dir = Path("subsets")
|
14 |
-
if subsets_dir.exists():
|
15 |
-
shutil.rmtree(subsets_dir)
|
16 |
-
subsets_dir.mkdir()
|
17 |
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
|
25 |
# Create language subsets and:
|
26 |
# - hard link the files from mp3_orig to subsets
|
@@ -51,7 +73,7 @@ def main():
|
|
51 |
|
52 |
dataset.to_json(subset_dir / "metadata.jsonl")
|
53 |
|
54 |
-
if config_name != "all":
|
55 |
(subset_dir / "audio").mkdir()
|
56 |
for name in dataset["name"]:
|
57 |
(subset_dir / "audio" / f"{name}.mp3").hardlink_to(
|
|
|
1 |
from pathlib import Path
|
2 |
import shutil
|
3 |
+
import argparse
|
4 |
|
5 |
import datasets
|
6 |
|
7 |
|
8 |
+
NUM_SONGS = 79
|
9 |
+
|
10 |
+
|
11 |
def main():
|
12 |
+
parser = argparse.ArgumentParser()
|
13 |
+
parser.add_argument(
|
14 |
+
"--move-audio",
|
15 |
+
action="store_true",
|
16 |
+
help="Move and link audio files (default: only create metadata.jsonl files)",
|
17 |
+
)
|
18 |
+
args = parser.parse_args()
|
19 |
+
|
20 |
datasets.disable_caching()
|
21 |
|
|
|
|
|
|
|
22 |
subsets_dir = Path("subsets")
|
|
|
|
|
|
|
23 |
|
24 |
+
if args.move_audio:
|
25 |
+
# Divide the MP3 files by language. Hugging Face requires each subset and its metadata to be in
|
26 |
+
# a separate directory. However, for backwards compatibility, we also want to keep the top-level
|
27 |
+
# "audio" directory and replace the MP3 files with symlinks into the subsets.
|
28 |
+
if subsets_dir.exists():
|
29 |
+
shutil.rmtree(subsets_dir)
|
30 |
+
subsets_dir.mkdir()
|
31 |
+
|
32 |
+
# Back up the directory with the original MP3 files
|
33 |
+
if not Path("audio_orig").exists():
|
34 |
+
Path("audio").rename("audio_orig")
|
35 |
+
elif Path("audio").exists():
|
36 |
+
shutil.rmtree("audio")
|
37 |
+
Path("audio").mkdir(exist_ok=True)
|
38 |
+
else:
|
39 |
+
num_audio_files = sum(1 for _ in subsets_dir.glob("*/audio/*.mp3"))
|
40 |
+
if num_audio_files != NUM_SONGS:
|
41 |
+
raise RuntimeError(
|
42 |
+
f"Expected '{subsets_dir}' to exist and contain all {NUM_SONGS} audio files in "
|
43 |
+
f"subdirectories by language. Found {num_audio_files} files matching the pattern. "
|
44 |
+
"Use --move-audio if the audio files are found in 'audio' instead."
|
45 |
+
)
|
46 |
|
47 |
# Create language subsets and:
|
48 |
# - hard link the files from mp3_orig to subsets
|
|
|
73 |
|
74 |
dataset.to_json(subset_dir / "metadata.jsonl")
|
75 |
|
76 |
+
if args.move_audio and config_name != "all":
|
77 |
(subset_dir / "audio").mkdir()
|
78 |
for name in dataset["name"]:
|
79 |
(subset_dir / "audio" / f"{name}.mp3").hardlink_to(
|