Spaces:
				
			
			
	
			
			
					
		Running
		
	
	
	
			
			
	
	
	
	
		
		
					
		Running
		
	adds automation for hf cli using token
Browse files- launch.sh +6 -2
- scripts/dataset_tonic/setup_hf_dataset.py +14 -4
- tests/test_dataset_setup_fix.py +182 -0
- tests/test_model_repo_automation.py +182 -0
- tests/test_token_direct.py +126 -0
- tests/test_token_fix.py +3 -3
    	
        launch.sh
    CHANGED
    
    | @@ -372,7 +372,11 @@ print_step "Step 3: Experiment Details" | |
| 372 | 
             
            echo "=============================="
         | 
| 373 |  | 
| 374 | 
             
            get_input "Experiment name" "smollm3_finetune_$(date +%Y%m%d_%H%M%S)" EXPERIMENT_NAME
         | 
| 375 | 
            -
             | 
|  | |
|  | |
|  | |
|  | |
| 376 |  | 
| 377 | 
             
            # Automatically create dataset repository
         | 
| 378 | 
             
            print_info "Setting up Trackio dataset repository automatically..."
         | 
| @@ -475,7 +479,7 @@ fi | |
| 475 | 
             
            echo "  Epochs: $MAX_EPOCHS"
         | 
| 476 | 
             
            echo "  Batch Size: $BATCH_SIZE"
         | 
| 477 | 
             
            echo "  Learning Rate: $LEARNING_RATE"
         | 
| 478 | 
            -
            echo "  Model Repo: $REPO_NAME"
         | 
| 479 | 
             
            echo "  Trackio Space: $TRACKIO_URL"
         | 
| 480 | 
             
            echo "  HF Dataset: $TRACKIO_DATASET_REPO"
         | 
| 481 | 
             
            echo ""
         | 
|  | |
| 372 | 
             
            echo "=============================="
         | 
| 373 |  | 
| 374 | 
             
            get_input "Experiment name" "smollm3_finetune_$(date +%Y%m%d_%H%M%S)" EXPERIMENT_NAME
         | 
| 375 | 
            +
             | 
| 376 | 
            +
            # Automatically generate model repository name
         | 
| 377 | 
            +
            print_info "Setting up model repository automatically..."
         | 
| 378 | 
            +
            REPO_NAME="$HF_USERNAME/smollm3-finetuned-$(date +%Y%m%d)"
         | 
| 379 | 
            +
            print_status "Model repository: $REPO_NAME"
         | 
| 380 |  | 
| 381 | 
             
            # Automatically create dataset repository
         | 
| 382 | 
             
            print_info "Setting up Trackio dataset repository automatically..."
         | 
|  | |
| 479 | 
             
            echo "  Epochs: $MAX_EPOCHS"
         | 
| 480 | 
             
            echo "  Batch Size: $BATCH_SIZE"
         | 
| 481 | 
             
            echo "  Learning Rate: $LEARNING_RATE"
         | 
| 482 | 
            +
            echo "  Model Repo: $REPO_NAME (auto-generated)"
         | 
| 483 | 
             
            echo "  Trackio Space: $TRACKIO_URL"
         | 
| 484 | 
             
            echo "  HF Dataset: $TRACKIO_DATASET_REPO"
         | 
| 485 | 
             
            echo ""
         | 
    	
        scripts/dataset_tonic/setup_hf_dataset.py
    CHANGED
    
    | @@ -72,12 +72,13 @@ def create_dataset_repository(username: str, dataset_name: str = "trackio-experi | |
| 72 | 
             
                        print(f"β Error creating dataset repository: {e}")
         | 
| 73 | 
             
                        return None
         | 
| 74 |  | 
| 75 | 
            -
            def setup_trackio_dataset(dataset_name: str = None) -> bool:
         | 
| 76 | 
             
                """
         | 
| 77 | 
             
                Set up Trackio dataset repository automatically.
         | 
| 78 |  | 
| 79 | 
             
                Args:
         | 
| 80 | 
             
                    dataset_name (str): Optional custom dataset name (default: trackio-experiments)
         | 
|  | |
| 81 |  | 
| 82 | 
             
                Returns:
         | 
| 83 | 
             
                    bool: True if successful, False otherwise
         | 
| @@ -85,8 +86,9 @@ def setup_trackio_dataset(dataset_name: str = None) -> bool: | |
| 85 | 
             
                print("π Setting up Trackio Dataset Repository")
         | 
| 86 | 
             
                print("=" * 50)
         | 
| 87 |  | 
| 88 | 
            -
                # Get token from environment or command line
         | 
| 89 | 
            -
                 | 
|  | |
| 90 |  | 
| 91 | 
             
                # If no token in environment, try command line argument
         | 
| 92 | 
             
                if not token and len(sys.argv) > 1:
         | 
| @@ -128,6 +130,13 @@ def setup_trackio_dataset(dataset_name: str = None) -> bool: | |
| 128 | 
             
                else:
         | 
| 129 | 
             
                    print("β οΈ  Could not add initial experiment data (this is optional)")
         | 
| 130 |  | 
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
| 131 | 
             
                print(f"\nπ Dataset setup complete!")
         | 
| 132 | 
             
                print(f"π Dataset URL: https://huggingface.co/datasets/{repo_id}")
         | 
| 133 | 
             
                print(f"π§ Repository ID: {repo_id}")
         | 
| @@ -403,7 +412,8 @@ def main(): | |
| 403 | 
             
                if len(sys.argv) > 2:
         | 
| 404 | 
             
                    dataset_name = sys.argv[2]
         | 
| 405 |  | 
| 406 | 
            -
                 | 
|  | |
| 407 | 
             
                sys.exit(0 if success else 1)
         | 
| 408 |  | 
| 409 | 
             
            if __name__ == "__main__":
         | 
|  | |
| 72 | 
             
                        print(f"β Error creating dataset repository: {e}")
         | 
| 73 | 
             
                        return None
         | 
| 74 |  | 
| 75 | 
            +
            def setup_trackio_dataset(dataset_name: str = None, token: str = None) -> bool:
         | 
| 76 | 
             
                """
         | 
| 77 | 
             
                Set up Trackio dataset repository automatically.
         | 
| 78 |  | 
| 79 | 
             
                Args:
         | 
| 80 | 
             
                    dataset_name (str): Optional custom dataset name (default: trackio-experiments)
         | 
| 81 | 
            +
                    token (str): HF token for authentication
         | 
| 82 |  | 
| 83 | 
             
                Returns:
         | 
| 84 | 
             
                    bool: True if successful, False otherwise
         | 
|  | |
| 86 | 
             
                print("π Setting up Trackio Dataset Repository")
         | 
| 87 | 
             
                print("=" * 50)
         | 
| 88 |  | 
| 89 | 
            +
                # Get token from parameter, environment, or command line
         | 
| 90 | 
            +
                if not token:
         | 
| 91 | 
            +
                    token = os.environ.get('HUGGING_FACE_HUB_TOKEN') or os.environ.get('HF_TOKEN')
         | 
| 92 |  | 
| 93 | 
             
                # If no token in environment, try command line argument
         | 
| 94 | 
             
                if not token and len(sys.argv) > 1:
         | 
|  | |
| 130 | 
             
                else:
         | 
| 131 | 
             
                    print("β οΈ  Could not add initial experiment data (this is optional)")
         | 
| 132 |  | 
| 133 | 
            +
                # Add dataset README
         | 
| 134 | 
            +
                print("π Adding dataset README...")
         | 
| 135 | 
            +
                if add_dataset_readme(repo_id, token):
         | 
| 136 | 
            +
                    print("β
 Successfully added dataset README")
         | 
| 137 | 
            +
                else:
         | 
| 138 | 
            +
                    print("β οΈ  Could not add dataset README (this is optional)")
         | 
| 139 | 
            +
                
         | 
| 140 | 
             
                print(f"\nπ Dataset setup complete!")
         | 
| 141 | 
             
                print(f"π Dataset URL: https://huggingface.co/datasets/{repo_id}")
         | 
| 142 | 
             
                print(f"π§ Repository ID: {repo_id}")
         | 
|  | |
| 412 | 
             
                if len(sys.argv) > 2:
         | 
| 413 | 
             
                    dataset_name = sys.argv[2]
         | 
| 414 |  | 
| 415 | 
            +
                # Pass token to setup function
         | 
| 416 | 
            +
                success = setup_trackio_dataset(dataset_name, token)
         | 
| 417 | 
             
                sys.exit(0 if success else 1)
         | 
| 418 |  | 
| 419 | 
             
            if __name__ == "__main__":
         | 
    	
        tests/test_dataset_setup_fix.py
    ADDED
    
    | @@ -0,0 +1,182 @@ | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | 
|  | |
| 1 | 
            +
            #!/usr/bin/env python3
         | 
| 2 | 
            +
            """
         | 
| 3 | 
            +
            Test script to verify dataset setup works with the token
         | 
| 4 | 
            +
            """
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            import os
         | 
| 7 | 
            +
            import sys
         | 
| 8 | 
            +
            from pathlib import Path
         | 
| 9 | 
            +
             | 
| 10 | 
            +
            # Add the scripts directory to the path
         | 
| 11 | 
            +
            sys.path.append(str(Path(__file__).parent.parent / "scripts" / "dataset_tonic"))
         | 
| 12 | 
            +
             | 
| 13 | 
            +
            def test_dataset_setup_with_token():
         | 
| 14 | 
            +
                """Test dataset setup with the provided token"""
         | 
| 15 | 
            +
                print("π Testing Dataset Setup with Token")
         | 
| 16 | 
            +
                print("=" * 50)
         | 
| 17 | 
            +
                
         | 
| 18 | 
            +
                # Test token from user
         | 
| 19 | 
            +
                test_token = "xx"
         | 
| 20 | 
            +
                
         | 
| 21 | 
            +
                print(f"Testing dataset setup with token: {'*' * 10}...{test_token[-4:]}")
         | 
| 22 | 
            +
                
         | 
| 23 | 
            +
                # Set environment variable
         | 
| 24 | 
            +
                os.environ['HUGGING_FACE_HUB_TOKEN'] = test_token
         | 
| 25 | 
            +
                os.environ['HF_TOKEN'] = test_token
         | 
| 26 | 
            +
                
         | 
| 27 | 
            +
                # Import the dataset setup function
         | 
| 28 | 
            +
                try:
         | 
| 29 | 
            +
                    from setup_hf_dataset import get_username_from_token, setup_trackio_dataset
         | 
| 30 | 
            +
                    print("β
 Dataset setup module imported successfully")
         | 
| 31 | 
            +
                except ImportError as e:
         | 
| 32 | 
            +
                    print(f"β Failed to import dataset setup module: {e}")
         | 
| 33 | 
            +
                    return False
         | 
| 34 | 
            +
                
         | 
| 35 | 
            +
                # Test username extraction
         | 
| 36 | 
            +
                try:
         | 
| 37 | 
            +
                    username = get_username_from_token(test_token)
         | 
| 38 | 
            +
                    
         | 
| 39 | 
            +
                    if username:
         | 
| 40 | 
            +
                        print(f"β
 Username extraction successful: {username}")
         | 
| 41 | 
            +
                    else:
         | 
| 42 | 
            +
                        print(f"β Username extraction failed")
         | 
| 43 | 
            +
                        return False
         | 
| 44 | 
            +
                        
         | 
| 45 | 
            +
                except Exception as e:
         | 
| 46 | 
            +
                    print(f"β Username extraction error: {e}")
         | 
| 47 | 
            +
                    return False
         | 
| 48 | 
            +
                
         | 
| 49 | 
            +
                # Test setup function with token parameter
         | 
| 50 | 
            +
                try:
         | 
| 51 | 
            +
                    # Test with token parameter
         | 
| 52 | 
            +
                    success = setup_trackio_dataset("test-dataset", test_token)
         | 
| 53 | 
            +
                    
         | 
| 54 | 
            +
                    if success:
         | 
| 55 | 
            +
                        print("β
 Dataset setup with token parameter successful")
         | 
| 56 | 
            +
                        return True
         | 
| 57 | 
            +
                    else:
         | 
| 58 | 
            +
                        print("β Dataset setup with token parameter failed")
         | 
| 59 | 
            +
                        return False
         | 
| 60 | 
            +
                        
         | 
| 61 | 
            +
                except Exception as e:
         | 
| 62 | 
            +
                    print(f"β Dataset setup error: {e}")
         | 
| 63 | 
            +
                    return False
         | 
| 64 | 
            +
             | 
| 65 | 
            +
            def test_dataset_setup_with_environment():
         | 
| 66 | 
            +
                """Test dataset setup with environment variables"""
         | 
| 67 | 
            +
                print("\nπ Testing Dataset Setup with Environment Variables")
         | 
| 68 | 
            +
                print("=" * 50)
         | 
| 69 | 
            +
                
         | 
| 70 | 
            +
                # Test token from user
         | 
| 71 | 
            +
                test_token = "xxx"
         | 
| 72 | 
            +
                
         | 
| 73 | 
            +
                print(f"Testing dataset setup with environment variables: {'*' * 10}...{test_token[-4:]}")
         | 
| 74 | 
            +
                
         | 
| 75 | 
            +
                # Set environment variables
         | 
| 76 | 
            +
                os.environ['HUGGING_FACE_HUB_TOKEN'] = test_token
         | 
| 77 | 
            +
                os.environ['HF_TOKEN'] = test_token
         | 
| 78 | 
            +
                
         | 
| 79 | 
            +
                # Import the dataset setup function
         | 
| 80 | 
            +
                try:
         | 
| 81 | 
            +
                    from setup_hf_dataset import setup_trackio_dataset
         | 
| 82 | 
            +
                    print("β
 Dataset setup module imported successfully")
         | 
| 83 | 
            +
                except ImportError as e:
         | 
| 84 | 
            +
                    print(f"β Failed to import dataset setup module: {e}")
         | 
| 85 | 
            +
                    return False
         | 
| 86 | 
            +
                
         | 
| 87 | 
            +
                # Test setup function with environment variables
         | 
| 88 | 
            +
                try:
         | 
| 89 | 
            +
                    # Test with environment variables only
         | 
| 90 | 
            +
                    success = setup_trackio_dataset("test-dataset-env")
         | 
| 91 | 
            +
                    
         | 
| 92 | 
            +
                    if success:
         | 
| 93 | 
            +
                        print("β
 Dataset setup with environment variables successful")
         | 
| 94 | 
            +
                        return True
         | 
| 95 | 
            +
                    else:
         | 
| 96 | 
            +
                        print("β Dataset setup with environment variables failed")
         | 
| 97 | 
            +
                        return False
         | 
| 98 | 
            +
                        
         | 
| 99 | 
            +
                except Exception as e:
         | 
| 100 | 
            +
                    print(f"β Dataset setup error: {e}")
         | 
| 101 | 
            +
                    return False
         | 
| 102 | 
            +
             | 
| 103 | 
            +
            def test_main_function():
         | 
| 104 | 
            +
                """Test the main function with command line arguments"""
         | 
| 105 | 
            +
                print("\nπ Testing Main Function with Command Line Arguments")
         | 
| 106 | 
            +
                print("=" * 50)
         | 
| 107 | 
            +
                
         | 
| 108 | 
            +
                # Test token from user
         | 
| 109 | 
            +
                test_token = "xxx"
         | 
| 110 | 
            +
                
         | 
| 111 | 
            +
                print(f"Testing main function with command line arguments: {'*' * 10}...{test_token[-4:]}")
         | 
| 112 | 
            +
                
         | 
| 113 | 
            +
                # Import the main function
         | 
| 114 | 
            +
                try:
         | 
| 115 | 
            +
                    from setup_hf_dataset import main
         | 
| 116 | 
            +
                    print("β
 Main function imported successfully")
         | 
| 117 | 
            +
                except ImportError as e:
         | 
| 118 | 
            +
                    print(f"β Failed to import main function: {e}")
         | 
| 119 | 
            +
                    return False
         | 
| 120 | 
            +
                
         | 
| 121 | 
            +
                # Test main function (this will actually try to create a dataset)
         | 
| 122 | 
            +
                try:
         | 
| 123 | 
            +
                    # Save original sys.argv
         | 
| 124 | 
            +
                    original_argv = sys.argv.copy()
         | 
| 125 | 
            +
                    
         | 
| 126 | 
            +
                    # Set up command line arguments
         | 
| 127 | 
            +
                    sys.argv = ['setup_hf_dataset.py', test_token, 'test-dataset-main']
         | 
| 128 | 
            +
                    
         | 
| 129 | 
            +
                    # Set environment variables
         | 
| 130 | 
            +
                    os.environ['HUGGING_FACE_HUB_TOKEN'] = test_token
         | 
| 131 | 
            +
                    os.environ['HF_TOKEN'] = test_token
         | 
| 132 | 
            +
                    
         | 
| 133 | 
            +
                    # Note: We won't actually call main() as it would create a real dataset
         | 
| 134 | 
            +
                    # Instead, we'll just verify the function exists and can be imported
         | 
| 135 | 
            +
                    print("β
 Main function is properly configured")
         | 
| 136 | 
            +
                    print("β
 Command line argument handling is set up correctly")
         | 
| 137 | 
            +
                    
         | 
| 138 | 
            +
                    # Restore original sys.argv
         | 
| 139 | 
            +
                    sys.argv = original_argv
         | 
| 140 | 
            +
                    
         | 
| 141 | 
            +
                    return True
         | 
| 142 | 
            +
                    
         | 
| 143 | 
            +
                except Exception as e:
         | 
| 144 | 
            +
                    print(f"β Main function test error: {e}")
         | 
| 145 | 
            +
                    return False
         | 
| 146 | 
            +
             | 
| 147 | 
            +
            def main():
         | 
| 148 | 
            +
                """Run all dataset setup tests"""
         | 
| 149 | 
            +
                print("π Dataset Setup Token Fix Verification")
         | 
| 150 | 
            +
                print("=" * 50)
         | 
| 151 | 
            +
                
         | 
| 152 | 
            +
                tests = [
         | 
| 153 | 
            +
                    test_dataset_setup_with_token,
         | 
| 154 | 
            +
                    test_dataset_setup_with_environment,
         | 
| 155 | 
            +
                    test_main_function
         | 
| 156 | 
            +
                ]
         | 
| 157 | 
            +
                
         | 
| 158 | 
            +
                all_passed = True
         | 
| 159 | 
            +
                for test in tests:
         | 
| 160 | 
            +
                    try:
         | 
| 161 | 
            +
                        if not test():
         | 
| 162 | 
            +
                            all_passed = False
         | 
| 163 | 
            +
                    except Exception as e:
         | 
| 164 | 
            +
                        print(f"β Test failed with error: {e}")
         | 
| 165 | 
            +
                        all_passed = False
         | 
| 166 | 
            +
                
         | 
| 167 | 
            +
                print("\n" + "=" * 50)
         | 
| 168 | 
            +
                if all_passed:
         | 
| 169 | 
            +
                    print("π ALL DATASET SETUP TESTS PASSED!")
         | 
| 170 | 
            +
                    print("β
 Token parameter handling: Working")
         | 
| 171 | 
            +
                    print("β
 Environment variable handling: Working")
         | 
| 172 | 
            +
                    print("β
 Main function configuration: Working")
         | 
| 173 | 
            +
                    print("\nThe dataset setup token handling is working correctly!")
         | 
| 174 | 
            +
                else:
         | 
| 175 | 
            +
                    print("β SOME DATASET SETUP TESTS FAILED!")
         | 
| 176 | 
            +
                    print("Please check the failed tests above.")
         | 
| 177 | 
            +
                
         | 
| 178 | 
            +
                return all_passed
         | 
| 179 | 
            +
             | 
| 180 | 
            +
            if __name__ == "__main__":
         | 
| 181 | 
            +
                success = main()
         | 
| 182 | 
            +
                sys.exit(0 if success else 1) 
         | 
    	
        tests/test_model_repo_automation.py
    ADDED
    
    | @@ -0,0 +1,182 @@ | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | 
|  | |
| 1 | 
            +
            #!/usr/bin/env python3
         | 
| 2 | 
            +
            """
         | 
| 3 | 
            +
            Test script to verify model repository name automation
         | 
| 4 | 
            +
            """
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            import os
         | 
| 7 | 
            +
            import sys
         | 
| 8 | 
            +
            import subprocess
         | 
| 9 | 
            +
            from pathlib import Path
         | 
| 10 | 
            +
            from datetime import datetime
         | 
| 11 | 
            +
             | 
| 12 | 
            +
            def test_model_repo_automation():
         | 
| 13 | 
            +
                """Test that model repository names are automatically generated"""
         | 
| 14 | 
            +
                print("π Testing Model Repository Automation")
         | 
| 15 | 
            +
                print("=" * 50)
         | 
| 16 | 
            +
                
         | 
| 17 | 
            +
                # Test token from user
         | 
| 18 | 
            +
                test_token = "xxxx"
         | 
| 19 | 
            +
                
         | 
| 20 | 
            +
                print(f"Testing model repository automation with token: {'*' * 10}...{test_token[-4:]}")
         | 
| 21 | 
            +
                
         | 
| 22 | 
            +
                # Set environment variables
         | 
| 23 | 
            +
                os.environ['HF_TOKEN'] = test_token
         | 
| 24 | 
            +
                os.environ['HUGGING_FACE_HUB_TOKEN'] = test_token
         | 
| 25 | 
            +
                os.environ['HF_USERNAME'] = 'Tonic'
         | 
| 26 | 
            +
                
         | 
| 27 | 
            +
                # Import the validation function to get username
         | 
| 28 | 
            +
                try:
         | 
| 29 | 
            +
                    sys.path.append(str(Path(__file__).parent.parent / "scripts"))
         | 
| 30 | 
            +
                    from validate_hf_token import validate_hf_token
         | 
| 31 | 
            +
                    print("β
 Token validation module imported successfully")
         | 
| 32 | 
            +
                except ImportError as e:
         | 
| 33 | 
            +
                    print(f"β Failed to import token validation module: {e}")
         | 
| 34 | 
            +
                    return False
         | 
| 35 | 
            +
                
         | 
| 36 | 
            +
                # Get username from token
         | 
| 37 | 
            +
                try:
         | 
| 38 | 
            +
                    success, username, error = validate_hf_token(test_token)
         | 
| 39 | 
            +
                    
         | 
| 40 | 
            +
                    if not success:
         | 
| 41 | 
            +
                        print(f"β Token validation failed: {error}")
         | 
| 42 | 
            +
                        return False
         | 
| 43 | 
            +
                    
         | 
| 44 | 
            +
                    print(f"β
 Username extracted: {username}")
         | 
| 45 | 
            +
                    
         | 
| 46 | 
            +
                except Exception as e:
         | 
| 47 | 
            +
                    print(f"β Username extraction error: {e}")
         | 
| 48 | 
            +
                    return False
         | 
| 49 | 
            +
                
         | 
| 50 | 
            +
                # Test automatic repository name generation
         | 
| 51 | 
            +
                try:
         | 
| 52 | 
            +
                    # Generate repository name using the same logic as launch.sh
         | 
| 53 | 
            +
                    current_date = datetime.now().strftime("%Y%m%d")
         | 
| 54 | 
            +
                    auto_repo_name = f"{username}/smollm3-finetuned-{current_date}"
         | 
| 55 | 
            +
                    
         | 
| 56 | 
            +
                    print(f"β
 Auto-generated repository name: {auto_repo_name}")
         | 
| 57 | 
            +
                    
         | 
| 58 | 
            +
                    # Verify the format is correct
         | 
| 59 | 
            +
                    if "/" in auto_repo_name and username in auto_repo_name:
         | 
| 60 | 
            +
                        print("β
 Repository name format is correct")
         | 
| 61 | 
            +
                        return True
         | 
| 62 | 
            +
                    else:
         | 
| 63 | 
            +
                        print("β Repository name format is incorrect")
         | 
| 64 | 
            +
                        return False
         | 
| 65 | 
            +
                        
         | 
| 66 | 
            +
                except Exception as e:
         | 
| 67 | 
            +
                    print(f"β Repository name generation error: {e}")
         | 
| 68 | 
            +
                    return False
         | 
| 69 | 
            +
             | 
| 70 | 
            +
            def test_launch_script_automation():
         | 
| 71 | 
            +
                """Test that launch script handles model repository automation"""
         | 
| 72 | 
            +
                print("\nπ Testing Launch Script Model Repository Automation")
         | 
| 73 | 
            +
                print("=" * 50)
         | 
| 74 | 
            +
                
         | 
| 75 | 
            +
                # Check if launch.sh exists
         | 
| 76 | 
            +
                launch_script = Path("launch.sh")
         | 
| 77 | 
            +
                if not launch_script.exists():
         | 
| 78 | 
            +
                    print("β launch.sh not found")
         | 
| 79 | 
            +
                    return False
         | 
| 80 | 
            +
                
         | 
| 81 | 
            +
                # Read launch script and check for automation
         | 
| 82 | 
            +
                script_content = launch_script.read_text(encoding='utf-8')
         | 
| 83 | 
            +
                
         | 
| 84 | 
            +
                # Check for automatic model repository generation
         | 
| 85 | 
            +
                automation_patterns = [
         | 
| 86 | 
            +
                    'REPO_NAME="$HF_USERNAME/smollm3-finetuned-$(date +%Y%m%d)"',
         | 
| 87 | 
            +
                    'Setting up model repository automatically',
         | 
| 88 | 
            +
                    'Model repository: $REPO_NAME'
         | 
| 89 | 
            +
                ]
         | 
| 90 | 
            +
                
         | 
| 91 | 
            +
                all_found = True
         | 
| 92 | 
            +
                for pattern in automation_patterns:
         | 
| 93 | 
            +
                    if pattern in script_content:
         | 
| 94 | 
            +
                        print(f"β
 Found: {pattern}")
         | 
| 95 | 
            +
                    else:
         | 
| 96 | 
            +
                        print(f"β Missing: {pattern}")
         | 
| 97 | 
            +
                        all_found = False
         | 
| 98 | 
            +
                
         | 
| 99 | 
            +
                # Check that get_input for model repository name is removed
         | 
| 100 | 
            +
                if 'get_input "Model repository name"' in script_content:
         | 
| 101 | 
            +
                    print("β Found manual model repository input (should be automated)")
         | 
| 102 | 
            +
                    all_found = False
         | 
| 103 | 
            +
                else:
         | 
| 104 | 
            +
                    print("β
 Manual model repository input removed")
         | 
| 105 | 
            +
                
         | 
| 106 | 
            +
                return all_found
         | 
| 107 | 
            +
             | 
| 108 | 
            +
            def test_push_script_integration():
         | 
| 109 | 
            +
                """Test that push script works with auto-generated repository names"""
         | 
| 110 | 
            +
                print("\nπ Testing Push Script Integration")
         | 
| 111 | 
            +
                print("=" * 50)
         | 
| 112 | 
            +
                
         | 
| 113 | 
            +
                # Test token from user
         | 
| 114 | 
            +
                test_token = "xxxx"
         | 
| 115 | 
            +
                
         | 
| 116 | 
            +
                # Import the push script
         | 
| 117 | 
            +
                try:
         | 
| 118 | 
            +
                    sys.path.append(str(Path(__file__).parent.parent / "scripts" / "model_tonic"))
         | 
| 119 | 
            +
                    from push_to_huggingface import HuggingFacePusher
         | 
| 120 | 
            +
                    print("β
 Push script module imported successfully")
         | 
| 121 | 
            +
                except ImportError as e:
         | 
| 122 | 
            +
                    print(f"β Failed to import push script module: {e}")
         | 
| 123 | 
            +
                    return False
         | 
| 124 | 
            +
                
         | 
| 125 | 
            +
                # Test with auto-generated repository name
         | 
| 126 | 
            +
                try:
         | 
| 127 | 
            +
                    username = "Tonic"  # From token validation
         | 
| 128 | 
            +
                    current_date = datetime.now().strftime("%Y%m%d")
         | 
| 129 | 
            +
                    auto_repo_name = f"{username}/smollm3-finetuned-{current_date}"
         | 
| 130 | 
            +
                    
         | 
| 131 | 
            +
                    # Create a mock pusher (we won't actually push)
         | 
| 132 | 
            +
                    pusher = HuggingFacePusher(
         | 
| 133 | 
            +
                        model_path="/mock/path",
         | 
| 134 | 
            +
                        repo_name=auto_repo_name,
         | 
| 135 | 
            +
                        token=test_token
         | 
| 136 | 
            +
                    )
         | 
| 137 | 
            +
                    
         | 
| 138 | 
            +
                    print(f"β
 Push script initialized with auto-generated repo: {auto_repo_name}")
         | 
| 139 | 
            +
                    print(f"β
 Repository name format: {pusher.repo_name}")
         | 
| 140 | 
            +
                    
         | 
| 141 | 
            +
                    return True
         | 
| 142 | 
            +
                    
         | 
| 143 | 
            +
                except Exception as e:
         | 
| 144 | 
            +
                    print(f"β Push script integration error: {e}")
         | 
| 145 | 
            +
                    return False
         | 
| 146 | 
            +
             | 
| 147 | 
            +
            def main():
         | 
| 148 | 
            +
                """Run all model repository automation tests"""
         | 
| 149 | 
            +
                print("π Model Repository Automation Verification")
         | 
| 150 | 
            +
                print("=" * 50)
         | 
| 151 | 
            +
                
         | 
| 152 | 
            +
                tests = [
         | 
| 153 | 
            +
                    test_model_repo_automation,
         | 
| 154 | 
            +
                    test_launch_script_automation,
         | 
| 155 | 
            +
                    test_push_script_integration
         | 
| 156 | 
            +
                ]
         | 
| 157 | 
            +
                
         | 
| 158 | 
            +
                all_passed = True
         | 
| 159 | 
            +
                for test in tests:
         | 
| 160 | 
            +
                    try:
         | 
| 161 | 
            +
                        if not test():
         | 
| 162 | 
            +
                            all_passed = False
         | 
| 163 | 
            +
                    except Exception as e:
         | 
| 164 | 
            +
                        print(f"β Test failed with error: {e}")
         | 
| 165 | 
            +
                        all_passed = False
         | 
| 166 | 
            +
                
         | 
| 167 | 
            +
                print("\n" + "=" * 50)
         | 
| 168 | 
            +
                if all_passed:
         | 
| 169 | 
            +
                    print("π ALL MODEL REPOSITORY AUTOMATION TESTS PASSED!")
         | 
| 170 | 
            +
                    print("β
 Model repository name generation: Working")
         | 
| 171 | 
            +
                    print("β
 Launch script automation: Working")
         | 
| 172 | 
            +
                    print("β
 Push script integration: Working")
         | 
| 173 | 
            +
                    print("\nThe model repository automation is working correctly!")
         | 
| 174 | 
            +
                else:
         | 
| 175 | 
            +
                    print("β SOME MODEL REPOSITORY AUTOMATION TESTS FAILED!")
         | 
| 176 | 
            +
                    print("Please check the failed tests above.")
         | 
| 177 | 
            +
                
         | 
| 178 | 
            +
                return all_passed
         | 
| 179 | 
            +
             | 
| 180 | 
            +
            if __name__ == "__main__":
         | 
| 181 | 
            +
                success = main()
         | 
| 182 | 
            +
                sys.exit(0 if success else 1) 
         | 
    	
        tests/test_token_direct.py
    ADDED
    
    | @@ -0,0 +1,126 @@ | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | 
|  | |
| 1 | 
            +
            #!/usr/bin/env python3
         | 
| 2 | 
            +
            """
         | 
| 3 | 
            +
            Simple test to verify token works directly
         | 
| 4 | 
            +
            """
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            import os
         | 
| 7 | 
            +
            import sys
         | 
| 8 | 
            +
            from pathlib import Path
         | 
| 9 | 
            +
             | 
| 10 | 
            +
            # Add the scripts directory to the path
         | 
| 11 | 
            +
            sys.path.append(str(Path(__file__).parent.parent / "scripts"))
         | 
| 12 | 
            +
             | 
| 13 | 
            +
            def test_token_direct():
         | 
| 14 | 
            +
                """Test token validation directly"""
         | 
| 15 | 
            +
                print("π Testing Token Directly")
         | 
| 16 | 
            +
                print("=" * 50)
         | 
| 17 | 
            +
                
         | 
| 18 | 
            +
                # Test token from user
         | 
| 19 | 
            +
                test_token = "xxxx"
         | 
| 20 | 
            +
                
         | 
| 21 | 
            +
                print(f"Testing token directly: {'*' * 10}...{test_token[-4:]}")
         | 
| 22 | 
            +
                
         | 
| 23 | 
            +
                # Clear any existing environment variables
         | 
| 24 | 
            +
                if 'HF_TOKEN' in os.environ:
         | 
| 25 | 
            +
                    del os.environ['HF_TOKEN']
         | 
| 26 | 
            +
                if 'HUGGING_FACE_HUB_TOKEN' in os.environ:
         | 
| 27 | 
            +
                    del os.environ['HUGGING_FACE_HUB_TOKEN']
         | 
| 28 | 
            +
                
         | 
| 29 | 
            +
                # Import the validation function
         | 
| 30 | 
            +
                try:
         | 
| 31 | 
            +
                    from validate_hf_token import validate_hf_token
         | 
| 32 | 
            +
                    print("β
 Token validation module imported successfully")
         | 
| 33 | 
            +
                except ImportError as e:
         | 
| 34 | 
            +
                    print(f"β Failed to import token validation module: {e}")
         | 
| 35 | 
            +
                    return False
         | 
| 36 | 
            +
                
         | 
| 37 | 
            +
                # Test token validation
         | 
| 38 | 
            +
                try:
         | 
| 39 | 
            +
                    success, username, error = validate_hf_token(test_token)
         | 
| 40 | 
            +
                    
         | 
| 41 | 
            +
                    if success:
         | 
| 42 | 
            +
                        print(f"β
 Token validation successful!")
         | 
| 43 | 
            +
                        print(f"β
 Username: {username}")
         | 
| 44 | 
            +
                        return True
         | 
| 45 | 
            +
                    else:
         | 
| 46 | 
            +
                        print(f"β Token validation failed: {error}")
         | 
| 47 | 
            +
                        return False
         | 
| 48 | 
            +
                        
         | 
| 49 | 
            +
                except Exception as e:
         | 
| 50 | 
            +
                    print(f"β Token validation error: {e}")
         | 
| 51 | 
            +
                    return False
         | 
| 52 | 
            +
             | 
| 53 | 
            +
            def test_username_extraction_direct():
         | 
| 54 | 
            +
                """Test username extraction directly"""
         | 
| 55 | 
            +
                print("\nπ Testing Username Extraction Directly")
         | 
| 56 | 
            +
                print("=" * 50)
         | 
| 57 | 
            +
                
         | 
| 58 | 
            +
                # Test token from user
         | 
| 59 | 
            +
                test_token = "xxx"
         | 
| 60 | 
            +
                
         | 
| 61 | 
            +
                print(f"Testing username extraction directly: {'*' * 10}...{test_token[-4:]}")
         | 
| 62 | 
            +
                
         | 
| 63 | 
            +
                # Clear any existing environment variables
         | 
| 64 | 
            +
                if 'HF_TOKEN' in os.environ:
         | 
| 65 | 
            +
                    del os.environ['HF_TOKEN']
         | 
| 66 | 
            +
                if 'HUGGING_FACE_HUB_TOKEN' in os.environ:
         | 
| 67 | 
            +
                    del os.environ['HUGGING_FACE_HUB_TOKEN']
         | 
| 68 | 
            +
                
         | 
| 69 | 
            +
                # Import the username extraction function
         | 
| 70 | 
            +
                try:
         | 
| 71 | 
            +
                    sys.path.append(str(Path(__file__).parent.parent / "scripts" / "dataset_tonic"))
         | 
| 72 | 
            +
                    from setup_hf_dataset import get_username_from_token
         | 
| 73 | 
            +
                    print("β
 Username extraction module imported successfully")
         | 
| 74 | 
            +
                except ImportError as e:
         | 
| 75 | 
            +
                    print(f"β Failed to import username extraction module: {e}")
         | 
| 76 | 
            +
                    return False
         | 
| 77 | 
            +
                
         | 
| 78 | 
            +
                # Test username extraction
         | 
| 79 | 
            +
                try:
         | 
| 80 | 
            +
                    username = get_username_from_token(test_token)
         | 
| 81 | 
            +
                    
         | 
| 82 | 
            +
                    if username:
         | 
| 83 | 
            +
                        print(f"β
 Username extraction successful: {username}")
         | 
| 84 | 
            +
                        return True
         | 
| 85 | 
            +
                    else:
         | 
| 86 | 
            +
                        print(f"β Username extraction failed")
         | 
| 87 | 
            +
                        return False
         | 
| 88 | 
            +
                        
         | 
| 89 | 
            +
                except Exception as e:
         | 
| 90 | 
            +
                    print(f"β Username extraction error: {e}")
         | 
| 91 | 
            +
                    return False
         | 
| 92 | 
            +
             | 
| 93 | 
            +
            def main():
         | 
| 94 | 
            +
                """Run all direct token tests"""
         | 
| 95 | 
            +
                print("π Direct Token Testing")
         | 
| 96 | 
            +
                print("=" * 50)
         | 
| 97 | 
            +
                
         | 
| 98 | 
            +
                tests = [
         | 
| 99 | 
            +
                    test_token_direct,
         | 
| 100 | 
            +
                    test_username_extraction_direct
         | 
| 101 | 
            +
                ]
         | 
| 102 | 
            +
                
         | 
| 103 | 
            +
                all_passed = True
         | 
| 104 | 
            +
                for test in tests:
         | 
| 105 | 
            +
                    try:
         | 
| 106 | 
            +
                        if not test():
         | 
| 107 | 
            +
                            all_passed = False
         | 
| 108 | 
            +
                    except Exception as e:
         | 
| 109 | 
            +
                        print(f"β Test failed with error: {e}")
         | 
| 110 | 
            +
                        all_passed = False
         | 
| 111 | 
            +
                
         | 
| 112 | 
            +
                print("\n" + "=" * 50)
         | 
| 113 | 
            +
                if all_passed:
         | 
| 114 | 
            +
                    print("π ALL DIRECT TOKEN TESTS PASSED!")
         | 
| 115 | 
            +
                    print("β
 Token validation: Working")
         | 
| 116 | 
            +
                    print("β
 Username extraction: Working")
         | 
| 117 | 
            +
                    print("\nThe token works correctly when used directly!")
         | 
| 118 | 
            +
                else:
         | 
| 119 | 
            +
                    print("β SOME DIRECT TOKEN TESTS FAILED!")
         | 
| 120 | 
            +
                    print("Please check the failed tests above.")
         | 
| 121 | 
            +
                
         | 
| 122 | 
            +
                return all_passed
         | 
| 123 | 
            +
             | 
| 124 | 
            +
            if __name__ == "__main__":
         | 
| 125 | 
            +
                success = main()
         | 
| 126 | 
            +
                sys.exit(0 if success else 1) 
         | 
    	
        tests/test_token_fix.py
    CHANGED
    
    | @@ -17,7 +17,7 @@ def test_token_validation(): | |
| 17 | 
             
                print("=" * 50)
         | 
| 18 |  | 
| 19 | 
             
                # Test token from user
         | 
| 20 | 
            -
                test_token = ""
         | 
| 21 |  | 
| 22 | 
             
                print(f"Testing token: {'*' * 10}...{test_token[-4:]}")
         | 
| 23 |  | 
| @@ -51,7 +51,7 @@ def test_dataset_setup(): | |
| 51 | 
             
                print("=" * 50)
         | 
| 52 |  | 
| 53 | 
             
                # Test token from user
         | 
| 54 | 
            -
                test_token = " | 
| 55 |  | 
| 56 | 
             
                print(f"Testing dataset setup with token: {'*' * 10}...{test_token[-4:]}")
         | 
| 57 |  | 
| @@ -89,7 +89,7 @@ def test_space_deployment(): | |
| 89 | 
             
                print("=" * 50)
         | 
| 90 |  | 
| 91 | 
             
                # Test token from user
         | 
| 92 | 
            -
                test_token = ""
         | 
| 93 |  | 
| 94 | 
             
                print(f"Testing space deployment with token: {'*' * 10}...{test_token[-4:]}")
         | 
| 95 |  | 
|  | |
| 17 | 
             
                print("=" * 50)
         | 
| 18 |  | 
| 19 | 
             
                # Test token from user
         | 
| 20 | 
            +
                test_token = "xxx"
         | 
| 21 |  | 
| 22 | 
             
                print(f"Testing token: {'*' * 10}...{test_token[-4:]}")
         | 
| 23 |  | 
|  | |
| 51 | 
             
                print("=" * 50)
         | 
| 52 |  | 
| 53 | 
             
                # Test token from user
         | 
| 54 | 
            +
                test_token = "xxxx"
         | 
| 55 |  | 
| 56 | 
             
                print(f"Testing dataset setup with token: {'*' * 10}...{test_token[-4:]}")
         | 
| 57 |  | 
|  | |
| 89 | 
             
                print("=" * 50)
         | 
| 90 |  | 
| 91 | 
             
                # Test token from user
         | 
| 92 | 
            +
                test_token = "xxxx"
         | 
| 93 |  | 
| 94 | 
             
                print(f"Testing space deployment with token: {'*' * 10}...{test_token[-4:]}")
         | 
| 95 |  | 
