sda
Browse files- handler.py +22 -14
handler.py
CHANGED
|
@@ -1,11 +1,13 @@
|
|
| 1 |
from typing import Dict, List, Any
|
| 2 |
-
from transformers import (AutoProcessor, pipeline)
|
| 3 |
|
| 4 |
|
| 5 |
class EndpointHandler():
|
| 6 |
def __init__(self, path="suno/bark-small"):
|
| 7 |
-
self.pipe = pipeline(
|
| 8 |
-
|
|
|
|
|
|
|
| 9 |
|
| 10 |
def __call__(self, data: Dict[str, Any]) -> List[Dict[str, Any]]:
|
| 11 |
processor = AutoProcessor.from_pretrained("suno/bark-small")
|
|
@@ -13,17 +15,23 @@ class EndpointHandler():
|
|
| 13 |
inputs = data.pop("inputs", data)
|
| 14 |
|
| 15 |
# get voice preset from processor
|
| 16 |
-
blank_inp = processor("blank", voice_preset="v2/en_speaker_1")
|
| 17 |
# get voice_preset
|
| 18 |
-
history_prompt = blank_inp["history_prompt"]
|
| 19 |
-
forward_params = {
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
|
| 25 |
-
}
|
| 26 |
-
output = self.pipe(inputs,
|
| 27 |
-
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
from typing import Dict, List, Any
|
| 2 |
+
from transformers import (AutoProcessor, pipeline, AutoModelForTextToWaveform)
|
| 3 |
|
| 4 |
|
| 5 |
class EndpointHandler():
|
| 6 |
def __init__(self, path="suno/bark-small"):
|
| 7 |
+
# self.pipe = pipeline(
|
| 8 |
+
# "text-to-speech", model=path, framework="pt", device=0)
|
| 9 |
+
self.processor = AutoProcessor.from_pretrained("suno/bark-small")
|
| 10 |
+
self.model = AutoModel.from_pretrained("suno/bark-small")
|
| 11 |
|
| 12 |
def __call__(self, data: Dict[str, Any]) -> List[Dict[str, Any]]:
|
| 13 |
processor = AutoProcessor.from_pretrained("suno/bark-small")
|
|
|
|
| 15 |
inputs = data.pop("inputs", data)
|
| 16 |
|
| 17 |
# get voice preset from processor
|
| 18 |
+
# blank_inp = processor("blank", voice_preset="v2/en_speaker_1")
|
| 19 |
# get voice_preset
|
| 20 |
+
# history_prompt = blank_inp["history_prompt"]
|
| 21 |
+
# forward_params = {
|
| 22 |
+
# "history_prompt": history_prompt,
|
| 23 |
+
# # you can add other generate parameters
|
| 24 |
+
# "num_beams": 6,
|
| 25 |
+
# "do_sample": True,
|
| 26 |
|
| 27 |
+
# }
|
| 28 |
+
# output = self.pipe(inputs,
|
| 29 |
+
# forward_params=forward_params)
|
| 30 |
+
inputs = processor(
|
| 31 |
+
text=[inputs], return_tensors="pt",
|
| 32 |
+
)
|
| 33 |
|
| 34 |
+
speech_values = model.generate(**inputs, do_sample=True)
|
| 35 |
+
sampling_rate = model.generation_config.sample_rate
|
| 36 |
+
#return {"output": output["audio"], "sample_rate": output["sampling_rate"]}
|
| 37 |
+
return {"output": speech_values.cpu().numpy().squeeze(), "sampling_rate": sampling_rate}
|