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)