Datasets:
michaelnetbiz
commited on
Commit
•
910be04
1
Parent(s):
f4b3ee0
Update scripts/prep_push_to_hf.py
Browse files- scripts/prep_push_to_hf.py +22 -22
scripts/prep_push_to_hf.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
#!/usr/bin/env python3
|
2 |
-
import
|
3 |
from pathlib import Path
|
4 |
|
5 |
import huggingface_hub
|
@@ -8,38 +8,38 @@ from datasets import Audio, Dataset
|
|
8 |
import pandas as pd
|
9 |
|
10 |
MAX_DURATION_IN_SECONDS = 10.0
|
|
|
11 |
|
12 |
|
13 |
def duration_filter(item):
|
14 |
return item < MAX_DURATION_IN_SECONDS
|
15 |
|
16 |
|
|
|
|
|
|
|
|
|
17 |
repo_dir = Path(__file__).resolve().parent.parent
|
18 |
-
data_dir =
|
19 |
-
kendex_dir =
|
20 |
-
audio_dir =
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
}
|
33 |
-
)
|
34 |
)
|
35 |
|
|
|
36 |
dataset = dataset.cast_column("audio", Audio(sampling_rate=16_000))
|
37 |
-
|
38 |
-
dataset = dataset.filter(
|
39 |
-
lambda x: False if len(x) >= 500 else True, input_columns=["text"]
|
40 |
-
)
|
41 |
dataset = dataset.filter(duration_filter, input_columns=["duration"])
|
42 |
-
|
43 |
dataset = dataset.remove_columns(["duration"])
|
44 |
|
45 |
huggingface_hub.login()
|
|
|
1 |
#!/usr/bin/env python3
|
2 |
+
from os.path import join
|
3 |
from pathlib import Path
|
4 |
|
5 |
import huggingface_hub
|
|
|
8 |
import pandas as pd
|
9 |
|
10 |
MAX_DURATION_IN_SECONDS = 10.0
|
11 |
+
MAX_LEN = 500
|
12 |
|
13 |
|
14 |
def duration_filter(item):
|
15 |
return item < MAX_DURATION_IN_SECONDS
|
16 |
|
17 |
|
18 |
+
def text_filter(item):
|
19 |
+
return len(item) < MAX_LEN
|
20 |
+
|
21 |
+
|
22 |
repo_dir = Path(__file__).resolve().parent.parent
|
23 |
+
data_dir = join(repo_dir, "data")
|
24 |
+
kendex_dir = join(data_dir, "Kendex")
|
25 |
+
audio_dir = join(kendex_dir, "wavs")
|
26 |
+
|
27 |
+
metadata = pd.read_csv(join(kendex_dir, "metadata.csv"), delimiter="|", header=None)
|
28 |
+
wavs = pd.Series([join(audio_dir, f"{f}.wav") for f in metadata[0]])
|
29 |
+
|
30 |
+
df = pd.DataFrame(
|
31 |
+
{
|
32 |
+
"audio": wavs,
|
33 |
+
"file": wavs,
|
34 |
+
"text": wavs[1],
|
35 |
+
"duration": [librosa.get_duration(path=a) for a in wavs],
|
36 |
+
}
|
|
|
|
|
37 |
)
|
38 |
|
39 |
+
dataset = Dataset.from_pandas(df)
|
40 |
dataset = dataset.cast_column("audio", Audio(sampling_rate=16_000))
|
41 |
+
dataset = dataset.filter(text_filter, input_columns=["text"])
|
|
|
|
|
|
|
42 |
dataset = dataset.filter(duration_filter, input_columns=["duration"])
|
|
|
43 |
dataset = dataset.remove_columns(["duration"])
|
44 |
|
45 |
huggingface_hub.login()
|