Spaces:
Paused
Paused
File size: 4,747 Bytes
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 |
#!/usr/bin/env python3
"""
Test script to verify the pipeline fixes work correctly
"""
import sys
import os
import traceback
from typing import Dict, Any
# Add the project root to the path
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
def test_pipeline_fixes():
"""Test the pipeline with improved error handling"""
print("π§ͺ Testing Monster Generation Pipeline Fixes")
print("=" * 50)
try:
# Import the pipeline
from core.ai_pipeline import MonsterGenerationPipeline
print("β
Successfully imported MonsterGenerationPipeline")
# 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 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 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"Pipeline: {'β
PASSED' if pipeline_success else 'β FAILED'}")
if fallback_success and pipeline_success:
print("\nπ All tests passed! Pipeline fixes are working correctly.")
elif fallback_success:
print("\nβ οΈ Fallback manager works, but pipeline may need model dependencies.")
print("This is expected if models aren't installed.")
else:
print("\nβ Some tests failed. Check the error messages above.")
return fallback_success and pipeline_success
if __name__ == "__main__":
success = main()
sys.exit(0 if success else 1) |