Spaces:
Build error
Build error
| import os | |
| import sys | |
| import requests | |
| import argparse | |
| def setup_huggingface_token(token=None): | |
| """ | |
| Set up the Hugging Face token for the Space. | |
| This script will help you test the token locally or configure it on Hugging Face. | |
| """ | |
| if not token: | |
| # Try to get token from environment | |
| token = os.environ.get("HF_TOKEN") | |
| if not token: | |
| token = os.environ.get("HUGGINGFACE_TOKEN") | |
| if not token: | |
| token = os.environ.get("HF_API_TOKEN") | |
| if not token: | |
| print("No token provided and no token found in environment variables.") | |
| print("To use this script, either:") | |
| print("1. Set the HF_TOKEN environment variable") | |
| print("2. Pass the token as an argument: python setup_token.py --token YOUR_TOKEN") | |
| return False | |
| # Test if token works by making a request to the API | |
| url = "https://huggingface.co/novateur/WavTokenizer-medium-speech-75tokens/resolve/main/wavtokenizer_mediumdata_frame75_3s_nq1_code4096_dim512_kmeans200_attn.yaml" | |
| headers = {"Authorization": f"Bearer {token}"} | |
| try: | |
| response = requests.head(url, headers=headers) | |
| if response.status_code == 200: | |
| print("✅ Token is valid and working!") | |
| print("\nTo set up this token on your Hugging Face Space:") | |
| print("1. Go to your Space settings") | |
| print("2. Navigate to 'Repository secrets'") | |
| print("3. Add a new secret with name 'HF_TOKEN' and the value of your token") | |
| print("\nYour app will automatically use this token when it starts up.") | |
| return True | |
| else: | |
| print(f"❌ Token validation failed with status code: {response.status_code}") | |
| return False | |
| except Exception as e: | |
| print(f"❌ Error validating token: {str(e)}") | |
| return False | |
| if __name__ == "__main__": | |
| parser = argparse.ArgumentParser(description="Set up Hugging Face token for your Space") | |
| parser.add_argument("--token", help="Your Hugging Face API token") | |
| args = parser.parse_args() | |
| setup_huggingface_token(args.token) |