Spaces:
Runtime error
Runtime error
| """ | |
| Test mesh generation locally before deployment. | |
| Verifies the complete pipeline works end-to-end. | |
| """ | |
| import sys | |
| from pathlib import Path | |
| # Add parent directory to path | |
| sys.path.insert(0, str(Path(__file__).parent)) | |
| from core import AssetPipeline, QUALITY_PRESETS | |
| from utils import MemoryManager | |
| def test_mesh_generation(): | |
| """Test complete mesh generation pipeline.""" | |
| print("=" * 80) | |
| print("๐งช MESH GENERATION TEST") | |
| print("=" * 80) | |
| print() | |
| # Initialize | |
| print("๐ฆ Initializing pipeline...") | |
| memory_manager = MemoryManager() | |
| memory_manager.setup_cuda_optimizations() | |
| pipeline = AssetPipeline() | |
| print(" โ Pipeline initialized") | |
| print() | |
| # Test configuration | |
| test_cases = [ | |
| { | |
| "name": "Fast Generation", | |
| "prompt": "medieval knight with detailed armor", | |
| "quality": "Fast", | |
| "expected_time": 45 | |
| }, | |
| { | |
| "name": "Balanced Generation", | |
| "prompt": "futuristic mech robot, game asset", | |
| "quality": "Balanced", | |
| "expected_time": 60 | |
| } | |
| ] | |
| results = [] | |
| for i, test in enumerate(test_cases, 1): | |
| print(f"๐ฏ Test {i}/{len(test_cases)}: {test['name']}") | |
| print(f" Prompt: {test['prompt']}") | |
| print(f" Quality: {test['quality']}") | |
| print(f" Expected time: ~{test['expected_time']}s") | |
| print() | |
| try: | |
| # Generate asset | |
| print(" ๐ Generating...") | |
| result = pipeline.generate( | |
| prompt=test['prompt'], | |
| quality=test['quality'] | |
| ) | |
| # Verify result | |
| if result.glb_path and result.glb_path.exists(): | |
| file_size_mb = result.glb_path.stat().st_size / 1e6 | |
| print(f" โ SUCCESS!") | |
| print(f" ๐ Generation time: {result.metadata.generation_time_s:.1f}s") | |
| print(f" ๐ฆ File size: {file_size_mb:.2f} MB") | |
| print(f" ๐จ FLUX steps: {result.metadata.flux_steps}") | |
| print(f" ๐จ Hunyuan steps: {result.metadata.hunyuan_steps}") | |
| print(f" ๐ง Optimized: {result.metadata.optimized}") | |
| print(f" ๐พ Cached: {result.cached}") | |
| print(f" ๐ Output: {result.glb_path}") | |
| results.append({ | |
| "test": test['name'], | |
| "success": True, | |
| "time": result.metadata.generation_time_s, | |
| "size_mb": file_size_mb, | |
| "cached": result.cached | |
| }) | |
| else: | |
| print(f" โ FAILED: No output file") | |
| results.append({ | |
| "test": test['name'], | |
| "success": False, | |
| "error": "No output file" | |
| }) | |
| except Exception as e: | |
| print(f" โ FAILED: {e}") | |
| results.append({ | |
| "test": test['name'], | |
| "success": False, | |
| "error": str(e) | |
| }) | |
| print() | |
| # Summary | |
| print("=" * 80) | |
| print("๐ TEST SUMMARY") | |
| print("=" * 80) | |
| print() | |
| success_count = sum(1 for r in results if r.get('success', False)) | |
| total_count = len(results) | |
| print(f"โ Passed: {success_count}/{total_count}") | |
| print(f"โ Failed: {total_count - success_count}/{total_count}") | |
| print() | |
| if success_count == total_count: | |
| print("๐ ALL TESTS PASSED!") | |
| print() | |
| print("โจ Pipeline is ready for deployment!") | |
| print() | |
| print("Next steps:") | |
| print("1. Run: .\\FINAL_DEPLOYMENT.ps1") | |
| print("2. Wait 5-10 minutes for Space to build") | |
| print("3. Test on HF Space with same prompts") | |
| print() | |
| return True | |
| else: | |
| print("โ ๏ธ SOME TESTS FAILED") | |
| print() | |
| print("Failed tests:") | |
| for r in results: | |
| if not r.get('success', False): | |
| print(f" โข {r['test']}: {r.get('error', 'Unknown error')}") | |
| print() | |
| print("Fix errors before deployment!") | |
| print() | |
| return False | |
| if __name__ == "__main__": | |
| try: | |
| success = test_mesh_generation() | |
| sys.exit(0 if success else 1) | |
| except KeyboardInterrupt: | |
| print("\n\nโ ๏ธ Test interrupted by user") | |
| sys.exit(1) | |
| except Exception as e: | |
| print(f"\n\nโ Test failed with error: {e}") | |
| import traceback | |
| traceback.print_exc() | |
| sys.exit(1) | |