from typing import Dict, Any from transformers import pipeline class EndpointHandler: def __init__(self, path=""): self.pipeline = pipeline("token-classification", model=path) def __call__(self, data: Dict[str, Any]) -> Dict[str, Any]: """ data args: inputs (:obj: `str`) Return: A :obj:`list` | `dict`: will be serialized and returned """ # get inputs inputs = data.pop("inputs",data) # run normal prediction prediction = self.pipeline(inputs) return { "inputs": inputs, "outputs": prediction }