File size: 863 Bytes
1d1c7b1 afac378 9845eee afac378 1d50a1e afac378 1d1c7b1 afac378 1d1c7b1 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
from transformers import pipeline
from typing import Any
class EndpointHandler():
def __init__(self, path=""):
# create inference pipeline
self.pipeline = pipeline("text-to-speech", model=path, device=0)
def __call__(self, data: Any) -> Any:
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
audio_array = prediction['audio']
sampling_rate = prediction['sampling_rate']
# If you need to return raw audio data
return {
"audio": audio_array,
"sampling_rate": sampling_rate
} |