dynamicworld / scripts /sync_bucket.py
fatmur's picture
Use Python for bucket uploads and downloads
699fff4 verified
Raw History Blame Contribute Delete
1.42 kB
"""Upload or download the Dynamic World raw and processed directories."""
import argparse
from pathlib import Path
from huggingface_hub import sync_bucket
BUCKET = "hf://buckets/fatmur/dynamicworld"
DATA_DIR = Path(__file__).resolve().parents[1]
def main() -> None:
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("direction", choices=("upload", "download"))
parser.add_argument("part", choices=("raw", "processed", "all"))
parser.add_argument(
"--data-dir",
type=Path,
default=DATA_DIR,
help="Local parent of raw/ and processed/",
)
parser.add_argument(
"--include",
action="append",
help="Glob relative to each selected folder (repeatable)",
)
parser.add_argument(
"--dry-run", action="store_true", help="Print the Hugging Face sync plan"
)
args = parser.parse_args()
folders = ("raw", "processed") if args.part == "all" else (args.part,)
for folder in folders:
local = str(args.data_dir / folder)
remote = f"{BUCKET}/{folder}"
source, dest = (
(local, remote) if args.direction == "upload" else (remote, local)
)
sync_bucket(
source,
dest,
include=args.include,
exclude=["*.partial.*"],
dry_run=args.dry_run,
)
if __name__ == "__main__":
main()