test key
Browse files- test_auth.py +18 -0
test_auth.py
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
from huggingface_hub import login, HfApi
|
| 3 |
+
|
| 4 |
+
# Authenticate with Hugging Face using the token from Space secrets
|
| 5 |
+
hf_token = os.getenv("HF_TOKEN")
|
| 6 |
+
if hf_token:
|
| 7 |
+
login(token=hf_token)
|
| 8 |
+
print("Authenticated with Hugging Face token.")
|
| 9 |
+
else:
|
| 10 |
+
print("HF_TOKEN not found in environment variables. Please set it in Space secrets.")
|
| 11 |
+
|
| 12 |
+
# Test access to the gated repo
|
| 13 |
+
try:
|
| 14 |
+
api = HfApi()
|
| 15 |
+
model_info = api.model_info("meta-llama/Llama-2-7b-hf")
|
| 16 |
+
print("Successfully accessed LLaMA-2-7b-hf repo:", model_info.id)
|
| 17 |
+
except Exception as e:
|
| 18 |
+
print(f"Error accessing gated repo: {e}")
|