Spaces:
Runtime error
Runtime error
| from huggingface_hub import HfApi | |
| import os | |
| import sys | |
| def check_token(): | |
| """Check if HUGGINGFACE_TOKEN is properly set.""" | |
| token = os.environ.get("HUGGINGFACE_TOKEN") | |
| if not token: | |
| print("Error: HUGGINGFACE_TOKEN not found in environment variables.") | |
| print("Please ensure you have:") | |
| print("1. Created a .env file from .env.example") | |
| print("2. Added your Hugging Face token to the .env file") | |
| print("3. The token has write access to Spaces") | |
| sys.exit(1) | |
| return token | |
| # Check token before proceeding | |
| token = check_token() | |
| # Initialize the Hugging Face API | |
| try: | |
| api = HfApi(token=token) | |
| except Exception as e: | |
| print(f"Error initializing Hugging Face API: {e}") | |
| sys.exit(1) | |
| print("Starting upload to Hugging Face Space...") | |
| # Create a new Space if it doesn't exist | |
| try: | |
| api.create_repo( | |
| repo_id="nananie143/advanced-reasoning", | |
| repo_type="space", | |
| space_sdk="gradio", | |
| private=False | |
| ) | |
| except Exception as e: | |
| if "409" in str(e): # HTTP 409 Conflict - repo already exists | |
| print("Space already exists, continuing with upload...") | |
| else: | |
| print(f"Error creating Space: {e}") | |
| print("Please check your token permissions and network connection.") | |
| sys.exit(1) | |
| # Upload the files | |
| try: | |
| api.upload_folder( | |
| folder_path=".", | |
| repo_id="nananie143/advanced-reasoning", | |
| repo_type="space", | |
| ignore_patterns=["*.pyc", "__pycache__", ".git", ".env", "*.gguf"] | |
| ) | |
| print("Upload completed successfully!") | |
| except Exception as e: | |
| print(f"Error uploading files: {e}") | |
| print("\nTroubleshooting steps:") | |
| print("1. Check your internet connection") | |
| print("2. Verify your HUGGINGFACE_TOKEN has write access") | |
| print("3. Ensure you're not rate limited") | |
| print("4. Try again in a few minutes") | |
| sys.exit(1) | |