hf token
Browse files- src/streamlit_app.py +14 -3
src/streamlit_app.py
CHANGED
|
@@ -12,10 +12,21 @@ import pickle
|
|
| 12 |
import chromadb
|
| 13 |
from chromadb.utils import embedding_functions
|
| 14 |
|
| 15 |
-
hf_token = os.getenv("HF_TOKEN")
|
|
|
|
| 16 |
if hf_token:
|
| 17 |
-
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
BASE_DIR = "/tmp"
|
| 21 |
os.makedirs(BASE_DIR, exist_ok=True)
|
|
|
|
| 12 |
import chromadb
|
| 13 |
from chromadb.utils import embedding_functions
|
| 14 |
|
| 15 |
+
hf_token = os.getenv("HF_TOKEN")
|
| 16 |
+
|
| 17 |
if hf_token:
|
| 18 |
+
try:
|
| 19 |
+
# Use the official login function
|
| 20 |
+
login(token=hf_token)
|
| 21 |
+
st.success("Hugging Face token successfully validated (or cached).")
|
| 22 |
+
except Exception as e:
|
| 23 |
+
# This might reveal a more specific error than AxiosError
|
| 24 |
+
st.error(f"Hugging Face login failed (check token validity): {e}")
|
| 25 |
+
# Still set the environment variables for downstream libraries
|
| 26 |
+
os.environ["HF_TOKEN"] = hf_token
|
| 27 |
+
os.environ["HUGGINGFACE_HUB_TOKEN"] = hf_token
|
| 28 |
+
else:
|
| 29 |
+
st.warning("HF_TOKEN not found. Using anonymous access (may lead to 403 for private models).")
|
| 30 |
|
| 31 |
BASE_DIR = "/tmp"
|
| 32 |
os.makedirs(BASE_DIR, exist_ok=True)
|