Datasets:
Claude Opus 5.5
FreeTZAN: 1,200 clips (audio/<split>/<genre>/), metadata, scripts, and dataset card
9bd1d61 Download scripts/make_hf_dataset.py from gclef-cmu/freetzan: direct link, hf CLI and curl.
- Browser
- Download file 3.01 kB
-
https://huggingface.co/datasets/gclef-cmu/freetzan/resolve/main/scripts/make_hf_dataset.py
- Command line
-
hf download hf://datasets/gclef-cmu/freetzan/scripts/make_hf_dataset.py
-
curl -L -o make_hf_dataset.py https://huggingface.co/datasets/gclef-cmu/freetzan/resolve/main/scripts/make_hf_dataset.py
3.01 kB
| # /// script | |
| # requires-python = ">=3.10" | |
| # dependencies = ["pandas>=2"] | |
| # /// | |
| """Assemble the Hugging Face Hub copy of FreeTZAN (https://huggingface.co/datasets/gclef-cmu/freetzan). | |
| The Hub repo mirrors this repository plus the audio (audio/<split>/<genre>/<track_id>.mp3, not in git), | |
| and adds: | |
| audio/<split>/metadata.csv that split's rows of metadata.csv, with `file_name` relative to the folder; | |
| the Hub dataset viewer and datasets.load_dataset read the clips through these | |
| README.md this README.md with a YAML dataset-card header that maps audio/train, | |
| audio/valid, audio/test to the Hub splits train, validation, test | |
| Writes into --out (a clone of the Hub repo), replacing audio/, scripts/ and resources/ there. Push with | |
| git + git-lfs (mp3 files are LFS-tracked by the Hub's default .gitattributes). | |
| Usage: uv run scripts/make_hf_dataset.py --out /path/to/hub/clone | |
| """ | |
| import argparse | |
| import hashlib | |
| import shutil | |
| from pathlib import Path | |
| import pandas as pd | |
| REPO = Path(__file__).resolve().parent.parent | |
| SPLITS = ['train', 'valid', 'test'] | |
| MIRROR = ['LICENSE', 'metadata.csv', 'checksums.sha1', 'scripts/build_freetzan.py', 'scripts/find_duplicates.py', | |
| 'scripts/extract_features.py', 'scripts/run_baselines.py', 'scripts/make_hf_dataset.py', | |
| 'resources/exclusions.csv', 'resources/duplicates.csv', 'resources/baselines.csv'] | |
| CARD = """--- | |
| pretty_name: FreeTZAN | |
| license: other | |
| license_name: per-track-creative-commons | |
| license_link: LICENSE | |
| task_categories: | |
| - audio-classification | |
| tags: | |
| - music | |
| - genre-classification | |
| size_categories: | |
| - 1K<n<10K | |
| configs: | |
| - config_name: default | |
| data_files: | |
| - split: train | |
| path: audio/train/** | |
| - split: validation | |
| path: audio/valid/** | |
| - split: test | |
| path: audio/test/** | |
| --- | |
| """ | |
| def main(): | |
| ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter) | |
| ap.add_argument('--out', required=True) | |
| args = ap.parse_args() | |
| out = Path(args.out) | |
| md = pd.read_csv(REPO / 'metadata.csv') | |
| assert set(md.split) == set(SPLITS) | |
| for d in ('audio', 'data', 'scripts', 'resources'): | |
| shutil.rmtree(out / d, ignore_errors=True) | |
| for f in MIRROR: | |
| (out / f).parent.mkdir(parents=True, exist_ok=True) | |
| shutil.copy2(REPO / f, out / f) | |
| for p, sha1 in zip(md.path, md.sha1): | |
| b = (REPO / p).read_bytes() | |
| assert hashlib.sha1(b).hexdigest() == sha1, p | |
| (out / p).parent.mkdir(parents=True, exist_ok=True) | |
| (out / p).write_bytes(b) | |
| for split in SPLITS: | |
| rows = md.split == split | |
| d = md[rows].drop(columns='path') | |
| d.insert(0, 'file_name', md.path[rows].str.removeprefix(f'audio/{split}/')) | |
| d.to_csv(out / 'audio' / split / 'metadata.csv', index=False) | |
| print(f'{split}: {len(d)} clips') | |
| (out / 'README.md').write_text(CARD + (REPO / 'README.md').read_text()) | |
| if __name__ == '__main__': | |
| main() | |