Spaces:
Sleeping
Sleeping
File size: 9,600 Bytes
4cdaca5 0df1705 4cdaca5 0df1705 4cdaca5 0df1705 4cdaca5 0df1705 4cdaca5 0df1705 4cdaca5 0df1705 4cdaca5 0df1705 4cdaca5 |
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 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 |
"""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())
|