fix(space): mirror Space secret 'near' into HF_TOKEN for gated Hub models
Browse files
app.py
CHANGED
|
@@ -1,6 +1,19 @@
|
|
| 1 |
import os
|
| 2 |
import sys
|
| 3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
# ZeroGPU: must run before `import spaces`. Space Variables often leave NEAR_* at 300/1800; HF still rejects those.
|
| 5 |
_ZEROGPU_HF_CEILING_S = min(max(15, int(os.environ.get("NEAR_ZEROGPU_HF_CEILING_S", "60"))), 120)
|
| 6 |
for _ek in ("NEAR_ZEROGPU_MAX_SECONDS", "NEAR_ZEROGPU_DURATION_CAP"):
|
|
|
|
| 1 |
import os
|
| 2 |
import sys
|
| 3 |
|
| 4 |
+
# transformers/huggingface_hub authenticate gated repos via HF_TOKEN (or HUGGING_FACE_HUB_TOKEN).
|
| 5 |
+
# Space secrets become env vars named exactly like the secret: a secret named "near" sets "near",
|
| 6 |
+
# not HF_TOKEN, so Hub calls stay anonymous until we mirror it here.
|
| 7 |
+
if not os.environ.get("HF_TOKEN") and not os.environ.get("HUGGING_FACE_HUB_TOKEN"):
|
| 8 |
+
_hub_tok = (os.environ.get("near") or os.environ.get("NEAR") or "").strip()
|
| 9 |
+
if _hub_tok:
|
| 10 |
+
os.environ["HF_TOKEN"] = _hub_tok
|
| 11 |
+
print(
|
| 12 |
+
"[NeAR] HF_TOKEN unset; using Space secret 'near' as HF_TOKEN. "
|
| 13 |
+
"Prefer renaming that secret to HF_TOKEN (standard Hub env name).",
|
| 14 |
+
flush=True,
|
| 15 |
+
)
|
| 16 |
+
|
| 17 |
# ZeroGPU: must run before `import spaces`. Space Variables often leave NEAR_* at 300/1800; HF still rejects those.
|
| 18 |
_ZEROGPU_HF_CEILING_S = min(max(15, int(os.environ.get("NEAR_ZEROGPU_HF_CEILING_S", "60"))), 120)
|
| 19 |
for _ek in ("NEAR_ZEROGPU_MAX_SECONDS", "NEAR_ZEROGPU_DURATION_CAP"):
|