Spaces:
Sleeping
Sleeping
| """ | |
| VocalGuard Backend Test Script | |
| Run this to verify backend setup is working correctly. | |
| """ | |
| import sys | |
| import os | |
| print("=" * 60) | |
| print("VocalGuard Backend Test") | |
| print("=" * 60) | |
| # Test 1: Python Version | |
| print("\nβ Testing Python version...") | |
| if sys.version_info >= (3, 8): | |
| print(f" β Python {sys.version.split()[0]} (OK)") | |
| else: | |
| print(f" β Python {sys.version.split()[0]} (Need 3.8+)") | |
| sys.exit(1) | |
| # Test 2: Import Core Libraries | |
| print("\nβ Testing core libraries...") | |
| try: | |
| import fastapi | |
| print(f" β FastAPI {fastapi.__version__}") | |
| except ImportError: | |
| print(" β FastAPI not found. Run: pip install -r requirements.txt") | |
| sys.exit(1) | |
| try: | |
| import firebase_admin | |
| print(f" β Firebase Admin SDK installed") | |
| except ImportError: | |
| print(" β Firebase Admin not found. Run: pip install -r requirements.txt") | |
| sys.exit(1) | |
| try: | |
| import librosa | |
| print(f" β Librosa {librosa.__version__}") | |
| except ImportError: | |
| print(" β Librosa not found. Run: pip install -r requirements.txt") | |
| sys.exit(1) | |
| try: | |
| import numpy | |
| print(f" β NumPy {numpy.__version__}") | |
| except ImportError: | |
| print(" β NumPy not found. Run: pip install -r requirements.txt") | |
| sys.exit(1) | |
| # Test 3: Check Environment Variables | |
| print("\nβ Checking environment configuration...") | |
| env_file = ".env" | |
| if os.path.exists(env_file): | |
| print(f" β .env file found") | |
| with open(env_file) as f: | |
| content = f.read() | |
| if "GOOGLE_APPLICATION_CREDENTIALS" in content: | |
| print(f" β GOOGLE_APPLICATION_CREDENTIALS configured") | |
| else: | |
| print(f" β οΈ GOOGLE_APPLICATION_CREDENTIALS not set in .env") | |
| else: | |
| print(f" β οΈ .env file not found (optional)") | |
| # Test 4: Check Processor Module | |
| print("\nβ Testing processor module...") | |
| try: | |
| import processor | |
| print(f" β Processor module loaded") | |
| print(f" π Chunk size: {processor.CHUNK_SECONDS}s") | |
| print(f" π€ Sample rate: {processor.TARGET_SR}Hz") | |
| except Exception as e: | |
| print(f" β Processor import failed: {e}") | |
| sys.exit(1) | |
| # Test 5: Check Main API Module | |
| print("\nβ Testing main API module...") | |
| try: | |
| import main | |
| print(f" β Main API module loaded") | |
| print(f" π FastAPI app created") | |
| except Exception as e: | |
| print(f" β Main module import failed: {e}") | |
| sys.exit(1) | |
| # Test 6: Optional - Check AI Models | |
| print("\nβ Checking AI models (optional)...") | |
| try: | |
| import torch | |
| print(f" β PyTorch {torch.__version__}") | |
| if torch.cuda.is_available(): | |
| print(f" π CUDA available (GPU acceleration)") | |
| else: | |
| print(f" π» CPU mode (slower processing)") | |
| except ImportError: | |
| print(" β οΈ PyTorch not installed (will use heuristics)") | |
| try: | |
| from transformers import WhisperProcessor | |
| print(f" β Transformers library available") | |
| except ImportError: | |
| print(" β οΈ Transformers not installed (transcription disabled)") | |
| try: | |
| from sentence_transformers import SentenceTransformer | |
| print(f" β Sentence Transformers available") | |
| except ImportError: | |
| print(" β οΈ Sentence Transformers not installed") | |
| # Summary | |
| print("\n" + "=" * 60) | |
| print("β Backend test completed successfully!") | |
| print("=" * 60) | |
| print("\nπ Next steps:") | |
| print(" 1. Configure Firebase credentials in .env") | |
| print(" 2. Update frontend/app.js with Firebase config") | |
| print(" 3. Run: python main.py") | |
| print(" 4. Open: http://localhost:8000 (should see {\"status\":\"ok\"})") | |
| print("\nπ To start backend: python main.py") | |
| print("=" * 60) | |