""" Simple test script to verify Transformers pipeline integration """ from transformers import pipeline import torch from PIL import Image import numpy as np def test_transformers_pipeline(): """Test if transformers depth estimation pipeline works""" print("๐Ÿงช Testing Transformers Depth Estimation Pipeline") print("=" * 50) try: # Initialize pipeline print("1. Initializing pipeline...") pipe = pipeline( "depth-estimation", model="apple/DepthPro", device=-1, # CPU torch_dtype=torch.float32 ) print("โœ… Pipeline initialized successfully!") # Create test image print("2. Creating test image...") test_image = Image.new('RGB', (640, 480), color='blue') # Add some pattern pixels = np.array(test_image) for y in range(480): for x in range(640): intensity = int(255 * (1 - y / 480)) pixels[y, x] = [intensity, intensity//2, intensity//3] test_image = Image.fromarray(pixels.astype(np.uint8)) print("โœ… Test image created!") # Test pipeline print("3. Running depth estimation...") result = pipe(test_image) print("โœ… Pipeline executed successfully!") # Check result print("4. Checking results...") if isinstance(result, dict): if 'depth' in result: depth = result['depth'] print(f" Depth type: {type(depth)}") if hasattr(depth, 'shape'): print(f" Depth shape: {depth.shape}") elif hasattr(depth, 'size'): print(f" Depth size: {depth.size}") print("โœ… Valid depth result obtained!") return True else: print(f" Result keys: {result.keys()}") print("โš ๏ธ No 'depth' key in result") return False else: print(f" Result type: {type(result)}") if hasattr(result, 'depth'): print("โœ… Result has depth attribute!") return True else: print("โš ๏ธ Result format unexpected") return False except ImportError as e: print(f"โŒ Import error: {e}") print("๐Ÿ’ก Try: pip install transformers torch") return False except Exception as e: print(f"โŒ Pipeline test failed: {e}") print("๐Ÿ’ก This is expected if the model isn't available or if there are compatibility issues") return False def test_fallback_dummy(): """Test the dummy pipeline fallback""" print("\n๐Ÿงช Testing Dummy Pipeline Fallback") print("=" * 40) try: # Import dummy pipeline from our app import sys import os sys.path.append(os.path.dirname(os.path.abspath(__file__))) from app import DummyDepthPipeline dummy = DummyDepthPipeline() test_image = Image.new('RGB', (512, 384), color='green') result = dummy(test_image) if isinstance(result, dict) and 'depth' in result: depth = result['depth'] print(f"โœ… Dummy pipeline works! Depth shape: {depth.shape}") print(f" Depth range: {np.min(depth):.2f} - {np.max(depth):.2f}") return True else: print(f"โŒ Unexpected result format: {type(result)}") return False except Exception as e: print(f"โŒ Dummy pipeline test failed: {e}") return False if __name__ == "__main__": print("๐Ÿš€ Testing Depth Pro Transformers Integration\n") # Test real pipeline pipeline_works = test_transformers_pipeline() # Test fallback dummy_works = test_fallback_dummy() print("\n" + "="*50) print("๐Ÿ Test Summary:") print("="*50) print(f"Transformers Pipeline: {'โœ… WORKS' if pipeline_works else 'โŒ FAILED (expected in some environments)'}") print(f"Dummy Pipeline Fallback: {'โœ… WORKS' if dummy_works else 'โŒ FAILED'}") if dummy_works: print("\n๐ŸŽ‰ The app should work with fallback even if the real model fails!") else: print("\nโš ๏ธ There may be issues with the fallback implementation.") if pipeline_works: print("๐ŸŒŸ Real Depth Pro model should work perfectly!") else: print("๐Ÿ’ก Real model may need specific environment setup or GPU.")