Spaces:
Sleeping
Sleeping
| #!/usr/bin/env python3 | |
| """ | |
| Test script to verify TTS service core functionality is preserved after logging fixes. | |
| This can be run in the Hugging Face environment to verify everything works. | |
| """ | |
| def test_tts_functionality(): | |
| """Test core TTS functionality without actually running synthesis""" | |
| print("π§ͺ Testing TTS Service Core Functionality") | |
| print("=" * 60) | |
| try: | |
| # Test imports and basic setup | |
| print("1οΈβ£ Testing imports...") | |
| import torch | |
| import numpy as np | |
| print(" β Core dependencies imported successfully") | |
| # Test device detection | |
| print("2οΈβ£ Testing device detection...") | |
| device = torch.device("cuda" if torch.cuda.is_available() else "cpu") | |
| print(f" β Device detected: {device}") | |
| # Test logging functions | |
| print("3οΈβ£ Testing logging functions...") | |
| from app import safe_log, logging_ok | |
| print(f" β Logging status: {'OK' if logging_ok else 'FALLBACK'}") | |
| safe_log("info", "Test message from functionality test") | |
| print(" β Safe logging works") | |
| # Test MCP availability | |
| print("4οΈβ£ Testing MCP integration...") | |
| from app import MCP_AVAILABLE | |
| print(f" β MCP Available: {'Yes' if MCP_AVAILABLE else 'No'}") | |
| # Test voice presets | |
| print("5οΈβ£ Testing voice presets...") | |
| from app import VOICE_PRESETS | |
| print(f" β Voice presets loaded: {len(VOICE_PRESETS)} options") | |
| for i, (code, desc) in enumerate(VOICE_PRESETS[:3]): # Show first 3 | |
| print(f" {i+1}. {code}: {desc}") | |
| if len(VOICE_PRESETS) > 3: | |
| print(f" ... and {len(VOICE_PRESETS)-3} more") | |
| print("\nπ All functionality tests passed!") | |
| return True | |
| except Exception as e: | |
| print(f"\nβ Functionality test failed: {e}") | |
| import traceback | |
| traceback.print_exc() | |
| return False | |
| def test_synthesis_stub(): | |
| """Test synthesis function structure without actual model loading""" | |
| print("\nπ€ Testing Synthesis Function Structure") | |
| print("=" * 60) | |
| try: | |
| from app import synthesize_speech | |
| print("β synthesize_speech function imported successfully") | |
| # Test with empty input (should return error gracefully) | |
| result = synthesize_speech("", "v2/en_speaker_6") | |
| if result[0] is None and "Please enter some text" in result[1]: | |
| print("β Empty input handling works correctly") | |
| else: | |
| print("β οΈ Empty input handling might need review") | |
| print("β Synthesis function structure is correct") | |
| return True | |
| except Exception as e: | |
| print(f"β Synthesis function test failed: {e}") | |
| return False | |
| def test_gradio_interface(): | |
| """Test that Gradio interface can be created""" | |
| print("\nπ₯οΈ Testing Gradio Interface Creation") | |
| print("=" * 60) | |
| try: | |
| # This would normally create the interface | |
| # We'll just verify the imports work | |
| import gradio as gr | |
| print("β Gradio imported successfully") | |
| # Test that our app structure is compatible | |
| from app import VOICE_PRESETS, get_system_info | |
| info = get_system_info() | |
| print("β System info function works") | |
| print(f" System info preview: {info[:100]}...") | |
| print("β Gradio interface structure is compatible") | |
| return True | |
| except ImportError: | |
| print("β οΈ Gradio not available (expected in local environment)") | |
| return True # This is expected locally | |
| except Exception as e: | |
| print(f"β Gradio interface test failed: {e}") | |
| return False | |
| if __name__ == "__main__": | |
| print("π§ TTS Service Functionality Verification") | |
| print("π― Testing that logging fixes preserve core functionality") | |
| print("=" * 80) | |
| success = True | |
| # Run all tests | |
| if not test_tts_functionality(): | |
| success = False | |
| if not test_synthesis_stub(): | |
| success = False | |
| if not test_gradio_interface(): | |
| success = False | |
| print("\n" + "=" * 80) | |
| if success: | |
| print("π ALL FUNCTIONALITY TESTS PASSED!") | |
| print("β TTS service core functionality is preserved") | |
| print("β Logging fixes don't break existing features") | |
| print("β Ready for deployment with improved logging") | |
| else: | |
| print("β SOME FUNCTIONALITY TESTS FAILED!") | |
| print("β Review the errors above before deployment") | |
| print(f"\nπ Test Summary:") | |
| print(f" β’ Core imports and device detection: {'β ' if success else 'β'}") | |
| print(f" β’ Logging system integration: {'β ' if success else 'β'}") | |
| print(f" β’ MCP compatibility: {'β ' if success else 'β'}") | |
| print(f" β’ Voice presets and synthesis: {'β ' if success else 'β'}") | |
| print(f" β’ Interface compatibility: {'β ' if success else 'β'}") |