Datasets:
remove typing
Browse files- vox_celeb.py +39 -47
vox_celeb.py
CHANGED
@@ -23,9 +23,7 @@ from hashlib import sha256
|
|
23 |
from itertools import repeat
|
24 |
from multiprocessing import Manager, Pool, Process
|
25 |
from pathlib import Path
|
26 |
-
from queue import Queue
|
27 |
from shutil import copyfileobj
|
28 |
-
from typing import Optional, cast
|
29 |
|
30 |
import pandas as pd
|
31 |
import requests
|
@@ -114,18 +112,18 @@ _PLACEHOLDER_MAPS = dict(
|
|
114 |
|
115 |
|
116 |
def _mp_download(
|
117 |
-
url
|
118 |
-
tmp_path
|
119 |
-
cred_user
|
120 |
-
cred_pass
|
121 |
-
resume_pos
|
122 |
-
length
|
123 |
-
queue
|
124 |
):
|
125 |
if length == resume_pos:
|
126 |
return
|
127 |
with open(tmp_path, "ab" if resume_pos else "wb") as tmp:
|
128 |
-
headers
|
129 |
if resume_pos != 0:
|
130 |
headers["Range"] = f"bytes={resume_pos}-"
|
131 |
response = requests.get(
|
@@ -164,18 +162,15 @@ class VoxCeleb(datasets.GeneratorBasedBuilder):
|
|
164 |
]
|
165 |
|
166 |
def _info(self):
|
167 |
-
features =
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
"clip_index": datasets.Value("int32"),
|
177 |
-
},
|
178 |
-
)
|
179 |
if self.config.name == "audio1":
|
180 |
features["speaker_name"] = datasets.Value("string")
|
181 |
features["speaker_nationality"] = datasets.Value("string")
|
@@ -196,8 +191,8 @@ class VoxCeleb(datasets.GeneratorBasedBuilder):
|
|
196 |
targets = (
|
197 |
["audio1", "audio2"] if self.config.name == "audio" else [self.config.name]
|
198 |
)
|
199 |
-
cred_user
|
200 |
-
cred_pass
|
201 |
creds_path = Path(
|
202 |
f"~/.huggingface/voxceleb_{self.VERSION}_credentials"
|
203 |
).expanduser()
|
@@ -227,12 +222,12 @@ class VoxCeleb(datasets.GeneratorBasedBuilder):
|
|
227 |
json.dump((cred_user, cred_pass), creds)
|
228 |
saved_credentials = True
|
229 |
|
230 |
-
def download_custom(placeholder_url
|
231 |
nonlocal dl_manager, cred_user, cred_pass
|
232 |
sources = _PLACEHOLDER_MAPS[placeholder_url]
|
233 |
-
tmp_paths
|
234 |
-
lengths
|
235 |
-
start_positions
|
236 |
for url in sources:
|
237 |
head = requests.head(url, auth=(cred_user, cred_pass))
|
238 |
if head.status_code == 401:
|
@@ -253,7 +248,7 @@ class VoxCeleb(datasets.GeneratorBasedBuilder):
|
|
253 |
else 0
|
254 |
)
|
255 |
|
256 |
-
def progress(q
|
257 |
with datasets.utils.logging.tqdm(
|
258 |
unit="B",
|
259 |
unit_scale=True,
|
@@ -309,23 +304,20 @@ class VoxCeleb(datasets.GeneratorBasedBuilder):
|
|
309 |
)
|
310 |
)
|
311 |
|
312 |
-
mapped_paths =
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
(
|
318 |
-
placeholder_key
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
download_custom,
|
327 |
-
)
|
328 |
-
),
|
329 |
)
|
330 |
|
331 |
return [
|
@@ -345,7 +337,7 @@ class VoxCeleb(datasets.GeneratorBasedBuilder):
|
|
345 |
),
|
346 |
]
|
347 |
|
348 |
-
def _generate_examples(self, paths
|
349 |
key = 0
|
350 |
for conf in paths:
|
351 |
dataset_id = "vox1" if conf == "audio1" else "vox2"
|
|
|
23 |
from itertools import repeat
|
24 |
from multiprocessing import Manager, Pool, Process
|
25 |
from pathlib import Path
|
|
|
26 |
from shutil import copyfileobj
|
|
|
27 |
|
28 |
import pandas as pd
|
29 |
import requests
|
|
|
112 |
|
113 |
|
114 |
def _mp_download(
|
115 |
+
url,
|
116 |
+
tmp_path,
|
117 |
+
cred_user,
|
118 |
+
cred_pass,
|
119 |
+
resume_pos,
|
120 |
+
length,
|
121 |
+
queue,
|
122 |
):
|
123 |
if length == resume_pos:
|
124 |
return
|
125 |
with open(tmp_path, "ab" if resume_pos else "wb") as tmp:
|
126 |
+
headers = {}
|
127 |
if resume_pos != 0:
|
128 |
headers["Range"] = f"bytes={resume_pos}-"
|
129 |
response = requests.get(
|
|
|
162 |
]
|
163 |
|
164 |
def _info(self):
|
165 |
+
features = {
|
166 |
+
"file": datasets.Value("string"),
|
167 |
+
"file_format": datasets.Value("string"),
|
168 |
+
"dataset_id": datasets.Value("string"),
|
169 |
+
"speaker_id": datasets.Value("string"),
|
170 |
+
"speaker_gender": datasets.Value("string"),
|
171 |
+
"video_id": datasets.Value("string"),
|
172 |
+
"clip_index": datasets.Value("int32"),
|
173 |
+
}
|
|
|
|
|
|
|
174 |
if self.config.name == "audio1":
|
175 |
features["speaker_name"] = datasets.Value("string")
|
176 |
features["speaker_nationality"] = datasets.Value("string")
|
|
|
191 |
targets = (
|
192 |
["audio1", "audio2"] if self.config.name == "audio" else [self.config.name]
|
193 |
)
|
194 |
+
cred_user = os.environ.get("HUGGING_FACE_VOX_CELEB_USER")
|
195 |
+
cred_pass = os.environ.get("HUGGING_FACE_VOX_CELEB_PASS")
|
196 |
creds_path = Path(
|
197 |
f"~/.huggingface/voxceleb_{self.VERSION}_credentials"
|
198 |
).expanduser()
|
|
|
222 |
json.dump((cred_user, cred_pass), creds)
|
223 |
saved_credentials = True
|
224 |
|
225 |
+
def download_custom(placeholder_url, path):
|
226 |
nonlocal dl_manager, cred_user, cred_pass
|
227 |
sources = _PLACEHOLDER_MAPS[placeholder_url]
|
228 |
+
tmp_paths = []
|
229 |
+
lengths = []
|
230 |
+
start_positions = []
|
231 |
for url in sources:
|
232 |
head = requests.head(url, auth=(cred_user, cred_pass))
|
233 |
if head.status_code == 401:
|
|
|
248 |
else 0
|
249 |
)
|
250 |
|
251 |
+
def progress(q, cur, total):
|
252 |
with datasets.utils.logging.tqdm(
|
253 |
unit="B",
|
254 |
unit_scale=True,
|
|
|
304 |
)
|
305 |
)
|
306 |
|
307 |
+
mapped_paths = dl_manager.extract(
|
308 |
+
dl_manager.download_custom(
|
309 |
+
dict(
|
310 |
+
(
|
311 |
+
placeholder_key,
|
312 |
+
dict(
|
313 |
+
(target, _URLS[target][placeholder_key])
|
314 |
+
for target in targets
|
315 |
+
),
|
316 |
+
)
|
317 |
+
for placeholder_key in ("placeholder", "test")
|
318 |
+
),
|
319 |
+
download_custom,
|
320 |
+
)
|
|
|
|
|
|
|
321 |
)
|
322 |
|
323 |
return [
|
|
|
337 |
),
|
338 |
]
|
339 |
|
340 |
+
def _generate_examples(self, paths, meta_paths):
|
341 |
key = 0
|
342 |
for conf in paths:
|
343 |
dataset_id = "vox1" if conf == "audio1" else "vox2"
|