hashmin commited on
Commit
099c6e5
·
verified ·
1 Parent(s): db8bd28

Upload epadb.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. epadb.py +28 -5
epadb.py CHANGED
@@ -1,4 +1,5 @@
1
  import json
 
2
  import datasets
3
 
4
  _CITATION = """\
@@ -44,24 +45,46 @@ class Epadb(datasets.GeneratorBasedBuilder):
44
  )
45
 
46
  def _split_generators(self, dl_manager):
 
47
  train_path = dl_manager.download("train.json")
48
  test_path = dl_manager.download("test.json")
49
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50
  return [
51
  datasets.SplitGenerator(
52
  name=datasets.Split.TRAIN,
53
- gen_kwargs={"filepath": train_path, "split": "train"},
 
 
 
54
  ),
55
  datasets.SplitGenerator(
56
  name=datasets.Split.TEST,
57
- gen_kwargs={"filepath": test_path, "split": "test"},
 
 
 
58
  ),
59
  ]
60
 
61
- def _generate_examples(self, filepath, split):
62
  with open(filepath, encoding="utf-8") as f:
63
  data = json.load(f)
64
  for idx, example in enumerate(data):
65
- # The audio field contains the relative path
66
- # datasets library will automatically download it
 
67
  yield idx, example
 
1
  import json
2
+ import os
3
  import datasets
4
 
5
  _CITATION = """\
 
45
  )
46
 
47
  def _split_generators(self, dl_manager):
48
+ # First, download the JSON files
49
  train_path = dl_manager.download("train.json")
50
  test_path = dl_manager.download("test.json")
51
 
52
+ # Read JSON to get list of all audio files
53
+ with open(train_path) as f:
54
+ train_data = json.load(f)
55
+ with open(test_path) as f:
56
+ test_data = json.load(f)
57
+
58
+ # Collect all unique audio files referenced
59
+ train_audio_files = [example["audio"] for example in train_data]
60
+ test_audio_files = [example["audio"] for example in test_data]
61
+
62
+ # Download all audio files
63
+ train_audio_paths = dl_manager.download(train_audio_files)
64
+ test_audio_paths = dl_manager.download(test_audio_files)
65
+
66
  return [
67
  datasets.SplitGenerator(
68
  name=datasets.Split.TRAIN,
69
+ gen_kwargs={
70
+ "filepath": train_path,
71
+ "audio_files": dict(zip(train_audio_files, train_audio_paths))
72
+ },
73
  ),
74
  datasets.SplitGenerator(
75
  name=datasets.Split.TEST,
76
+ gen_kwargs={
77
+ "filepath": test_path,
78
+ "audio_files": dict(zip(test_audio_files, test_audio_paths))
79
+ },
80
  ),
81
  ]
82
 
83
+ def _generate_examples(self, filepath, audio_files):
84
  with open(filepath, encoding="utf-8") as f:
85
  data = json.load(f)
86
  for idx, example in enumerate(data):
87
+ # Replace the audio path with the downloaded local path
88
+ audio_path = example["audio"]
89
+ example["audio"] = audio_files[audio_path]
90
  yield idx, example