muhammadhasnain100 Cursor commited on
Commit
a77098c
·
1 Parent(s): d52695b

Remove Hub token from repo; use Space secret HF_TOKEN (HF push policy)

Browse files
Files changed (2) hide show
  1. README.md +6 -0
  2. space_credentials.py +15 -6
README.md CHANGED
@@ -10,3 +10,9 @@ app_port: 7860
10
  # COMSATS Chatbot — FastAPI backend
11
 
12
  Docker Space running **FastAPI** + **Uvicorn** on port **7860**. Open `/docs` for Swagger.
 
 
 
 
 
 
 
10
  # COMSATS Chatbot — FastAPI backend
11
 
12
  Docker Space running **FastAPI** + **Uvicorn** on port **7860**. Open `/docs` for Swagger.
13
+
14
+ ## Secrets (required for embedding downloads)
15
+
16
+ In the Space **Settings → Variables and secrets**, add a **secret** named **`HF_TOKEN`** with a Hub token from [your tokens page](https://huggingface.co/settings/tokens) (read access is enough). The app maps this to `HUGGING_FACE_HUB_TOKEN` at startup via `space_credentials.py` — no `.env` file in the repo.
17
+
18
+ **First boot** may take several minutes: dependencies install, the BGE embedding model downloads, and the FAISS index is built from the bundled CSV files (nothing under `faiss_kb/*.faiss` is committed).
space_credentials.py CHANGED
@@ -1,9 +1,18 @@
1
- """Runtime credentials for Hugging Face Spaces (no .env). Import this before huggingface_hub loads."""
 
2
 
3
- import os
 
 
 
4
 
5
- # Hub token for embedding/model downloads (rw token from HF Space owner).
6
- HF_TOKEN = ""
 
 
 
7
 
8
- for _key in ("HF_TOKEN", "HUGGING_FACE_HUB_TOKEN", "HUGGINGFACEHUB_API_TOKEN"):
9
- os.environ.setdefault(_key, HF_TOKEN)
 
 
 
1
+ """
2
+ Hugging Face Hub auth for model downloads (embeddings, etc.).
3
 
4
+ Do not put real tokens in this repo — HF blocks pushes that contain secrets.
5
+
6
+ For the Space: Settings → Variables and secrets → add secret name `HF_TOKEN`
7
+ (value = a read token from https://huggingface.co/settings/tokens).
8
 
9
+ This module mirrors that secret into env vars the Hugging Face libraries expect.
10
+ No .env file is required.
11
+ """
12
+
13
+ import os
14
 
15
+ _token = (os.environ.get("HF_TOKEN") or "").strip()
16
+ if _token:
17
+ for _key in ("HF_TOKEN", "HUGGING_FACE_HUB_TOKEN", "HUGGINGFACEHUB_API_TOKEN"):
18
+ os.environ.setdefault(_key, _token)