Spaces:
Runtime error
Runtime error
Commit ·
a77098c
1
Parent(s): d52695b
Remove Hub token from repo; use Space secret HF_TOKEN (HF push policy)
Browse files- README.md +6 -0
- 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 |
-
"""
|
|
|
|
| 2 |
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
-
|
| 9 |
-
|
|
|
|
|
|
|
|
|
| 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)
|