mnansary commited on
Commit
5f2f83d
1 Parent(s): f0eca56

base v with tsvs

Browse files
Files changed (1) hide show
  1. common_voice_bn.py +11 -31
common_voice_bn.py CHANGED
@@ -71,8 +71,7 @@ class CommonVoiceConfig(datasets.BuilderConfig):
71
 
72
 
73
  class CommonVoice(datasets.GeneratorBasedBuilder):
74
- # DEFAULT_CONFIG_NAME = "en"
75
- DEFAULT_CONFIG_NAME = "bn"
76
  DEFAULT_WRITER_BATCH_SIZE = 1000
77
 
78
  BUILDER_CONFIGS = [
@@ -133,9 +132,7 @@ class CommonVoice(datasets.GeneratorBasedBuilder):
133
  path = urllib.parse.quote(path.encode("utf-8"), safe="~()*!.'")
134
  # use_cdn = self.config.size_bytes < 20 * 1024 * 1024 * 1024
135
  # response = requests.get(f"{_API_URL}/bucket/dataset/{path}/{use_cdn}", timeout=10.0).json()
136
- response = requests.get(
137
- f"{_API_URL}/bucket/dataset/{path}", timeout=10.0
138
- ).json()
139
  return response["url"]
140
 
141
  def _log_download(self, locale, bundle_version, auth_token):
@@ -159,25 +156,15 @@ class CommonVoice(datasets.GeneratorBasedBuilder):
159
  dl_manager.download_config.ignore_url_params = True
160
 
161
  self._log_download(self.config.name, bundle_version, hf_auth_token)
162
- # archive_path = dl_manager.download(self._get_bundle_url(self.config.name, bundle_url_template))
163
- archive_path = dl_manager.download(
164
- "https://mozilla-common-voice-datasets.s3.dualstack.us-west-2.amazonaws.com/cv-corpus-9.0-2022-04-27/cv-corpus-9.0-2022-04-27-bn.tar.gz"
165
- )
166
-
167
- local_extracted_archive = (
168
- dl_manager.extract(archive_path) if not dl_manager.is_streaming else None
169
- )
170
-
171
- path_to_data = "/".join(["cv-corpus-9.0-2022-04-27", "bn"])
172
 
173
- # if self.config.version < datasets.Version("5.0.0"):
174
- # path_to_data = ""
175
-
176
- # else:
177
- # path_to_data = "/".join([bundle_version, self.config.name])
178
  path_to_clips = "/".join([path_to_data, "clips"]) if path_to_data else "clips"
179
 
180
- # we provide our custom csvs with the huggingface repo so,
181
  path_to_tsvs = "/" + "bengali_ai_tsv" + "/"
182
 
183
  return [
@@ -186,7 +173,6 @@ class CommonVoice(datasets.GeneratorBasedBuilder):
186
  gen_kwargs={
187
  "local_extracted_archive": local_extracted_archive,
188
  "archive_iterator": dl_manager.iter_archive(archive_path),
189
- # "metadata_filepath": "/".join([path_to_data, "train.tsv"]) if path_to_data else "train.tsv",
190
  "metadata_filepath": "/".join([path_to_tsvs, "train.tsv"]),
191
  "path_to_clips": path_to_clips,
192
  },
@@ -196,7 +182,6 @@ class CommonVoice(datasets.GeneratorBasedBuilder):
196
  gen_kwargs={
197
  "local_extracted_archive": local_extracted_archive,
198
  "archive_iterator": dl_manager.iter_archive(archive_path),
199
- # "metadata_filepath": "/".join([path_to_data, "test.tsv"]) if path_to_data else "test.tsv",
200
  "metadata_filepath": "/".join([path_to_tsvs, "test.tsv"]),
201
  "path_to_clips": path_to_clips,
202
  },
@@ -206,11 +191,10 @@ class CommonVoice(datasets.GeneratorBasedBuilder):
206
  gen_kwargs={
207
  "local_extracted_archive": local_extracted_archive,
208
  "archive_iterator": dl_manager.iter_archive(archive_path),
209
- # "metadata_filepath": "/".join([path_to_data, "dev.tsv"]) if path_to_data else "dev.tsv",
210
- "metadata_filepath": "/".join([path_to_tsvs, "dev.tsv"]),
211
  "path_to_clips": path_to_clips,
212
  },
213
- ),
214
  ]
215
 
216
  def _generate_examples(
@@ -250,11 +234,7 @@ class CommonVoice(datasets.GeneratorBasedBuilder):
250
  if path in metadata:
251
  result = metadata[path]
252
  # set the audio feature and the path to the extracted file
253
- path = (
254
- os.path.join(local_extracted_archive, path)
255
- if local_extracted_archive
256
- else path
257
- )
258
  result["audio"] = {"path": path, "bytes": f.read()}
259
  # set path to None if the audio file doesn't exist locally (i.e. in streaming mode)
260
  result["path"] = path if local_extracted_archive else None
 
71
 
72
 
73
  class CommonVoice(datasets.GeneratorBasedBuilder):
74
+ DEFAULT_CONFIG_NAME = "en"
 
75
  DEFAULT_WRITER_BATCH_SIZE = 1000
76
 
77
  BUILDER_CONFIGS = [
 
132
  path = urllib.parse.quote(path.encode("utf-8"), safe="~()*!.'")
133
  # use_cdn = self.config.size_bytes < 20 * 1024 * 1024 * 1024
134
  # response = requests.get(f"{_API_URL}/bucket/dataset/{path}/{use_cdn}", timeout=10.0).json()
135
+ response = requests.get(f"{_API_URL}/bucket/dataset/{path}", timeout=10.0).json()
 
 
136
  return response["url"]
137
 
138
  def _log_download(self, locale, bundle_version, auth_token):
 
156
  dl_manager.download_config.ignore_url_params = True
157
 
158
  self._log_download(self.config.name, bundle_version, hf_auth_token)
159
+ archive_path = dl_manager.download(self._get_bundle_url(self.config.name, bundle_url_template))
160
+ local_extracted_archive = dl_manager.extract(archive_path) if not dl_manager.is_streaming else None
 
 
 
 
 
 
 
 
161
 
162
+ if self.config.version < datasets.Version("5.0.0"):
163
+ path_to_data = ""
164
+ else:
165
+ path_to_data = "/".join([bundle_version, self.config.name])
 
166
  path_to_clips = "/".join([path_to_data, "clips"]) if path_to_data else "clips"
167
 
 
168
  path_to_tsvs = "/" + "bengali_ai_tsv" + "/"
169
 
170
  return [
 
173
  gen_kwargs={
174
  "local_extracted_archive": local_extracted_archive,
175
  "archive_iterator": dl_manager.iter_archive(archive_path),
 
176
  "metadata_filepath": "/".join([path_to_tsvs, "train.tsv"]),
177
  "path_to_clips": path_to_clips,
178
  },
 
182
  gen_kwargs={
183
  "local_extracted_archive": local_extracted_archive,
184
  "archive_iterator": dl_manager.iter_archive(archive_path),
 
185
  "metadata_filepath": "/".join([path_to_tsvs, "test.tsv"]),
186
  "path_to_clips": path_to_clips,
187
  },
 
191
  gen_kwargs={
192
  "local_extracted_archive": local_extracted_archive,
193
  "archive_iterator": dl_manager.iter_archive(archive_path),
194
+ "metadata_filepath": "/".join([path_to_tsvs, "dev.tsv"]),
 
195
  "path_to_clips": path_to_clips,
196
  },
197
+ )
198
  ]
199
 
200
  def _generate_examples(
 
234
  if path in metadata:
235
  result = metadata[path]
236
  # set the audio feature and the path to the extracted file
237
+ path = os.path.join(local_extracted_archive, path) if local_extracted_archive else path
 
 
 
 
238
  result["audio"] = {"path": path, "bytes": f.read()}
239
  # set path to None if the audio file doesn't exist locally (i.e. in streaming mode)
240
  result["path"] = path if local_extracted_archive else None