Spaces:
Sleeping
Sleeping
| #!/usr/bin/env python3 | |
| """ | |
| Bulletproof logging validation for TTS service. | |
| This script validates the logging fixes without requiring full dependencies. | |
| """ | |
| import ast | |
| import sys | |
| import os | |
| def validate_python_syntax(filepath): | |
| """Validate Python syntax by parsing the AST""" | |
| try: | |
| with open(filepath, 'r', encoding='utf-8') as f: | |
| content = f.read() | |
| # Parse the AST to check syntax | |
| ast.parse(content, filename=filepath) | |
| return True, "Syntax is valid" | |
| except SyntaxError as e: | |
| return False, f"Syntax error at line {e.lineno}: {e.msg}" | |
| except Exception as e: | |
| return False, f"Error reading file: {e}" | |
| def check_bulletproof_logging(filepath): | |
| """Check that bulletproof logging fixes are properly implemented""" | |
| try: | |
| with open(filepath, 'r', encoding='utf-8') as f: | |
| content = f.read() | |
| required_fixes = [ | |
| ('logging.disable(logging.CRITICAL)', 'Complete logging module disablement'), | |
| ('os.environ["PYTHONWARNINGS"] = "ignore"', 'Warning suppression'), | |
| ('def safe_log(level, message):', 'Print-based logging function'), | |
| ('print(f"[TTS-{level.upper()}] {message}", flush=True)', 'Bulletproof print logging'), | |
| ('quiet=True', 'Gradio quiet launch parameter'), | |
| ('logger.disabled = True', 'Individual logger disabling'), | |
| ('root_logger.handlers = []', 'Root logger cleanup') | |
| ] | |
| missing_fixes = [] | |
| for pattern, description in required_fixes: | |
| if pattern not in content: | |
| missing_fixes.append((pattern, description)) | |
| return len(missing_fixes) == 0, missing_fixes | |
| except Exception as e: | |
| return False, [(f"Error reading file: {e}", "File read error")] | |
| def check_dual_protocol_support(filepath): | |
| """Check that dual protocol support is implemented""" | |
| try: | |
| with open(filepath, 'r', encoding='utf-8') as f: | |
| content = f.read() | |
| dual_protocol_indicators = [ | |
| "dual protocol support", | |
| "both Gradio and MCP", | |
| "MCP-only mode", | |
| "Gradio Interface: Starting", | |
| "MCP Server: Available" | |
| ] | |
| found_indicators = [] | |
| for indicator in dual_protocol_indicators: | |
| if indicator.lower() in content.lower(): | |
| found_indicators.append(indicator) | |
| return len(found_indicators) >= 3, found_indicators | |
| except Exception as e: | |
| return False, [f"Error: {e}"] | |
| def check_consistency_with_stt(): | |
| """Check consistency with STT service logging approach""" | |
| try: | |
| stt_path = "/Users/petergits/dev/ChatCalAI-with-Voice/stt-gpu-service/app.py" | |
| if not os.path.exists(stt_path): | |
| return True, ["STT service not found for comparison"] | |
| with open(stt_path, 'r') as f: | |
| stt_content = f.read() | |
| with open('app.py', 'r') as f: | |
| tts_content = f.read() | |
| consistency_checks = [ | |
| 'logging.disable(logging.CRITICAL)', | |
| 'def safe_log(level, message):', | |
| 'flush=True' | |
| ] | |
| inconsistencies = [] | |
| for pattern in consistency_checks: | |
| stt_has = pattern in stt_content | |
| tts_has = pattern in tts_content | |
| if stt_has and not tts_has: | |
| inconsistencies.append(f"Missing in TTS: {pattern}") | |
| return len(inconsistencies) == 0, inconsistencies | |
| except Exception as e: | |
| return False, [f"Error checking consistency: {e}"] | |
| def main(): | |
| """Main validation function""" | |
| print("=" * 60) | |
| print("π οΈ TTS Service Bulletproof Logging Validation") | |
| print("=" * 60) | |
| app_path = "app.py" | |
| if not os.path.exists(app_path): | |
| print(f"β Error: {app_path} not found") | |
| return 1 | |
| all_passed = True | |
| # Test 1: Syntax validation | |
| print("1οΈβ£ Validating Python syntax...") | |
| syntax_ok, syntax_msg = validate_python_syntax(app_path) | |
| if syntax_ok: | |
| print(f" β {syntax_msg}") | |
| else: | |
| print(f" β {syntax_msg}") | |
| all_passed = False | |
| # Test 2: Bulletproof logging fixes check | |
| print("\n2οΈβ£ Checking bulletproof logging fixes...") | |
| logging_ok, logging_issues = check_bulletproof_logging(app_path) | |
| if logging_ok: | |
| print(" β All bulletproof logging fixes applied") | |
| else: | |
| print(" β Missing logging fixes:") | |
| for pattern, description in logging_issues: | |
| print(f" - {description}") | |
| all_passed = False | |
| # Test 3: Consistency with STT service | |
| print("\n3οΈβ£ Checking consistency with STT service...") | |
| consistency_ok, consistency_issues = check_consistency_with_stt() | |
| if consistency_ok: | |
| print(" β Consistent with STT service logging approach") | |
| else: | |
| print(" β Inconsistencies found:") | |
| for issue in consistency_issues: | |
| print(f" - {issue}") | |
| all_passed = False | |
| # Test 4: File metrics | |
| print("\n4οΈβ£ Checking file metrics...") | |
| try: | |
| file_size = os.path.getsize(app_path) | |
| with open(app_path, 'r') as f: | |
| line_count = sum(1 for _ in f) | |
| print(f" π File size: {file_size:,} bytes") | |
| print(f" π Line count: {line_count:,} lines") | |
| print(" β File metrics look good") | |
| except Exception as e: | |
| print(f" β Error checking file metrics: {e}") | |
| all_passed = False | |
| print("\n" + "=" * 60) | |
| if all_passed: | |
| print("π ALL VALIDATIONS PASSED!") | |
| print("\nπ Validation Summary:") | |
| print(" β Python syntax is valid") | |
| print(" β Bulletproof logging fixes applied") | |
| print(" β Consistent with STT service approach") | |
| print(" β Ready for ZeroGPU deployment") | |
| print("\nπ TTS service will start cleanly without logging conflicts!") | |
| return 0 | |
| else: | |
| print("β SOME VALIDATIONS FAILED!") | |
| print("β Review the issues above before deployment") | |
| return 1 | |
| if __name__ == "__main__": | |
| sys.exit(main()) |