|
from typing import Dict, List, Any |
|
from transformers import pipeline |
|
from PIL import Image |
|
import base64 |
|
from io import BytesIO |
|
class EndpointHandler(): |
|
def __init__(self, path="."): |
|
|
|
self.pipe = pipeline("image-segmentation", model=path, trust_remote_code=True) |
|
def __call__(self, data: Dict[str, Any]) -> List[Dict[str, Any]]: |
|
|
|
image_path = data.pop("inputs",data) |
|
|
|
|
|
pillow_mask = self.pipe(image_path, return_mask=True) |
|
pillow_image = self.pipe(image_path) |
|
|
|
|
|
return [{"image": pillow_image, "mask": pillow_mask}] |