File size: 5,617 Bytes
b77cba7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""
Installation verification script
Checks that all components are properly installed and configured
"""

import sys
from pathlib import Path
import importlib

def check_python_version():
    """Check Python version."""
    print("Checking Python version...")
    version = sys.version_info
    if version.major >= 3 and version.minor >= 10:
        print(f"  βœ… Python {version.major}.{version.minor}.{version.micro}")
        return True
    else:
        print(f"  ❌ Python {version.major}.{version.minor}.{version.micro} (requires 3.10+)")
        return False

def check_package(package_name, import_name=None):
    """Check if a package is installed."""
    if import_name is None:
        import_name = package_name
    
    try:
        mod = importlib.import_module(import_name)
        version = getattr(mod, '__version__', 'unknown')
        print(f"  βœ… {package_name} ({version})")
        return True
    except ImportError:
        print(f"  ❌ {package_name} not found")
        return False

def check_cuda():
    """Check CUDA availability."""
    print("Checking CUDA...")
    try:
        import torch
        if torch.cuda.is_available():
            print(f"  βœ… CUDA available (version {torch.version.cuda})")
            print(f"     GPU: {torch.cuda.get_device_name(0)}")
            return True
        else:
            print("  ⚠️  CUDA not available (CPU mode)")
            return False
    except ImportError:
        print("  ❌ PyTorch not installed")
        return False

def check_files():
    """Check that all required files exist."""
    print("Checking project files...")
    
    required_files = [
        'src/__init__.py',
        'src/vad.py',
        'src/diarization.py',
        'src/pipeline.py',
        'src/utils.py',
        'app.py',
        'vad_diarization.py',
        'requirements.txt',
        'Dockerfile',
        'README.md'
    ]
    
    all_exist = True
    for file in required_files:
        path = Path(file)
        if path.exists():
            print(f"  βœ… {file}")
        else:
            print(f"  ❌ {file} missing")
            all_exist = False
    
    return all_exist

def check_hf_token():
    """Check for Hugging Face token."""
    print("Checking Hugging Face token...")
    import os
    token = os.environ.get('HF_TOKEN')
    if token:
        print(f"  βœ… HF_TOKEN found (length: {len(token)})")
        return True
    else:
        print("  ⚠️  HF_TOKEN not set (required for full pipeline)")
        print("     Set with: export HF_TOKEN='your_token_here'")
        return False

def test_vad():
    """Test VAD functionality."""
    print("Testing VAD...")
    try:
        from src.vad import SileroVAD
        vad = SileroVAD(threshold=0.5)
        print("  βœ… VAD initialized successfully")
        
        # Quick benchmark
        metrics = vad.benchmark_latency(duration_seconds=1.0)
        latency = metrics['latency_per_second_ms']
        print(f"  βœ… VAD latency: {latency:.2f}ms per second")
        
        if latency < 100:
            print("  βœ… Latency target achieved (<100ms)")
        else:
            print("  ⚠️  Latency above target")
        
        return True
    except Exception as e:
        print(f"  ❌ VAD test failed: {e}")
        return False

def main():
    """Run all verification checks."""
    print("\n" + "="*60)
    print("INSTALLATION VERIFICATION")
    print("="*60 + "\n")
    
    results = {}
    
    # Python version
    results['python'] = check_python_version()
    print()
    
    # Required packages
    print("Checking required packages...")
    packages = [
        ('torch', 'torch'),
        ('numpy', 'numpy'),
        ('librosa', 'librosa'),
        ('soundfile', 'soundfile'),
        ('gradio', 'gradio'),
        ('matplotlib', 'matplotlib'),
        ('silero-vad', 'silero_vad'),
        ('pyannote.audio', 'pyannote.audio')
    ]
    
    results['packages'] = all(check_package(name, imp) for name, imp in packages)
    print()
    
    # CUDA
    results['cuda'] = check_cuda()
    print()
    
    # Files
    results['files'] = check_files()
    print()
    
    # HF Token
    results['token'] = check_hf_token()
    print()
    
    # VAD test
    results['vad'] = test_vad()
    print()
    
    # Summary
    print("="*60)
    print("VERIFICATION SUMMARY")
    print("="*60)
    
    total = len(results)
    passed = sum(1 for v in results.values() if v)
    
    for check, result in results.items():
        status = "βœ… PASS" if result else "❌ FAIL"
        print(f"{check.upper():20s}: {status}")
    
    print()
    print(f"Results: {passed}/{total} checks passed")
    
    if passed == total:
        print("\nπŸŽ‰ All checks passed! System is ready to use.")
        print("\nNext steps:")
        print("1. Run demo: python vad_diarization.py")
        print("2. Launch Gradio: python app.py")
        print("3. Run benchmarks: python benchmarks/run_benchmarks.py --quick")
    elif results['python'] and results['packages'] and results['files']:
        print("\nβœ… Core system is functional.")
        if not results['token']:
            print("⚠️  Set HF_TOKEN for full pipeline functionality")
        if not results['cuda']:
            print("⚠️  CUDA not available, will use CPU (slower)")
    else:
        print("\n❌ Installation incomplete. Please fix the issues above.")
        print("\nTry running: ./setup.sh")
    
    print("="*60 + "\n")
    
    return passed == total

if __name__ == "__main__":
    success = main()
    sys.exit(0 if success else 1)