|
from typing import Dict, List, Any |
|
from optimum.pipeline import pipeline |
|
from transformers import AutoTokenizer |
|
from optimum import ORTModelForSeq2SeqLM |
|
|
|
|
|
class EndpointHandler(): |
|
def __init__(self, path=""): |
|
tokenizer = AutoTokenizer.from_pretrained(path) |
|
model = ORTModelForSeq2SeqLM.from_pretrained(path) |
|
self.pipeline = pipeline("summarization",model=model, tokenizer=tokenizer) |
|
|
|
def __call__(self, data: Dict[str, Any]) -> List[Dict[str, Any]]: |
|
""" |
|
data args: |
|
inputs (:obj: `str`) |
|
Return: |
|
A :obj:`list` | `dict`: will be serialized and returned |
|
""" |
|
|
|
inputs = data.pop("inputs",data) |
|
|
|
|
|
return self.pipeline(inputs) |
|
|