SeaWolf-AI commited on
Commit
2f85585
·
verified ·
1 Parent(s): 4e09904

Use HF_TOKEN for private model download

Browse files
Files changed (1) hide show
  1. app.py +7 -1
app.py CHANGED
@@ -31,12 +31,18 @@ _state = {"ready": False, "msg": "idle", "pct": 0}
31
  _lock = threading.Lock()
32
 
33
 
 
 
 
34
  def _fetch(name: str, url: str):
35
  dst = MODELS / name
36
  if dst.exists() and dst.stat().st_size > 10_000_000:
37
  return
38
  tmp = dst.with_suffix(dst.suffix + ".part")
39
- req = urllib.request.Request(url, headers={"User-Agent": "pocket-zimage/1.0"})
 
 
 
40
  with urllib.request.urlopen(req) as r, open(tmp, "wb") as f:
41
  total = int(r.headers.get("Content-Length") or 0)
42
  done = 0
 
31
  _lock = threading.Lock()
32
 
33
 
34
+ HF_TOKEN = os.environ.get("HF_TOKEN") or os.environ.get("HUGGING_FACE_HUB_TOKEN")
35
+
36
+
37
  def _fetch(name: str, url: str):
38
  dst = MODELS / name
39
  if dst.exists() and dst.stat().st_size > 10_000_000:
40
  return
41
  tmp = dst.with_suffix(dst.suffix + ".part")
42
+ hdr = {"User-Agent": "pocket-zimage/1.0"}
43
+ if HF_TOKEN and "huggingface.co" in url:
44
+ hdr["Authorization"] = "Bearer " + HF_TOKEN
45
+ req = urllib.request.Request(url, headers=hdr)
46
  with urllib.request.urlopen(req) as r, open(tmp, "wb") as f:
47
  total = int(r.headers.get("Content-Length") or 0)
48
  done = 0