Datasets:
Delete loading script
Browse files- BA_Datensatz_V2.py +0 -82
BA_Datensatz_V2.py
DELETED
@@ -1,82 +0,0 @@
|
|
1 |
-
import datasets
|
2 |
-
import csv
|
3 |
-
import json
|
4 |
-
import os
|
5 |
-
import csv
|
6 |
-
|
7 |
-
# Defining Access
|
8 |
-
_DATA_URL = "https://huggingface.co/datasets/LennyBijan/BA_Datensatz_V2/resolve/main/data"
|
9 |
-
|
10 |
-
|
11 |
-
class BA_Datensatz_V2(datasets.GeneratorBasedBuilder):
|
12 |
-
|
13 |
-
def _info(self):
|
14 |
-
return datasets.DatasetInfo(
|
15 |
-
description="German Dataset that focuses on juristical data",
|
16 |
-
features=datasets.Features({
|
17 |
-
"clip_id": datasets.Value("string"),
|
18 |
-
"path": datasets.Value("string"),
|
19 |
-
"audio": datasets.Audio(sampling_rate=16_000),
|
20 |
-
"sentence": datasets.Value("string"),
|
21 |
-
"split": datasets.Value("string")
|
22 |
-
}),
|
23 |
-
supervised_keys=None,
|
24 |
-
)
|
25 |
-
|
26 |
-
def _split_generators(self, dl_manager):
|
27 |
-
dl_manager.download_config.ignore_url_params = True
|
28 |
-
|
29 |
-
audio_path = {}
|
30 |
-
local_extracted_archive = {}
|
31 |
-
metadata_path = {}
|
32 |
-
split_type = {"train": datasets.Split.TRAIN, "test": datasets.Split.TEST}
|
33 |
-
for split in split_type:
|
34 |
-
audio_path[split] = dl_manager.download(f"{_DATA_URL}/audio_{split}.tgz")
|
35 |
-
local_extracted_archive[split] = dl_manager.extract(audio_path[split]) if not dl_manager.is_streaming else None
|
36 |
-
metadata_path[split] = dl_manager.download_and_extract(f"{_DATA_URL}/metadata_{split}.csv.gz")
|
37 |
-
path_to_clips = "BA_Datensatz_V2"
|
38 |
-
|
39 |
-
return [
|
40 |
-
datasets.SplitGenerator(
|
41 |
-
name=split_type[split],
|
42 |
-
gen_kwargs={
|
43 |
-
"local_extracted_archive": local_extracted_archive[split],
|
44 |
-
"audio_files": dl_manager.iter_archive(audio_path[split]),
|
45 |
-
"metadata_path": dl_manager.download_and_extract(metadata_path[split]),
|
46 |
-
"path_to_clips": path_to_clips,
|
47 |
-
"split": split # pass the split name to _generate_examples
|
48 |
-
},
|
49 |
-
) for split in split_type
|
50 |
-
]
|
51 |
-
|
52 |
-
def _generate_examples(self, audio_files, metadata_path, path_to_clips, local_extracted_archive, split):
|
53 |
-
metadata = {}
|
54 |
-
# Open and read the metadata CSV file.
|
55 |
-
with open(metadata_path, "r", encoding="utf-8") as f:
|
56 |
-
reader = csv.reader(f)
|
57 |
-
for row in reader:
|
58 |
-
filename, sentence = row
|
59 |
-
clip_id = filename.split('_')[0]
|
60 |
-
# Append the split name dynamically to the path_to_clips.
|
61 |
-
path = os.path.join(path_to_clips, split +"/wav/"+ clip_id, filename)
|
62 |
-
metadata[path] = {
|
63 |
-
"clip_id": clip_id,
|
64 |
-
"sentence": sentence,
|
65 |
-
"path": path,
|
66 |
-
}
|
67 |
-
id_ = 0
|
68 |
-
for path, file_content in audio_files: # No need to adjust the path if no local extraction.
|
69 |
-
if path in metadata:
|
70 |
-
result = dict(metadata[path])
|
71 |
-
path = os.path.join(local_extracted_archive, path) if local_extracted_archive else path
|
72 |
-
audio_data = {"path": path, "bytes": file_content.read()}
|
73 |
-
result["audio"] = audio_data
|
74 |
-
result["path"] = path
|
75 |
-
yield id_, result
|
76 |
-
id_ += 1
|
77 |
-
else:
|
78 |
-
print(f"No metadata entry for {path}")
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|