File size: 594 Bytes
6caa2dc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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}")