"""Download every upstream file listed in opusdb.sources into RAW_DIR (resumable).""" import os import sys from concurrent.futures import ThreadPoolExecutor sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..")) from huggingface_hub import hf_hub_download # noqa: E402 from opusdb.sources import SOURCES # noqa: E402 RAW_DIR = os.environ.get("OPUSDB_RAW", "raw") def fetch(job): repo, path = job local = hf_hub_download(repo, path, repo_type="dataset", local_dir=os.path.join(RAW_DIR, repo.replace("/", "__"))) print(f"ok {repo}/{path} {os.path.getsize(local)/1e6:.1f} MB", flush=True) return local if __name__ == "__main__": jobs = sorted({(s.repo, f) for s in SOURCES for f in s.files}, key=lambda j: j[1].startswith(("sample", "data/tur"))) with ThreadPoolExecutor(4) as pool: list(pool.map(fetch, jobs)) print("DONE")