backend / space_credentials.py
muhammadhasnain100's picture
Cursor
Remove Hub token from repo; use Space secret HF_TOKEN (HF push policy)
a77098c
Raw History Blame Contribute Delete
611 Bytes
"""
Hugging Face Hub auth for model downloads (embeddings, etc.).
Do not put real tokens in this repo — HF blocks pushes that contain secrets.
For the Space: Settings → Variables and secrets → add secret name `HF_TOKEN`
(value = a read token from https://huggingface.co/settings/tokens).
This module mirrors that secret into env vars the Hugging Face libraries expect.
No .env file is required.
"""
import os
_token = (os.environ.get("HF_TOKEN") or "").strip()
if _token:
for _key in ("HF_TOKEN", "HUGGING_FACE_HUB_TOKEN", "HUGGINGFACEHUB_API_TOKEN"):
os.environ.setdefault(_key, _token)