Experimental_v1 / handler.py
eventhorizon28's picture
Update handler.py
9845eee verified
raw
history blame contribute delete
863 Bytes
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
}