#!/usr/bin/env python3 """ Test script for GenVidBench app """ import os import sys def test_imports(): """Test if all required modules can be imported""" print("๐Ÿงช Testing imports...") try: import torch print("โœ… PyTorch imported successfully") except ImportError as e: print(f"โŒ PyTorch import failed: {e}") return False try: import gradio as gr print("โœ… Gradio imported successfully") except ImportError as e: print(f"โŒ Gradio import failed: {e}") return False try: from mmaction.apis import init_recognizer, inference_recognizer print("โœ… MMAction2 APIs imported successfully") except ImportError as e: print(f"โŒ MMAction2 import failed: {e}") return False return True def test_files(): """Test if required files exist""" print("๐Ÿงช Testing file structure...") required_files = [ 'app.py', 'requirements.txt', 'README.md', 'demo/demo_configs/tsn_r50_1x1x8_video_infer.py' ] for file_path in required_files: if os.path.exists(file_path): print(f"โœ… {file_path} exists") else: print(f"โŒ {file_path} missing") return False return True def test_model_checkpoint(): """Test if model checkpoint exists or can be downloaded""" print("๐Ÿงช Testing model checkpoint...") checkpoint_path = 'checkpoints/tsn_r50_8xb32-1x1x8-100e_kinetics400-rgb_20220818-2692d16c.pth' if os.path.exists(checkpoint_path): print(f"โœ… Model checkpoint found: {checkpoint_path}") return True else: print(f"โš ๏ธ Model checkpoint not found: {checkpoint_path}") print(" Run 'python download_model.py' to download it") return False def main(): """Run all tests""" print("๐Ÿš€ Testing GenVidBench setup...") print("=" * 50) tests = [ ("Import Test", test_imports), ("File Structure Test", test_files), ("Model Checkpoint Test", test_model_checkpoint) ] results = [] for test_name, test_func in tests: print(f"\n๐Ÿ“‹ {test_name}") print("-" * 30) result = test_func() results.append((test_name, result)) print("\n" + "=" * 50) print("๐Ÿ“Š Test Results Summary:") print("=" * 50) all_passed = True for test_name, result in results: status = "โœ… PASS" if result else "โŒ FAIL" print(f"{status} {test_name}") if not result: all_passed = False if all_passed: print("\n๐ŸŽ‰ All tests passed! Your app is ready for deployment.") else: print("\nโš ๏ธ Some tests failed. Please fix the issues before deploying.") return all_passed if __name__ == "__main__": success = main() sys.exit(0 if success else 1)