File size: 1,418 Bytes
699fff4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
"""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()