Files
timmy-config/scripts/multimodal/test_pipeline.py

111 lines
3.4 KiB
Python
Raw Normal View History

#!/usr/bin/env python3
"""
Test script for the Multimodal Meaning Kernel Extraction Pipeline.
Creates a simple test image and runs the pipeline.
"""
import os
import sys
from pathlib import Path
# Add the parent directory to path
sys.path.insert(0, str(Path(__file__).parent.parent))
def create_test_image():
"""Create a simple test image with text."""
try:
from PIL import Image, ImageDraw, ImageFont
# Create a simple image with text
img = Image.new('RGB', (800, 400), color='white')
draw = ImageDraw.Draw(img)
# Try to use a default font
try:
font = ImageFont.truetype("Arial", 24)
except:
font = ImageFont.load_default()
# Draw some text
text = "Research Diagram Test\\n\\nThis is a test diagram for\\nmeaning kernel extraction.\\n\\nKey concepts:\\n- Multimodal processing\\n- OCR extraction\\n- Kernel generation"
draw.text((50, 50), text, fill='black', font=font)
# Draw a simple rectangle
draw.rectangle([300, 200, 500, 300], outline='blue', width=2)
draw.text((320, 220), "Process", fill='blue', font=font)
# Save the image
test_dir = Path(__file__).parent / "test_output"
test_dir.mkdir(exist_ok=True)
image_path = test_dir / "test_diagram.png"
img.save(image_path)
print(f"Created test image: {image_path}")
return image_path
except ImportError as e:
print(f"Cannot create test image: {e}")
print("Please install Pillow: pip install Pillow")
return None
def test_pipeline():
"""Test the extraction pipeline."""
# First check if we can import the pipeline
try:
from extract_meaning_kernels import DiagramProcessor, MeaningKernel
print("✓ Pipeline module imported successfully")
except ImportError as e:
print(f"✗ Failed to import pipeline: {e}")
return False
# Create test image
test_image = create_test_image()
if not test_image:
print("Skipping pipeline test - no test image")
return True # Not a failure, just missing dependency
# Create processor
processor = DiagramProcessor()
# Process the test image
print("\\nProcessing test image...")
try:
kernels = processor.extract_from_image(test_image)
print(f"✓ Extracted {len(kernels)} kernels")
# Print kernel details
for kernel in kernels:
print(f"\\nKernel: {kernel.kernel_id}")
print(f" Type: {kernel.metadata.get('type', 'unknown')}")
print(f" Confidence: {kernel.confidence:.2f}")
print(f" Content: {kernel.content[:100]}...")
# Get stats
stats = processor.get_stats()
print(f"\\nStatistics:")
for key, value in stats.items():
print(f" {key}: {value}")
return True
except Exception as e:
print(f"✗ Pipeline test failed: {e}")
import traceback
traceback.print_exc()
return False
if __name__ == "__main__":
print("Testing Multimodal Meaning Kernel Extraction Pipeline")
print("=" * 60)
success = test_pipeline()
print("\\n" + "=" * 60)
if success:
print("✓ All tests passed!")
sys.exit(0)
else:
print("✗ Some tests failed")
sys.exit(1)