Spaces:
Paused
Paused
| #!/usr/bin/env python3 | |
| """ | |
| Basic test script to verify ChatCal Voice structure. | |
| Run this to check if all imports work and basic functionality is available. | |
| """ | |
| import os | |
| import sys | |
| import asyncio | |
| from datetime import datetime | |
| # Add current directory to path for imports | |
| sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) | |
| def test_imports(): | |
| """Test that all core modules import correctly.""" | |
| print("π Testing imports...") | |
| try: | |
| from core.config import config | |
| print("β Config imported successfully") | |
| from core.session import SessionData | |
| print("β SessionData imported successfully") | |
| from core.session_manager import SessionManager | |
| print("β SessionManager imported successfully") | |
| from core.llm_provider import get_llm | |
| print("β LLM Provider imported successfully") | |
| from core.chat_agent import ChatCalAgent | |
| print("β ChatCalAgent imported successfully") | |
| from core.calendar_service import CalendarService | |
| print("β CalendarService imported successfully") | |
| from core.audio_handler import AudioHandler | |
| print("β AudioHandler imported successfully") | |
| print("π All imports successful!") | |
| return True | |
| except Exception as e: | |
| print(f"β Import error: {e}") | |
| return False | |
| def test_basic_functionality(): | |
| """Test basic functionality of core components.""" | |
| print("\nπ§ͺ Testing basic functionality...") | |
| try: | |
| # Test config | |
| from core.config import config | |
| print(f"π App Name: {config.app_name}") | |
| print(f"π Default Voice: {config.default_voice}") | |
| # Test session creation | |
| from core.session import SessionData | |
| session = SessionData(session_id="test_session") | |
| session.add_message("user", "Hello test") | |
| print(f"π¬ Session created with {len(session.conversation_history)} messages") | |
| # Test LLM provider | |
| from core.llm_provider import get_llm | |
| llm = get_llm() | |
| print(f"π€ LLM initialized: {type(llm).__name__}") | |
| # Test calendar service | |
| from core.calendar_service import CalendarService | |
| calendar = CalendarService() | |
| print(f"π Calendar service initialized (demo_mode: {calendar.demo_mode})") | |
| # Test audio handler | |
| from core.audio_handler import AudioHandler | |
| audio = AudioHandler() | |
| status = audio.get_audio_status() | |
| print(f"π΅ Audio handler initialized (demo_mode: {status['demo_mode']})") | |
| print("π Basic functionality tests passed!") | |
| return True | |
| except Exception as e: | |
| print(f"β Functionality test error: {e}") | |
| return False | |
| async def test_chat_agent(): | |
| """Test the chat agent with a simple message.""" | |
| print("\n㪠Testing chat agent...") | |
| try: | |
| from core.chat_agent import ChatCalAgent | |
| from core.session import SessionData | |
| agent = ChatCalAgent() | |
| session = SessionData(session_id="test_chat") | |
| # Test message processing | |
| response = await agent.process_message("Hello, I'm John", session) | |
| print(f"π€ Agent response: {response[:100]}...") | |
| print(f"π€ User info extracted: {session.user_info}") | |
| print("π Chat agent test passed!") | |
| return True | |
| except Exception as e: | |
| print(f"β Chat agent test error: {e}") | |
| return False | |
| def test_gradio_compatibility(): | |
| """Test Gradio compatibility.""" | |
| print("\nπ¨ Testing Gradio compatibility...") | |
| try: | |
| import gradio as gr | |
| print(f"β Gradio version: {gr.__version__}") | |
| # Test basic Gradio components | |
| with gr.Blocks() as demo: | |
| gr.Markdown("# Test Interface") | |
| chatbot = gr.Chatbot() | |
| msg = gr.Textbox(label="Message") | |
| print("β Gradio interface creation successful") | |
| print("π Gradio compatibility test passed!") | |
| return True | |
| except Exception as e: | |
| print(f"β Gradio compatibility error: {e}") | |
| return False | |
| async def main(): | |
| """Run all tests.""" | |
| print("π ChatCal Voice - Basic Structure Test") | |
| print("=" * 50) | |
| # Set minimal environment for testing | |
| os.environ.setdefault("GROQ_API_KEY", "test_key") | |
| os.environ.setdefault("MY_PHONE_NUMBER", "+1-555-123-4567") | |
| os.environ.setdefault("MY_EMAIL_ADDRESS", "test@example.com") | |
| os.environ.setdefault("SECRET_KEY", "test_secret") | |
| tests = [ | |
| ("Imports", test_imports), | |
| ("Basic Functionality", test_basic_functionality), | |
| ("Chat Agent", test_chat_agent), | |
| ("Gradio Compatibility", test_gradio_compatibility) | |
| ] | |
| passed = 0 | |
| total = len(tests) | |
| for test_name, test_func in tests: | |
| print(f"\n{'='*20} {test_name} {'='*20}") | |
| try: | |
| if asyncio.iscoroutinefunction(test_func): | |
| result = await test_func() | |
| else: | |
| result = test_func() | |
| if result: | |
| passed += 1 | |
| except Exception as e: | |
| print(f"β {test_name} failed with exception: {e}") | |
| print(f"\n{'='*50}") | |
| print(f"π Test Results: {passed}/{total} tests passed") | |
| if passed == total: | |
| print("π All tests passed! ChatCal Voice structure is ready.") | |
| print("\nπ Next steps:") | |
| print("1. Update STT_SERVICE_URL and TTS_SERVICE_URL in .env") | |
| print("2. Add your actual API keys") | |
| print("3. Deploy to Hugging Face Spaces") | |
| else: | |
| print("β Some tests failed. Check the errors above.") | |
| return False | |
| return True | |
| if __name__ == "__main__": | |
| asyncio.run(main()) |