import os | |
from huggingface_hub import login, HfApi | |
# Authenticate with Hugging Face using the token from Space secrets | |
hf_token = os.getenv("HF_TOKEN") | |
if hf_token: | |
login(token=hf_token) | |
print("Authenticated with Hugging Face token.") | |
else: | |
print("HF_TOKEN not found in environment variables. Please set it in Space secrets.") | |
# Test access to the gated repo | |
try: | |
api = HfApi() | |
model_info = api.model_info("meta-llama/Llama-2-7b-hf") | |
print("Successfully accessed LLaMA-2-7b-hf repo:", model_info.id) | |
except Exception as e: | |
print(f"Error accessing gated repo: {e}") |