"""Fetch Breeze inference code + suite handler without apt/curl. The pytorch runtime image has no curl, and apt-get ca-certificates dies with exit 22 on HF Inference Endpoints. urllib is already on the image. """ from __future__ import annotations import io import os import shutil import tarfile import urllib.request DEST = "/opt/breeze-tts" CODE_TGZ = "https://codeload.github.com/breezeblue-ai/breeze-tts/tar.gz/refs/heads/main" HANDLER = "https://huggingface.co/copperscout1/breeze-tts-2-handler/resolve/main" FILES = ("serve.py", "generate.py", "handler.py") def fetch(url: str) -> bytes: req = urllib.request.Request(url, headers={"User-Agent": "vividlex-breeze-tts"}) with urllib.request.urlopen(req, timeout=120) as res: return res.read() def main() -> None: os.makedirs(DEST, exist_ok=True) raw = fetch(CODE_TGZ) with tarfile.open(fileobj=io.BytesIO(raw), mode="r:gz") as tar: tar.extractall("/tmp") src = "/tmp/breeze-tts-main" if not os.path.isdir(src): names = [n for n in os.listdir("/tmp") if n.startswith("breeze-tts")] if not names: raise RuntimeError("breeze-tts tarball did not unpack") src = os.path.join("/tmp", names[0]) for name in os.listdir(src): dest = os.path.join(DEST, name) if os.path.exists(dest): if os.path.isdir(dest): shutil.rmtree(dest) else: os.remove(dest) shutil.move(os.path.join(src, name), dest) for name in FILES: path = os.path.join(DEST, name) with open(path, "wb") as fh: fh.write(fetch(f"{HANDLER}/{name}")) print(f"wrote {path}", flush=True) print("bootstrap ok", flush=True) if __name__ == "__main__": main()