chris-propeller/transformers-inference-endpoint-fail
0
1from typing import Dict, Any, List2import torch3import numpy as np4from PIL import Image5import base646import io7import cv28 9# Test importing the problematic packages10from transformers import Sam3Model, Sam3Processor11 12 13class EndpointHandler:14 """15 Minimal test handler to isolate dependency loading issues16 This handler imports all the same dependencies but doesn't execute SAM3 inference17 """18 19 def __init__(self, path: str = ""):20 """21 Initialize the handler - test dependency loading without heavy model loading22 23 Args:24 path: Path to model weights (unused in this test)25 """26 self.device = "cuda" if torch.cuda.is_available() else "cpu"27 print(f"✅ Test handler initialized successfully on device: {self.device}")28 29 # Test that we can import the SAM3 classes without loading the model30 print(f"✅ Successfully imported Sam3Model: {Sam3Model}")31 print(f"✅ Successfully imported Sam3Processor: {Sam3Processor}")32 33 # Test other dependencies34 print(f"✅ PyTorch version: {torch.__version__}")35 print(f"✅ NumPy version: {np.__version__}")36 print(f"✅ PIL (Pillow) available: {Image}")37 print(f"✅ OpenCV available: {cv2.__version__}")38 39 # Don't actually load the model to avoid memory/download issues40 self.model = None41 self.processor = None42 43 print("✅ Minimal test handler ready - all dependencies loaded successfully!")44 45 def __call__(self, data: Dict[str, Any]) -> Dict[str, Any]:46 """47 Minimal test endpoint that returns success without actual inference48 49 Args:50 data: Input data (will be ignored in this test)51 52 Returns:53 Simple success response to verify the handler works54 """55 try:56 print("📝 Test handler called with data keys:", list(data.keys()) if data else "No data")57 58 # Test basic operations with imported libraries59 test_array = np.array([1, 2, 3])60 test_tensor = torch.tensor([1.0, 2.0, 3.0])61 62 print(f"✅ NumPy test array: {test_array}")63 print(f"✅ PyTorch test tensor: {test_tensor}")64 print(f"✅ Device available: {self.device}")65 66 # Return a successful test response67 return {68 "status": "success",69 "message": "✅ All dependencies loaded and working correctly!",70 "test_results": {71 "numpy_test": test_array.tolist(),72 "torch_test": test_tensor.tolist(),73 "device": self.device,74 "torch_version": torch.__version__,75 "numpy_version": np.__version__,76 "opencv_version": cv2.__version__,77 "transformers_classes_available": {78 "Sam3Model": str(Sam3Model),79 "Sam3Processor": str(Sam3Processor)80 }81 },82 "input_data_received": data is not None,83 "handler_type": "minimal_test_handler"84 }85 86 except Exception as e:87 print(f"❌ Error in test handler: {str(e)}")88 return {89 "status": "error",90 "message": f"Test handler failed: {str(e)}",91 "error_type": type(e).__name__,92 "handler_type": "minimal_test_handler"93 }