Download handler.py from eventhorizon28/Experimental_v1: direct link, hf CLI and curl.
- Browser
- Download file 863 Bytes
-
https://huggingface.co/eventhorizon28/Experimental_v1/resolve/main/handler.py
- Command line
-
hf download hf://eventhorizon28/Experimental_v1/handler.py
-
curl -L -o handler.py https://huggingface.co/eventhorizon28/Experimental_v1/resolve/main/handler.py
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 | |
| } |