Use HF_TOKEN for private model download
Browse files30 unmodified lines31323334353637383940414230 unmodified lines_lock = threading.Lock()def _fetch(name: str, url: str):dst = MODELS / nameif dst.exists() and dst.stat().st_size > 10_000_000:returntmp = dst.with_suffix(dst.suffix + ".part")req = urllib.request.Request(url, headers={"User-Agent": "pocket-zimage/1.0"})with urllib.request.urlopen(req) as r, open(tmp, "wb") as f:total = int(r.headers.get("Content-Length") or 0)done = 030 unmodified lines31323334353637383940414243444546474830 unmodified lines_lock = threading.Lock()HF_TOKEN = os.environ.get("HF_TOKEN") or os.environ.get("HUGGING_FACE_HUB_TOKEN")def _fetch(name: str, url: str):dst = MODELS / nameif dst.exists() and dst.stat().st_size > 10_000_000:returntmp = dst.with_suffix(dst.suffix + ".part")hdr = {"User-Agent": "pocket-zimage/1.0"}if HF_TOKEN and "huggingface.co" in url:hdr["Authorization"] = "Bearer " + HF_TOKENreq = urllib.request.Request(url, headers=hdr)with urllib.request.urlopen(req) as r, open(tmp, "wb") as f:total = int(r.headers.get("Content-Length") or 0)done = 0
app.py+7-1