From 9985d98bf49db5a39ce50769bebaf7f6b3b8d508 Mon Sep 17 00:00:00 2001 From: Michael Treadgold Date: Thu, 18 Jun 2026 20:04:18 +1200 Subject: [PATCH] Add weights download script for repos without LFS support --- download_weights.py | 72 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 download_weights.py diff --git a/download_weights.py b/download_weights.py new file mode 100644 index 0000000..ad3d1d8 --- /dev/null +++ b/download_weights.py @@ -0,0 +1,72 @@ +"""Download Inflect-Nano-v1 model weights from HuggingFace. + +Run this once after cloning the repo: + python download_weights.py +""" +from __future__ import annotations + +import sys +from pathlib import Path + +# Use requests or urllib — try both +try: + import requests + _has_requests = True +except ImportError: + import urllib.request + import urllib.error + _has_requests = False + +WEIGHTS_DIR = Path(__file__).resolve().parent / "weights" +HF_BASE = "https://huggingface.co/owensong/Inflect-Nano-v1/resolve/main/weights" + +FILES = [ + "inflect_nano_v1_acoustic.pt", + "inflect_nano_v1_vocoder.pt", +] + + +def download_file(url: str, dest: Path) -> None: + dest.parent.mkdir(parents=True, exist_ok=True) + print(f"Downloading {dest.name}...", end=" ", flush=True) + + if _has_requests: + resp = requests.get(url, stream=True) + resp.raise_for_status() + total = int(resp.headers.get("content-length", 0)) + with dest.open("wb") as f: + downloaded = 0 + for chunk in resp.iter_content(chunk_size=8192): + f.write(chunk) + downloaded += len(chunk) + if total: + pct = downloaded * 100 // total + print(f"\rDownloading {dest.name}... {pct}%", end="", flush=True) + print(" done.") + else: + urllib.request.urlretrieve(url, str(dest)) + print("done.") + + +def main() -> None: + missing = [f for f in FILES if not (WEIGHTS_DIR / f).is_file()] + if not missing: + print("All weights already present.") + return + + print(f"Missing {len(missing)} weight file(s). Downloading from HuggingFace...\n") + for filename in missing: + url = f"{HF_BASE}/{filename}" + dest = WEIGHTS_DIR / filename + try: + download_file(url, dest) + except Exception as e: + print(f"\n FAILED: {e}") + print(f" Manual download: {url}") + sys.exit(1) + + print(f"\nAll weights downloaded to {WEIGHTS_DIR}") + + +if __name__ == "__main__": + main()