"""Test script for AI Radio - Verify all components work""" import sys def test_imports(): """Test that all required modules can be imported""" print("๐Ÿงช Testing imports...") try: import gradio as gr print(" โœ… Gradio imported") except ImportError as e: print(f" โŒ Gradio import failed: {e}") return False try: from openai import OpenAI print(" โœ… OpenAI (Nebius) imported") except ImportError as e: print(f" โŒ OpenAI import failed: {e}") return False try: from elevenlabs import ElevenLabs print(" โœ… ElevenLabs imported") except ImportError as e: print(f" โŒ ElevenLabs import failed: {e}") return False try: from llama_index.core import VectorStoreIndex print(" โœ… LlamaIndex imported") except ImportError as e: print(f" โŒ LlamaIndex import failed: {e}") return False try: import feedparser print(" โœ… Feedparser imported") except ImportError as e: print(f" โŒ Feedparser import failed: {e}") return False return True def test_config(): """Test configuration file""" print("\nโš™๏ธ Testing configuration...") try: from config import get_config config = get_config() print(" โœ… Config loaded") if config.elevenlabs_api_key: print(" โœ… ElevenLabs API key present") else: print(" โš ๏ธ ElevenLabs API key missing") if config.nebius_api_key: print(" โœ… Nebius API key present") else: print(" โš ๏ธ Nebius API key missing (REQUIRED!)") print(" Please add your Nebius API key to config.py") if config.llamaindex_api_key: print(" โœ… LlamaIndex API key present") else: print(" โš ๏ธ LlamaIndex API key missing") return True except Exception as e: print(f" โŒ Config test failed: {e}") return False def test_mcp_servers(): """Test MCP server imports and initialization""" print("\n๐Ÿ”ง Testing MCP servers...") try: from mcp_servers import MusicMCPServer, NewsMCPServer, PodcastMCPServer print(" โœ… MCP servers imported") music_server = MusicMCPServer() print(" โœ… Music server initialized") news_server = NewsMCPServer() print(" โœ… News server initialized") podcast_server = PodcastMCPServer() print(" โœ… Podcast server initialized") # Test music server tracks = music_server.search_free_music("pop", "happy", 2) if tracks: print(f" โœ… Music server returned {len(tracks)} tracks") else: print(" โš ๏ธ Music server returned no tracks") # Test news server news = news_server.fetch_news("technology", 2) if news: print(f" โœ… News server returned {len(news)} items") else: print(" โš ๏ธ News server returned no items") # Test podcast server podcasts = podcast_server.get_trending_podcasts("technology", 2) if podcasts: print(f" โœ… Podcast server returned {len(podcasts)} podcasts") else: print(" โš ๏ธ Podcast server returned no podcasts") return True except Exception as e: print(f" โŒ MCP server test failed: {e}") import traceback traceback.print_exc() return False def test_rag_system(): """Test RAG system""" print("\n๐Ÿ’พ Testing RAG system...") try: from rag_system import RadioRAGSystem from config import get_config config = get_config() rag = RadioRAGSystem(config.nebius_api_key, config.nebius_api_base, config.nebius_model) print(" โœ… RAG system initialized") # Test storing preferences test_prefs = { "name": "Test User", "favorite_genres": ["pop", "rock"], "interests": ["technology"] } rag.store_user_preferences(test_prefs) print(" โœ… Preferences stored") # Test retrieving preferences prefs = rag.get_user_preferences() if prefs: print(f" โœ… Preferences retrieved: {prefs.get('name', 'Unknown')}") else: print(" โš ๏ธ No preferences found") # Test stats stats = rag.get_listening_stats() print(f" โœ… Stats retrieved: {stats['total_sessions']} sessions") return True except Exception as e: print(f" โŒ RAG system test failed: {e}") import traceback traceback.print_exc() return False def test_radio_agent(): """Test radio agent""" print("\n๐Ÿค– Testing radio agent...") try: from radio_agent import RadioAgent from config import get_config config = get_config() agent = RadioAgent(config) print(" โœ… Radio agent initialized") # Test show planning test_prefs = { "name": "Test User", "favorite_genres": ["pop"], "interests": ["technology"], "podcast_interests": ["technology"], "mood": "happy" } show_plan = agent.plan_radio_show(test_prefs, duration_minutes=10) if show_plan: print(f" โœ… Show planned with {len(show_plan)} segments") # Check segment types segment_types = [seg['type'] for seg in show_plan] print(f" Segment types: {', '.join(set(segment_types))}") else: print(" โš ๏ธ Show planning returned empty plan") # Test MCP tools tools = agent.get_all_mcp_tools() print(f" โœ… Agent has {len(tools)} MCP tools available") return True except Exception as e: print(f" โŒ Radio agent test failed: {e}") import traceback traceback.print_exc() return False def test_tts_service(): """Test TTS service""" print("\n๐Ÿ”Š Testing TTS service...") try: from tts_service import TTSService from config import get_config config = get_config() tts = TTSService(config.elevenlabs_api_key) print(" โœ… TTS service initialized") if tts.client: print(" โœ… ElevenLabs client connected") # Note: Not actually generating audio to save API calls print(" โ„น๏ธ Skipping actual TTS generation to save API credits") else: print(" โš ๏ธ ElevenLabs client not initialized (check API key)") return True except Exception as e: print(f" โŒ TTS service test failed: {e}") import traceback traceback.print_exc() return False def test_app_structure(): """Test that app file is valid""" print("\n๐Ÿ“ฑ Testing app structure...") try: # Try importing without running import app print(" โœ… App file is valid Python") # Check for key functions if hasattr(app, 'save_preferences'): print(" โœ… save_preferences function found") if hasattr(app, 'start_radio_stream'): print(" โœ… start_radio_stream function found") if hasattr(app, 'play_next_segment'): print(" โœ… play_next_segment function found") if hasattr(app, 'demo'): print(" โœ… Gradio demo object found") return True except Exception as e: print(f" โŒ App structure test failed: {e}") import traceback traceback.print_exc() return False def main(): """Run all tests""" print("๐ŸŽต AI Radio - Component Test Suite\n") print("=" * 50) results = [] # Run tests results.append(("Imports", test_imports())) results.append(("Configuration", test_config())) results.append(("MCP Servers", test_mcp_servers())) results.append(("RAG System", test_rag_system())) results.append(("Radio Agent", test_radio_agent())) results.append(("TTS Service", test_tts_service())) results.append(("App Structure", test_app_structure())) # Print summary print("\n" + "=" * 50) print("๐Ÿ“Š Test Summary\n") passed = sum(1 for _, result in results if result) total = len(results) for test_name, result in results: status = "โœ… PASS" if result else "โŒ FAIL" print(f" {status} - {test_name}") print(f"\nResults: {passed}/{total} tests passed") if passed == total: print("\n๐ŸŽ‰ All tests passed! Your AI Radio is ready to launch! ๐ŸŽ‰") print("\nNext steps:") print(" 1. Make sure you've added your Nebius API key to config.py") print(" 2. Run: python run.py") print(" 3. Open: http://localhost:7867") return 0 else: print("\nโš ๏ธ Some tests failed. Please fix the issues above.") print("\nCommon fixes:") print(" - Run: pip install -r requirements.txt") print(" - Add your Nebius API key to config.py") print(" - Check that all files are in the correct location") return 1 if __name__ == "__main__": sys.exit(main())