Spaces:
				
			
			
	
			
			
		Runtime error
		
	
	
	
			
			
	
	
	
	
		
		
		Runtime error
		
	Upload folder using huggingface_hub
Browse files- .env.example +13 -1
- upload_to_hub.py +43 -10
    	
        .env.example
    CHANGED
    
    | @@ -1,4 +1,6 @@ | |
| 1 | 
             
            # Hugging Face Configuration
         | 
|  | |
|  | |
| 2 | 
             
            HUGGINGFACE_TOKEN=your_huggingface_token_here
         | 
| 3 |  | 
| 4 | 
             
            # System Configuration
         | 
| @@ -29,9 +31,13 @@ HEALTH_CHECK_INTERVAL=30 | |
| 29 | 
             
            PERFORMANCE_LOG_RETENTION_DAYS=7
         | 
| 30 |  | 
| 31 | 
             
            # API Keys
         | 
|  | |
|  | |
|  | |
|  | |
|  | |
| 32 | 
             
            OPENAI_API_KEY=your_openai_api_key
         | 
| 33 | 
             
            GROQ_API_KEY=your_groq_api_key
         | 
| 34 | 
            -
            HUGGINGFACE_API_KEY=your_huggingface_api_key
         | 
| 35 |  | 
| 36 | 
             
            # Service Configuration
         | 
| 37 | 
             
            PORT=7860
         | 
| @@ -76,3 +82,9 @@ ENABLE_PORTFOLIO_OPTIMIZATION=True | |
| 76 | 
             
            ENABLE_MARKET_ANALYSIS=True
         | 
| 77 | 
             
            ENABLE_MONETIZATION_STRATEGY=True
         | 
| 78 | 
             
            ENABLE_VENTURE_ANALYSIS=True
         | 
|  | |
|  | |
|  | |
|  | |
|  | |
|  | 
|  | |
| 1 | 
             
            # Hugging Face Configuration
         | 
| 2 | 
            +
            # Get your token from https://huggingface.co/settings/tokens
         | 
| 3 | 
            +
            # Make sure to select "WRITE" access when creating the token
         | 
| 4 | 
             
            HUGGINGFACE_TOKEN=your_huggingface_token_here
         | 
| 5 |  | 
| 6 | 
             
            # System Configuration
         | 
|  | |
| 31 | 
             
            PERFORMANCE_LOG_RETENTION_DAYS=7
         | 
| 32 |  | 
| 33 | 
             
            # API Keys
         | 
| 34 | 
            +
            # Get your Hugging Face token from https://huggingface.co/settings/tokens
         | 
| 35 | 
            +
            # Required for uploading to Spaces - must have WRITE access
         | 
| 36 | 
            +
            HUGGINGFACE_API_KEY=your_huggingface_api_key
         | 
| 37 | 
            +
             | 
| 38 | 
            +
            # Optional API keys for additional features
         | 
| 39 | 
             
            OPENAI_API_KEY=your_openai_api_key
         | 
| 40 | 
             
            GROQ_API_KEY=your_groq_api_key
         | 
|  | |
| 41 |  | 
| 42 | 
             
            # Service Configuration
         | 
| 43 | 
             
            PORT=7860
         | 
|  | |
| 82 | 
             
            ENABLE_MARKET_ANALYSIS=True
         | 
| 83 | 
             
            ENABLE_MONETIZATION_STRATEGY=True
         | 
| 84 | 
             
            ENABLE_VENTURE_ANALYSIS=True
         | 
| 85 | 
            +
             | 
| 86 | 
            +
            # Note: After copying this file to .env:
         | 
| 87 | 
            +
            # 1. Replace 'your_huggingface_token_here' with your actual token
         | 
| 88 | 
            +
            # 2. Make sure your token has WRITE access for Spaces
         | 
| 89 | 
            +
            # 3. Keep this .env.example file for reference
         | 
| 90 | 
            +
            # 4. Never commit your actual .env file with real tokens
         | 
    	
        upload_to_hub.py
    CHANGED
    
    | @@ -1,8 +1,28 @@ | |
| 1 | 
             
            from huggingface_hub import HfApi
         | 
| 2 | 
             
            import os
         | 
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
| 3 |  | 
| 4 | 
             
            # Initialize the Hugging Face API
         | 
| 5 | 
            -
             | 
|  | |
|  | |
|  | |
|  | |
| 6 |  | 
| 7 | 
             
            print("Starting upload to Hugging Face Space...")
         | 
| 8 |  | 
| @@ -15,14 +35,27 @@ try: | |
| 15 | 
             
                    private=False
         | 
| 16 | 
             
                )
         | 
| 17 | 
             
            except Exception as e:
         | 
| 18 | 
            -
                 | 
|  | |
|  | |
|  | |
|  | |
|  | |
| 19 |  | 
| 20 | 
             
            # Upload the files
         | 
| 21 | 
            -
             | 
| 22 | 
            -
                 | 
| 23 | 
            -
             | 
| 24 | 
            -
             | 
| 25 | 
            -
             | 
| 26 | 
            -
             | 
| 27 | 
            -
             | 
| 28 | 
            -
            print("Upload completed successfully!")
         | 
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | 
|  | |
| 1 | 
             
            from huggingface_hub import HfApi
         | 
| 2 | 
             
            import os
         | 
| 3 | 
            +
            import sys
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            def check_token():
         | 
| 6 | 
            +
                """Check if HUGGINGFACE_TOKEN is properly set."""
         | 
| 7 | 
            +
                token = os.environ.get("HUGGINGFACE_TOKEN")
         | 
| 8 | 
            +
                if not token:
         | 
| 9 | 
            +
                    print("Error: HUGGINGFACE_TOKEN not found in environment variables.")
         | 
| 10 | 
            +
                    print("Please ensure you have:")
         | 
| 11 | 
            +
                    print("1. Created a .env file from .env.example")
         | 
| 12 | 
            +
                    print("2. Added your Hugging Face token to the .env file")
         | 
| 13 | 
            +
                    print("3. The token has write access to Spaces")
         | 
| 14 | 
            +
                    sys.exit(1)
         | 
| 15 | 
            +
                return token
         | 
| 16 | 
            +
             | 
| 17 | 
            +
            # Check token before proceeding
         | 
| 18 | 
            +
            token = check_token()
         | 
| 19 |  | 
| 20 | 
             
            # Initialize the Hugging Face API
         | 
| 21 | 
            +
            try:
         | 
| 22 | 
            +
                api = HfApi(token=token)
         | 
| 23 | 
            +
            except Exception as e:
         | 
| 24 | 
            +
                print(f"Error initializing Hugging Face API: {e}")
         | 
| 25 | 
            +
                sys.exit(1)
         | 
| 26 |  | 
| 27 | 
             
            print("Starting upload to Hugging Face Space...")
         | 
| 28 |  | 
|  | |
| 35 | 
             
                    private=False
         | 
| 36 | 
             
                )
         | 
| 37 | 
             
            except Exception as e:
         | 
| 38 | 
            +
                if "409" in str(e):  # HTTP 409 Conflict - repo already exists
         | 
| 39 | 
            +
                    print("Space already exists, continuing with upload...")
         | 
| 40 | 
            +
                else:
         | 
| 41 | 
            +
                    print(f"Error creating Space: {e}")
         | 
| 42 | 
            +
                    print("Please check your token permissions and network connection.")
         | 
| 43 | 
            +
                    sys.exit(1)
         | 
| 44 |  | 
| 45 | 
             
            # Upload the files
         | 
| 46 | 
            +
            try:
         | 
| 47 | 
            +
                api.upload_folder(
         | 
| 48 | 
            +
                    folder_path=".",
         | 
| 49 | 
            +
                    repo_id="nananie143/advanced-reasoning",
         | 
| 50 | 
            +
                    repo_type="space",
         | 
| 51 | 
            +
                    ignore_patterns=["*.pyc", "__pycache__", ".git", ".env", "*.gguf"]
         | 
| 52 | 
            +
                )
         | 
| 53 | 
            +
                print("Upload completed successfully!")
         | 
| 54 | 
            +
            except Exception as e:
         | 
| 55 | 
            +
                print(f"Error uploading files: {e}")
         | 
| 56 | 
            +
                print("\nTroubleshooting steps:")
         | 
| 57 | 
            +
                print("1. Check your internet connection")
         | 
| 58 | 
            +
                print("2. Verify your HUGGINGFACE_TOKEN has write access")
         | 
| 59 | 
            +
                print("3. Ensure you're not rate limited")
         | 
| 60 | 
            +
                print("4. Try again in a few minutes")
         | 
| 61 | 
            +
                sys.exit(1)
         |