Download test_environment.py from 000x/sinhala-subtitle-hardcoder: direct link, hf CLI and curl.
- Browser
- Download file 5.78 kB
-
https://huggingface.co/spaces/000x/sinhala-subtitle-hardcoder/resolve/main/test_environment.py
- Command line
-
hf download hf://spaces/000x/sinhala-subtitle-hardcoder/test_environment.py
-
curl -L -o test_environment.py https://huggingface.co/spaces/000x/sinhala-subtitle-hardcoder/resolve/main/test_environment.py
5.78 kB
| #!/usr/bin/env python3 | |
| """ | |
| Test script for Sinhala Subtitle Hardcoder | |
| Run this to test functionality before deploying to Hugging Face | |
| """ | |
| import os | |
| import sys | |
| def test_imports(): | |
| """Test if all required packages are installed""" | |
| print("Testing imports...") | |
| try: | |
| import gradio as gr | |
| print("✅ Gradio imported successfully") | |
| except ImportError: | |
| print("❌ Gradio not found. Run: pip install gradio") | |
| return False | |
| try: | |
| import requests | |
| print("✅ Requests imported successfully") | |
| except ImportError: | |
| print("❌ Requests not found. Run: pip install requests") | |
| return False | |
| return True | |
| def test_ffmpeg(): | |
| """Test if FFmpeg is installed""" | |
| print("\nTesting FFmpeg...") | |
| import subprocess | |
| try: | |
| result = subprocess.run(['ffmpeg', '-version'], | |
| capture_output=True, | |
| text=True, | |
| timeout=5) | |
| if result.returncode == 0: | |
| version = result.stdout.split('\n')[0] | |
| print(f"✅ FFmpeg found: {version}") | |
| return True | |
| else: | |
| print("❌ FFmpeg found but returned error") | |
| return False | |
| except FileNotFoundError: | |
| print("❌ FFmpeg not found. Install it:") | |
| print(" Ubuntu/Debian: sudo apt-get install ffmpeg") | |
| print(" macOS: brew install ffmpeg") | |
| print(" Windows: Download from https://ffmpeg.org/") | |
| return False | |
| except Exception as e: | |
| print(f"❌ Error testing FFmpeg: {e}") | |
| return False | |
| def test_fonts(): | |
| """Test if Sinhala fonts are available""" | |
| print("\nTesting Sinhala fonts...") | |
| import subprocess | |
| try: | |
| # Check for common Sinhala fonts | |
| result = subprocess.run(['fc-list', ':lang=si'], | |
| capture_output=True, | |
| text=True, | |
| timeout=5) | |
| if 'Noto' in result.stdout or 'Sinhala' in result.stdout: | |
| print("✅ Sinhala fonts found") | |
| fonts = [line for line in result.stdout.split('\n') if 'Sinhala' in line or 'Noto' in line] | |
| for font in fonts[:3]: | |
| print(f" - {font[:80]}...") | |
| return True | |
| else: | |
| print("⚠️ No Sinhala fonts found. Install Noto fonts:") | |
| print(" Ubuntu/Debian: sudo apt-get install fonts-noto-core fonts-noto-extra") | |
| print(" macOS: brew install font-noto-sans") | |
| return False | |
| except FileNotFoundError: | |
| print("⚠️ fontconfig not found, cannot check fonts") | |
| return False | |
| except Exception as e: | |
| print(f"⚠️ Error checking fonts: {e}") | |
| return False | |
| def test_subtitle_encoding(): | |
| """Test subtitle encoding handling""" | |
| print("\nTesting subtitle encoding...") | |
| test_content = """1 | |
| 00:00:01,000 --> 00:00:04,000 | |
| හෙලෝ, මෙය සිංහල උපසිරැසි පරීක්ෂණයකි | |
| 2 | |
| 00:00:05,000 --> 00:00:08,000 | |
| Unicode test: \u0D9A\u0DCA\u200D\u0DBB\u0DD2\u0DBA\u0DCF | |
| """ | |
| import tempfile | |
| try: | |
| # Create test file | |
| with tempfile.NamedTemporaryFile(mode='w', encoding='utf-8', | |
| suffix='.srt', delete=False) as f: | |
| f.write(test_content) | |
| test_file = f.name | |
| # Try to read it back | |
| with open(test_file, 'r', encoding='utf-8') as f: | |
| content = f.read() | |
| # Check for Sinhala characters | |
| if '\u0D80' <= content[50] <= '\u0DFF': # Check if Sinhala unicode present | |
| print("✅ Subtitle encoding test passed") | |
| os.unlink(test_file) | |
| return True | |
| else: | |
| print("❌ Subtitle encoding test failed") | |
| os.unlink(test_file) | |
| return False | |
| except Exception as e: | |
| print(f"❌ Subtitle encoding test failed: {e}") | |
| return False | |
| def test_app_import(): | |
| """Test if app.py can be imported""" | |
| print("\nTesting app.py import...") | |
| try: | |
| sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) | |
| import app | |
| print("✅ app.py imported successfully") | |
| return True | |
| except Exception as e: | |
| print(f"❌ Failed to import app.py: {e}") | |
| return False | |
| def main(): | |
| """Run all tests""" | |
| print("=" * 60) | |
| print("Sinhala Subtitle Hardcoder - Environment Test") | |
| print("=" * 60) | |
| tests = [ | |
| ("Imports", test_imports), | |
| ("FFmpeg", test_ffmpeg), | |
| ("Sinhala Fonts", test_fonts), | |
| ("Subtitle Encoding", test_subtitle_encoding), | |
| ("App Import", test_app_import), | |
| ] | |
| results = {} | |
| for name, test_func in tests: | |
| results[name] = test_func() | |
| print("\n" + "=" * 60) | |
| print("Test Results Summary") | |
| print("=" * 60) | |
| for name, passed in results.items(): | |
| status = "✅ PASS" if passed else "❌ FAIL" | |
| print(f"{name:20s}: {status}") | |
| print("=" * 60) | |
| if all(results.values()): | |
| print("\n🎉 All tests passed! Ready to deploy to Hugging Face.") | |
| print("\nNext steps:") | |
| print("1. Create a new Space on Hugging Face") | |
| print("2. Upload app.py, requirements.txt, packages.txt, README.md") | |
| print("3. Wait for build to complete") | |
| print("4. Test with real videos!") | |
| return 0 | |
| else: | |
| print("\n⚠️ Some tests failed. Fix the issues above before deploying.") | |
| failed = [name for name, passed in results.items() if not passed] | |
| print(f"\nFailed tests: {', '.join(failed)}") | |
| return 1 | |
| if __name__ == "__main__": | |
| sys.exit(main()) | |