tts-gpu-service / validate_syntax.py
Peter Michael Gits
fix: Apply bulletproof logging and Gradio fixes
84a363d
#!/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())