| from typing import Dict, Any, List |
| import torch |
| import numpy as np |
| from PIL import Image |
| import base64 |
| import io |
| import cv2 |
|
|
| |
| 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}") |
|
|
| |
| print(f"β
Successfully imported Sam3Model: {Sam3Model}") |
| print(f"β
Successfully imported Sam3Processor: {Sam3Processor}") |
|
|
| |
| print(f"β
PyTorch version: {torch.__version__}") |
| print(f"β
NumPy version: {np.__version__}") |
| print(f"β
PIL (Pillow) available: {Image}") |
| print(f"β
OpenCV available: {cv2.__version__}") |
|
|
| |
| 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_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 { |
| "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" |
| } |