updated-marshall-asr / push_to_hf.py
Pavan-salient's picture
Mirror TrySalient dataset with audio
ed119cc verified
"""Upload the prepared Westlake ASR dataset to Hugging Face."""
import argparse
import os
from pathlib import Path
from typing import Optional
from huggingface_hub import HfApi
def validate_paths(dataset_root: Path) -> None:
required = [dataset_root / "data" / "turns.jsonl"]
missing = [str(p) for p in required if not p.exists()]
if missing:
raise SystemExit(f"Dataset assets missing: {missing}")
def get_token(passed: Optional[str]) -> str:
token = passed or os.getenv("HUGGINGFACE_TOKEN")
if not token:
raise SystemExit("Hugging Face token not provided. Pass --token or set HUGGINGFACE_TOKEN.")
return token
def upload(dataset_root: Path, repo_id: str, token: str, commit_message: str, dry_run: bool, private: bool) -> None:
api = HfApi(token=token)
if dry_run:
print("[dry-run] would upload the following directories:")
for path in sorted(dataset_root.rglob("*")):
if path.is_file():
rel = path.relative_to(dataset_root)
print(f" {rel}")
return
repo_type = "dataset"
api.create_repo(repo_id=repo_id, repo_type=repo_type, token=token, exist_ok=True, private=private)
api.upload_folder(
repo_id=repo_id,
repo_type=repo_type,
folder_path=str(dataset_root),
commit_message=commit_message,
allow_patterns=None,
ignore_patterns=["*.mp3", "data/evaluations/**"],
)
print(f"Uploaded {dataset_root} to hf://datasets/{repo_id}")
def parse_args():
parser = argparse.ArgumentParser(description="Push Westlake ASR dataset to Hugging Face")
parser.add_argument("repo_id", help="Target dataset repo, e.g. org/westlake-asr")
parser.add_argument("--dataset-root", default=Path(__file__).resolve().parent, type=Path, help="Root directory to upload")
parser.add_argument("--token", help="Hugging Face access token")
parser.add_argument("--commit-message", default="Add Westlake ASR dataset", help="Commit message for upload")
parser.add_argument("--dry-run", action="store_true", help="List files without uploading")
parser.add_argument("--public", action="store_true", help="Create repository as public (default is private)")
return parser.parse_args()
def main():
args = parse_args()
dataset_root = args.dataset_root
validate_paths(dataset_root)
token = get_token(args.token)
commit_message = args.commit_message
private = not args.public
upload(dataset_root, args.repo_id, token, commit_message, args.dry_run, private)
if __name__ == "__main__":
main()