Spaces:
Sleeping
Sleeping
| #!/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) | |