Spaces:
				
			
			
	
			
			
					
		Running
		
	
	
	
			
			
	
	
	
	
		
		
					
		Running
		
	File size: 10,180 Bytes
			
			| d291e63 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 | #!/usr/bin/env python3
"""
Test script for deployment components verification
Tests Trackio Space deployment and model repository deployment components
"""
import os
import sys
import json
from pathlib import Path
def test_trackio_space_components():
    """Test Trackio Space deployment components"""
    print("π Testing Trackio Space Deployment Components")
    print("=" * 50)
    
    # Test 1: Check if deployment script exists
    deploy_script = Path("scripts/trackio_tonic/deploy_trackio_space.py")
    if deploy_script.exists():
        print("β
 Trackio Space deployment script exists")
    else:
        print("β Trackio Space deployment script missing")
        return False
    
    # Test 2: Check if app.py template exists
    app_template = Path("templates/spaces/app.py")
    if app_template.exists():
        print("β
 Gradio app template exists")
        
        # Check if it has required components
        with open(app_template, 'r', encoding='utf-8') as f:
            content = f.read()
            if "class TrackioSpace" in content:
                print("β
 TrackioSpace class implemented")
            else:
                print("β TrackioSpace class missing")
                return False
            
            if "def create_experiment" in content:
                print("β
 Experiment creation functionality")
            else:
                print("β Experiment creation missing")
                return False
            
            if "def log_metrics" in content:
                print("β
 Metrics logging functionality")
            else:
                print("β Metrics logging missing")
                return False
            
            if "def get_experiment" in content:
                print("β
 Experiment retrieval functionality")
            else:
                print("β Experiment retrieval missing")
                return False
    else:
        print("β Gradio app template missing")
        return False
    
    # Test 3: Check if requirements.txt exists
    requirements = Path("templates/spaces/requirements.txt")
    if requirements.exists():
        print("β
 Space requirements file exists")
        
        # Check for required dependencies
        with open(requirements, 'r', encoding='utf-8') as f:
            content = f.read()
            required_deps = ['gradio', 'pandas', 'plotly', 'datasets', 'huggingface-hub']
            for dep in required_deps:
                if dep in content:
                    print(f"β
 Required dependency: {dep}")
                else:
                    print(f"β Missing dependency: {dep}")
                    return False
    else:
        print("β Space requirements file missing")
        return False
    
    # Test 4: Check if README template exists
    readme_template = Path("templates/spaces/README.md")
    if readme_template.exists():
        print("β
 Space README template exists")
        
        # Check for required metadata
        with open(readme_template, 'r', encoding='utf-8') as f:
            content = f.read()
            if "title:" in content and "sdk: gradio" in content:
                print("β
 HF Spaces metadata present")
            else:
                print("β HF Spaces metadata missing")
                return False
    else:
        print("β Space README template missing")
        return False
    
    print("β
 All Trackio Space components verified!")
    return True
def test_model_repository_components():
    """Test model repository deployment components"""
    print("\nπ Testing Model Repository Deployment Components")
    print("=" * 50)
    
    # Test 1: Check if push script exists
    push_script = Path("scripts/model_tonic/push_to_huggingface.py")
    if push_script.exists():
        print("β
 Model push script exists")
    else:
        print("β Model push script missing")
        return False
    
    # Test 2: Check if quantize script exists
    quantize_script = Path("scripts/model_tonic/quantize_model.py")
    if quantize_script.exists():
        print("β
 Model quantization script exists")
    else:
        print("β Model quantization script missing")
        return False
    
    # Test 3: Check if model card template exists
    model_card_template = Path("templates/model_card.md")
    if model_card_template.exists():
        print("β
 Model card template exists")
        
        # Check for required sections
        with open(model_card_template, 'r', encoding='utf-8') as f:
            content = f.read()
            required_sections = ['base_model:', 'pipeline_tag:', 'tags:']
            for section in required_sections:
                if section in content:
                    print(f"β
 Required section: {section}")
                else:
                    print(f"β Missing section: {section}")
                    return False
    else:
        print("β Model card template missing")
        return False
    
    # Test 4: Check if model card generator exists
    card_generator = Path("scripts/model_tonic/generate_model_card.py")
    if card_generator.exists():
        print("β
 Model card generator exists")
    else:
        print("β Model card generator missing")
        return False
    
    # Test 5: Check push script functionality
    with open(push_script, 'r', encoding='utf-8') as f:
        content = f.read()
        required_functions = [
            'def create_repository',
            'def upload_model_files',
            'def create_model_card',
            'def validate_model_path'
        ]
        for func in required_functions:
            if func in content:
                print(f"β
 Required function: {func}")
            else:
                print(f"β Missing function: {func}")
                return False
    
    print("β
 All Model Repository components verified!")
    return True
def test_integration_components():
    """Test integration between components"""
    print("\nπ Testing Integration Components")
    print("=" * 50)
    
    # Test 1: Check if launch script integrates deployment
    launch_script = Path("launch.sh")
    if launch_script.exists():
        print("β
 Launch script exists")
        
        with open(launch_script, 'r', encoding='utf-8') as f:
            content = f.read()
            if "deploy_trackio_space.py" in content:
                print("β
 Trackio Space deployment integrated")
            else:
                print("β Trackio Space deployment not integrated")
                return False
            
            if "push_to_huggingface.py" in content:
                print("β
 Model push integrated")
            else:
                print("β Model push not integrated")
                return False
    else:
        print("β Launch script missing")
        return False
    
    # Test 2: Check if monitoring integration exists
    monitoring_script = Path("src/monitoring.py")
    if monitoring_script.exists():
        print("β
 Monitoring script exists")
        
        with open(monitoring_script, 'r', encoding='utf-8') as f:
            content = f.read()
            if "class SmolLM3Monitor" in content:
                print("β
 SmolLM3Monitor class implemented")
            else:
                print("β SmolLM3Monitor class missing")
                return False
    else:
        print("β Monitoring script missing")
        return False
    
    # Test 3: Check if dataset integration exists
    dataset_script = Path("scripts/dataset_tonic/setup_hf_dataset.py")
    if dataset_script.exists():
        print("β
 Dataset setup script exists")
        
        with open(dataset_script, 'r', encoding='utf-8') as f:
            content = f.read()
            if "def setup_trackio_dataset" in content:
                print("β
 Dataset setup function implemented")
            else:
                print("β Dataset setup function missing")
                return False
    else:
        print("β Dataset setup script missing")
        return False
    
    print("β
 All integration components verified!")
    return True
def test_token_validation():
    """Test token validation functionality"""
    print("\nπ Testing Token Validation")
    print("=" * 50)
    
    # Test 1: Check if validation script exists
    validation_script = Path("scripts/validate_hf_token.py")
    if validation_script.exists():
        print("β
 Token validation script exists")
        
        with open(validation_script, 'r', encoding='utf-8') as f:
            content = f.read()
            if "def validate_hf_token" in content:
                print("β
 Token validation function implemented")
            else:
                print("β Token validation function missing")
                return False
    else:
        print("β Token validation script missing")
        return False
    
    print("β
 Token validation components verified!")
    return True
def main():
    """Run all component tests"""
    print("π Deployment Components Verification")
    print("=" * 50)
    
    tests = [
        test_trackio_space_components,
        test_model_repository_components,
        test_integration_components,
        test_token_validation
    ]
    
    all_passed = True
    for test in tests:
        try:
            if not test():
                all_passed = False
        except Exception as e:
            print(f"β Test failed with error: {e}")
            all_passed = False
    
    print("\n" + "=" * 50)
    if all_passed:
        print("π ALL COMPONENTS VERIFIED SUCCESSFULLY!")
        print("β
 Trackio Space deployment components: Complete")
        print("β
 Model repository deployment components: Complete")
        print("β
 Integration components: Complete")
        print("β
 Token validation components: Complete")
        print("\nAll important deployment components are properly implemented!")
    else:
        print("β SOME COMPONENTS NEED ATTENTION!")
        print("Please check the failed components above.")
    
    return all_passed
if __name__ == "__main__":
    success = main()
    sys.exit(0 if success else 1)  | 
