File size: 648 Bytes
c1cb360 96a0103 fe371ad 001e799 b3aebd1 6d33a5e 1aeb34c 6d33a5e 1e592e3 6d33a5e 1e592e3 6d33a5e b47e2d8 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
from typing import Dict, List, Any
from transformers import pipeline
class EndpointHandler:
def __init__(self, path=""):
self.pipeline = pipeline("text-generation", model="Qwen/Qwen2-1.5B-Instruct")
def __call__(self, data: Any) -> List[List[Dict[str, float]]]:
inputs = data.pop("inputs", data)
parameters = data.pop("parameters", None)
# pass inputs with all kwargs in data
if parameters is not None:
prediction = self.pipeline(inputs, **parameters)
else:
prediction = self.pipeline(inputs)
# postprocess the prediction
return prediction
|