chris-propeller's picture
repro
31fd8be
Raw
History Blame Contribute Delete
3.46 kB
from typing import Dict, Any, List
import torch
import numpy as np
from PIL import Image
import base64
import io
import cv2
# Test importing the problematic packages
from transformers import Sam3Model, Sam3Processor
class EndpointHandler:
"""
Minimal test handler to isolate dependency loading issues
This handler imports all the same dependencies but doesn't execute SAM3 inference
"""
def __init__(self, path: str = ""):
"""
Initialize the handler - test dependency loading without heavy model loading
Args:
path: Path to model weights (unused in this test)
"""
self.device = "cuda" if torch.cuda.is_available() else "cpu"
print(f"βœ… Test handler initialized successfully on device: {self.device}")
# Test that we can import the SAM3 classes without loading the model
print(f"βœ… Successfully imported Sam3Model: {Sam3Model}")
print(f"βœ… Successfully imported Sam3Processor: {Sam3Processor}")
# Test other dependencies
print(f"βœ… PyTorch version: {torch.__version__}")
print(f"βœ… NumPy version: {np.__version__}")
print(f"βœ… PIL (Pillow) available: {Image}")
print(f"βœ… OpenCV available: {cv2.__version__}")
# Don't actually load the model to avoid memory/download issues
self.model = None
self.processor = None
print("βœ… Minimal test handler ready - all dependencies loaded successfully!")
def __call__(self, data: Dict[str, Any]) -> Dict[str, Any]:
"""
Minimal test endpoint that returns success without actual inference
Args:
data: Input data (will be ignored in this test)
Returns:
Simple success response to verify the handler works
"""
try:
print("πŸ“ Test handler called with data keys:", list(data.keys()) if data else "No data")
# Test basic operations with imported libraries
test_array = np.array([1, 2, 3])
test_tensor = torch.tensor([1.0, 2.0, 3.0])
print(f"βœ… NumPy test array: {test_array}")
print(f"βœ… PyTorch test tensor: {test_tensor}")
print(f"βœ… Device available: {self.device}")
# Return a successful test response
return {
"status": "success",
"message": "βœ… All dependencies loaded and working correctly!",
"test_results": {
"numpy_test": test_array.tolist(),
"torch_test": test_tensor.tolist(),
"device": self.device,
"torch_version": torch.__version__,
"numpy_version": np.__version__,
"opencv_version": cv2.__version__,
"transformers_classes_available": {
"Sam3Model": str(Sam3Model),
"Sam3Processor": str(Sam3Processor)
}
},
"input_data_received": data is not None,
"handler_type": "minimal_test_handler"
}
except Exception as e:
print(f"❌ Error in test handler: {str(e)}")
return {
"status": "error",
"message": f"Test handler failed: {str(e)}",
"error_type": type(e).__name__,
"handler_type": "minimal_test_handler"
}