benmcewen commited on
Commit
8f92565
·
verified ·
1 Parent(s): 8368171

Add files using upload-large-folder tool

Browse files
Files changed (3) hide show
  1. .gitignore +0 -0
  2. WABAD.py +71 -71
  3. __init__.py +0 -0
.gitignore ADDED
File without changes
WABAD.py CHANGED
@@ -1,72 +1,72 @@
1
- import datasets
2
- import pandas as pd
3
- import os
4
- import ast
5
-
6
-
7
- class WABADBuilderConfig(datasets.BuilderConfig):
8
- def __init__(self, location_dir, **kwargs):
9
- super().__init__(**kwargs)
10
- self.location_dir = location_dir
11
-
12
- class WABADDataset(datasets.GeneratorBasedBuilder):
13
- BUILDER_CONFIGS = [
14
- WABADBuilderConfig(name="BAM", location_dir="BAM", description="BAM location"),
15
- WABADBuilderConfig(name="ARD", location_dir="ARD", description="ARD location"),
16
- # add more locations here
17
- ]
18
-
19
- def _info(self):
20
- return datasets.DatasetInfo(
21
- features=datasets.Features({
22
- "audio": datasets.Audio(),
23
- "labels": datasets.Sequence(datasets.Value("int32")),
24
- "site_ID": datasets.Value("string"),
25
- # any other metadata
26
- })
27
- )
28
-
29
- def _split_generators(self, dl_manager):
30
- config_dir = self.config.location_dir
31
-
32
- # Use the correct dataset URL format and download specific files
33
- train_url = f"https://huggingface.co/datasets/benmcewen/WABAD/resolve/main/{config_dir}/{config_dir}_metadata_train.parquet"
34
- test_url = f"https://huggingface.co/datasets/benmcewen/WABAD/resolve/main/{config_dir}/{config_dir}_metadata_test.parquet"
35
-
36
- # Download the parquet files
37
- train_file = dl_manager.download(train_url)
38
- test_file = dl_manager.download(test_url)
39
-
40
- return [
41
- datasets.SplitGenerator(
42
- name=datasets.Split.TRAIN,
43
- gen_kwargs={
44
- "parquet_file": train_file,
45
- "config_dir": config_dir
46
- },
47
- ),
48
- datasets.SplitGenerator(
49
- name=datasets.Split.TEST,
50
- gen_kwargs={
51
- "parquet_file": test_file,
52
- "config_dir": config_dir
53
- },
54
- )
55
- ]
56
-
57
- def _generate_examples(self, parquet_file, config_dir):
58
- df = pd.read_parquet(parquet_file)
59
- for idx, row in df.iterrows():
60
- # Download audio file on demand
61
- audio_url = f"https://huggingface.co/datasets/benmcewen/WABAD/resolve/main/{config_dir}/audio/{os.path.basename(row['filepath'])}"
62
-
63
- labels = row["labels"]
64
- if isinstance(labels, str):
65
- labels = ast.literal_eval(labels)
66
-
67
- yield idx, {
68
- "audio": {"path": audio_url, "bytes": None}, # Let datasets handle the download
69
- "labels": labels,
70
- "site_ID": row.get("site_ID", self.config.name),
71
- # other metadata
72
  }
 
1
+ import datasets
2
+ import pandas as pd
3
+ import os
4
+ import ast
5
+
6
+
7
+ class WABADBuilderConfig(datasets.BuilderConfig):
8
+ def __init__(self, location_dir, **kwargs):
9
+ super().__init__(**kwargs)
10
+ self.location_dir = location_dir
11
+
12
+ class WABADDataset(datasets.GeneratorBasedBuilder):
13
+ BUILDER_CONFIGS = [
14
+ WABADBuilderConfig(name="BAM", location_dir="BAM", description="BAM location"),
15
+ WABADBuilderConfig(name="ARD", location_dir="ARD", description="ARD location"),
16
+ # add more locations here
17
+ ]
18
+
19
+ def _info(self):
20
+ return datasets.DatasetInfo(
21
+ features=datasets.Features({
22
+ "audio": datasets.Audio(),
23
+ "labels": datasets.Sequence(datasets.Value("int32")),
24
+ "site_ID": datasets.Value("string"),
25
+ # any other metadata
26
+ })
27
+ )
28
+
29
+ def _split_generators(self, dl_manager):
30
+ config_dir = self.config.location_dir
31
+
32
+ # Use the correct dataset URL format and download specific files
33
+ train_url = f"https://huggingface.co/datasets/benmcewen/WABAD/resolve/main/{config_dir}/{config_dir}_metadata_train.parquet"
34
+ test_url = f"https://huggingface.co/datasets/benmcewen/WABAD/resolve/main/{config_dir}/{config_dir}_metadata_test.parquet"
35
+
36
+ # Download the parquet files
37
+ train_file = dl_manager.download(train_url)
38
+ test_file = dl_manager.download(test_url)
39
+
40
+ return [
41
+ datasets.SplitGenerator(
42
+ name=datasets.Split.TRAIN,
43
+ gen_kwargs={
44
+ "parquet_file": train_file,
45
+ "config_dir": config_dir
46
+ },
47
+ ),
48
+ datasets.SplitGenerator(
49
+ name=datasets.Split.TEST,
50
+ gen_kwargs={
51
+ "parquet_file": test_file,
52
+ "config_dir": config_dir
53
+ },
54
+ )
55
+ ]
56
+
57
+ def _generate_examples(self, parquet_file, config_dir):
58
+ df = pd.read_parquet(parquet_file)
59
+ for idx, row in df.iterrows():
60
+ # Download audio file on demand
61
+ audio_url = f"https://huggingface.co/datasets/benmcewen/WABAD/resolve/main/{config_dir}/audio/{os.path.basename(row['filepath'])}"
62
+
63
+ labels = row["labels"]
64
+ if isinstance(labels, str):
65
+ labels = ast.literal_eval(labels)
66
+
67
+ yield idx, {
68
+ "audio": {"path": audio_url, "bytes": None}, # Let datasets handle the download
69
+ "labels": labels,
70
+ "site_ID": row.get("site_ID", self.config.name),
71
+ # other metadata
72
  }
__init__.py ADDED
File without changes