Spaces:
Running
on
Zero
Running
on
Zero
File size: 7,973 Bytes
e8293cd e4aa154 e8293cd e4aa154 e8293cd e4aa154 e8293cd e4aa154 e8293cd e4aa154 e8293cd e4aa154 e8293cd e4aa154 e8293cd e4aa154 e8293cd |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 |
#!/usr/bin/env python3
"""
Test script to verify the pipeline fixes work correctly
"""
import sys
import os
import traceback
from typing import Dict, Any
from PIL import Image
import numpy as np
# Add the project root to the path
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
# Import the pipeline at module level
try:
from core.ai_pipeline import MonsterGenerationPipeline
PIPELINE_AVAILABLE = True
except ImportError as e:
print(f"β οΈ Warning: Could not import MonsterGenerationPipeline: {e}")
PIPELINE_AVAILABLE = False
def test_pipeline_fixes():
"""Test the pipeline with improved error handling"""
print("π§ͺ Testing Monster Generation Pipeline Fixes")
print("=" * 50)
try:
# Initialize pipeline
print("π§ Initializing pipeline...")
pipeline = MonsterGenerationPipeline(device="cpu") # Use CPU for testing
print("β
Pipeline initialized successfully")
# Test with a simple text input
print("\nπ Testing monster generation...")
test_input = "Create a friendly fire monster with wings"
result = pipeline.generate_monster(
text_input=test_input,
user_id="test_user"
)
print(f"\nπ Generation Result:")
print(f"Status: {result.get('status', 'unknown')}")
print(f"Success: {result.get('generation_log', {}).get('success', False)}")
print(f"Stages completed: {result.get('generation_log', {}).get('stages_completed', [])}")
print(f"Fallbacks used: {result.get('generation_log', {}).get('fallbacks_used', [])}")
print(f"Errors: {result.get('generation_log', {}).get('errors', [])}")
if result.get('traits'):
print(f"Monster name: {result.get('traits', {}).get('name', 'Unknown')}")
print(f"Monster element: {result.get('traits', {}).get('element', 'Unknown')}")
if result.get('dialogue'):
print(f"Monster dialogue: {result.get('dialogue', '')}")
print(f"Download files: {result.get('download_files', [])}")
# Clean up
pipeline.cleanup()
print("\nπ§Ή Pipeline cleaned up successfully")
return True
except Exception as e:
print(f"β Test failed with error: {e}")
print(f"Error type: {type(e).__name__}")
print("Full traceback:")
traceback.print_exc()
return False
def test_fallback_manager():
"""Test the fallback manager"""
print("\nπ§ͺ Testing Fallback Manager")
print("=" * 30)
try:
from utils.fallbacks import FallbackManager
fallback = FallbackManager()
# Test text generation fallback
print("π Testing text generation fallback...")
traits, dialogue = fallback.handle_text_gen_failure("Create a water monster")
print(f"β
Generated traits: {traits.get('name', 'Unknown')}")
print(f"β
Generated dialogue: {dialogue}")
# Test image generation fallback
print("π¨ Testing image generation fallback...")
image = fallback.handle_image_gen_failure("Create a fire monster")
print(f"β
Generated image: {type(image)}")
# Test 3D generation fallback
print("π² Testing 3D generation fallback...")
model_3d = fallback.handle_3d_gen_failure(image)
print(f"β
Generated 3D model: {type(model_3d)}")
print("β
All fallback tests passed!")
return True
except Exception as e:
print(f"β Fallback test failed: {e}")
traceback.print_exc()
return False
def test_pipeline_timeout():
"""Test that the pipeline handles 3D generation timeout gracefully"""
if not PIPELINE_AVAILABLE:
print("β οΈ Skipping pipeline timeout test - pipeline not available")
return False
print("π§ͺ Testing pipeline timeout handling...")
# Create a simple test image
test_image = Image.new('RGB', (512, 512), color='red')
# Initialize pipeline
pipeline = MonsterGenerationPipeline(device="cpu") # Use CPU for testing
# Test with a simple text input
result = pipeline.generate_monster(
text_input="Create a simple red monster",
user_id="test_user"
)
print(f"π Pipeline result status: {result.get('status', 'unknown')}")
print(f"π Stages completed: {result.get('generation_log', {}).get('stages_completed', [])}")
print(f"π Fallbacks used: {result.get('generation_log', {}).get('fallbacks_used', [])}")
print(f"π Errors: {result.get('generation_log', {}).get('errors', [])}")
# Check if we got a result
if result.get('status') in ['success', 'fallback']:
print("β
Pipeline completed successfully!")
if result.get('model_3d'):
print(f"β
3D model generated: {result['model_3d']}")
if result.get('image'):
print(f"β
Image generated: {type(result['image'])}")
if result.get('traits'):
print(f"β
Monster traits: {result['traits'].get('name', 'Unknown')}")
else:
print("β Pipeline failed")
return False
return True
def test_3d_generator_timeout():
"""Test the 3D generator timeout mechanism directly"""
print("\nπ§ͺ Testing 3D generator timeout mechanism...")
try:
from models.model_3d_generator import Hunyuan3DGenerator
# Create a test image
test_image = Image.new('RGB', (512, 512), color='blue')
# Initialize 3D generator with short timeout for testing
generator = Hunyuan3DGenerator(device="cpu")
generator.api_timeout = 10 # 10 seconds timeout for testing
print("β±οΈ Testing with 10-second timeout...")
# This should either complete quickly or timeout
result = generator.image_to_3d(test_image)
print(f"β
3D generation completed: {type(result)}")
return True
except Exception as e:
print(f"β 3D generation failed: {e}")
if "timeout" in str(e).lower():
print("β
Timeout mechanism working correctly")
return True
else:
print("β Unexpected error")
return False
def main():
"""Main test function"""
print("π Starting Pipeline Fix Verification")
print("=" * 50)
# Test fallback manager first (doesn't require heavy models)
fallback_success = test_fallback_manager()
# Test 3D generator timeout mechanism
timeout_success = test_3d_generator_timeout()
# Test pipeline timeout handling
pipeline_timeout_success = test_pipeline_timeout()
# Test full pipeline (may fail due to missing models, but should show better error handling)
pipeline_success = test_pipeline_fixes()
print("\n" + "=" * 50)
print("π Test Results Summary:")
print(f"Fallback Manager: {'β
PASSED' if fallback_success else 'β FAILED'}")
print(f"3D Generator Timeout: {'β
PASSED' if timeout_success else 'β FAILED'}")
print(f"Pipeline Timeout: {'β
PASSED' if pipeline_timeout_success else 'β FAILED'}")
print(f"Full Pipeline: {'β
PASSED' if pipeline_success else 'β FAILED'}")
if fallback_success and timeout_success:
print("\nπ Core timeout and fallback mechanisms are working!")
if pipeline_success:
print("π Full pipeline is working correctly!")
else:
print("β οΈ Pipeline may need model dependencies, but timeout handling is functional.")
else:
print("\nβ Some core tests failed. Check the error messages above.")
return fallback_success and timeout_success
if __name__ == "__main__":
success = main()
sys.exit(0 if success else 1) |