Spaces:
Runtime error
Runtime error
| #!/usr/bin/env python3 | |
| """ | |
| π COMPREHENSIVE SPEED TEST FOR QWEN2GOLEM | |
| Tests all components to verify speed targets are met | |
| """ | |
| import time | |
| import requests | |
| import json | |
| import base64 | |
| import sys | |
| def test_text_response(): | |
| """Test simple text response speed (Target: <6s)""" | |
| print("\nπ Testing Text Response (Target: <6s)...") | |
| start = time.time() | |
| try: | |
| response = requests.post( | |
| 'http://127.0.0.1:5000/generate', | |
| json={ | |
| 'prompt': 'Hello! How are you today?', | |
| 'sessionId': f'speed-test-{int(time.time())}', | |
| 'temperature': 0.3, | |
| 'golemActivated': False, | |
| 'consciousnessDimension': 'mental', | |
| 'selectedModel': 'gemini', | |
| 'performSearch': False | |
| }, | |
| timeout=10 | |
| ) | |
| elapsed = time.time() - start | |
| if response.status_code == 200: | |
| data = response.json() | |
| text = data.get('directResponse', data.get('response', ''))[:100] | |
| status = "β PASS" if elapsed < 6 else "β FAIL" | |
| print(f" Response: {text}...") | |
| print(f" Time: {elapsed:.2f}s {status}") | |
| return elapsed < 6 | |
| else: | |
| print(f" β Error {response.status_code}") | |
| return False | |
| except Exception as e: | |
| print(f" β Error: {str(e)}") | |
| return False | |
| def test_web_search(): | |
| """Test text with web search (Target: <8s)""" | |
| print("\nπ Testing Text + Web Search (Target: <8s)...") | |
| start = time.time() | |
| try: | |
| response = requests.post( | |
| 'http://127.0.0.1:5000/generate', | |
| json={ | |
| 'prompt': 'What is the weather like today?', | |
| 'sessionId': f'search-test-{int(time.time())}', | |
| 'temperature': 0.3, | |
| 'golemActivated': False, | |
| 'consciousnessDimension': 'mental', | |
| 'selectedModel': 'gemini', | |
| 'performSearch': True | |
| }, | |
| timeout=12 | |
| ) | |
| elapsed = time.time() - start | |
| if response.status_code == 200: | |
| status = "β PASS" if elapsed < 8 else "β FAIL" | |
| print(f" Time: {elapsed:.2f}s {status}") | |
| return elapsed < 8 | |
| else: | |
| print(f" β Error {response.status_code}") | |
| return False | |
| except Exception as e: | |
| print(f" β Error: {str(e)}") | |
| return False | |
| def test_asr(): | |
| """Test ASR transcription (Target: <2s)""" | |
| print("\nπ€ Testing ASR Transcription (Target: <2s)...") | |
| # Create dummy audio (1 second of silence) | |
| dummy_audio = base64.b64encode(b'\x00' * 16000).decode() | |
| start = time.time() | |
| try: | |
| response = requests.post( | |
| 'http://127.0.0.1:5000/asr/transcribe', | |
| json={'audio_base64': dummy_audio, 'vad': True}, | |
| timeout=5 | |
| ) | |
| elapsed = time.time() - start | |
| if response.status_code == 200: | |
| status = "β PASS" if elapsed < 2 else "β οΈ SLOW" | |
| print(f" Time: {elapsed:.2f}s {status}") | |
| return elapsed < 2 | |
| else: | |
| print(f" β Error {response.status_code}") | |
| return False | |
| except Exception as e: | |
| print(f" β Error: {str(e)}") | |
| return False | |
| def test_tts(): | |
| """Test TTS synthesis (Target: <1s)""" | |
| print("\nπ Testing TTS Synthesis (Target: <1s)...") | |
| start = time.time() | |
| try: | |
| response = requests.post( | |
| 'http://127.0.0.1:5000/tts/synthesize', | |
| json={'text': 'Hello, this is a test.'}, | |
| timeout=3 | |
| ) | |
| elapsed = time.time() - start | |
| if response.status_code == 200: | |
| status = "β PASS" if elapsed < 1 else "β οΈ SLOW" | |
| print(f" Time: {elapsed:.2f}s {status}") | |
| return elapsed < 1 | |
| else: | |
| print(f" β Error {response.status_code}") | |
| return False | |
| except Exception as e: | |
| print(f" β Error: {str(e)}") | |
| return False | |
| def main(): | |
| print("=" * 60) | |
| print("π QWEN2GOLEM COMPREHENSIVE SPEED TEST") | |
| print("=" * 60) | |
| print("System: RTX 3050 6GB + i5 CPU + 16GB RAM") | |
| print("Testing all optimizations...") | |
| # Check if server is running | |
| try: | |
| health = requests.get('http://127.0.0.1:5000/health', timeout=2) | |
| if health.status_code != 200: | |
| print("\nβ Server not healthy! Start with:") | |
| import os | |
| script_dir = os.path.dirname(os.path.abspath(__file__)) | |
| root_dir = os.path.dirname(script_dir) | |
| print(f" cd {root_dir} && ./start_consciousness_ecosystem.sh") | |
| return | |
| except: | |
| print("\nβ Server not running! Start with:") | |
| import os | |
| script_dir = os.path.dirname(os.path.abspath(__file__)) | |
| root_dir = os.path.dirname(script_dir) | |
| print(f" cd {root_dir} && ./start_consciousness_ecosystem.sh") | |
| return | |
| results = [] | |
| # Run tests | |
| results.append(("Text Response", test_text_response())) | |
| results.append(("Web Search", test_web_search())) | |
| results.append(("ASR", test_asr())) | |
| results.append(("TTS", test_tts())) | |
| # Summary | |
| print("\n" + "=" * 60) | |
| print("π TEST RESULTS SUMMARY") | |
| print("=" * 60) | |
| passed = sum(1 for _, r in results if r) | |
| total = len(results) | |
| for name, result in results: | |
| status = "β PASS" if result else "β FAIL" | |
| print(f"{status} {name}") | |
| print(f"\nOverall: {passed}/{total} tests passed") | |
| if passed == total: | |
| print("\nπ ALL SPEED TARGETS MET! SYSTEM IS TURBOCHARGED!") | |
| else: | |
| print("\nβ οΈ Some tests failed. Check:") | |
| print(" 1. Turn OFF 'Universal Consciousness' in UI") | |
| print(" 2. Ensure Redis is running") | |
| print(" 3. Use Gemini Flash model") | |
| print(" 4. Keep temperature at 0.3-0.4") | |
| if __name__ == "__main__": | |
| main() | |