from transformers import AutoProcessor, AutoModel class EndpointHandler(): def __init__(self, path=""): self.processor = AutoProcessor.from_pretrained(path) self.model = AutoModel.from_pretrained(path) def __call__(self, data): #-> List[Dict[str, Any]] """ data args: inputs (:obj: `list`) Return: A :obj:`np.array' | `int`: will be serialized and returned """ # get inputs input_text = data['inputs'] inputs = self.processor( text=input_text, return_tensors="pt", voice_preset = "v2/en_speaker_6" ) speech_values = self.model.generate(**inputs, do_sample=True) sampling_rate = self.model.generation_config.sample_rate return (speech_values, sampling_rate)