Commit
·
2074891
1
Parent(s):
96937e3
Upload handler.py
Browse files- handler.py +10 -1
handler.py
CHANGED
|
@@ -1,9 +1,17 @@
|
|
| 1 |
from transformers import AutoProcessor, AutoModel
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
class EndpointHandler():
|
| 4 |
def __init__(self, path=""):
|
| 5 |
self.processor = AutoProcessor.from_pretrained(path)
|
| 6 |
self.model = AutoModel.from_pretrained(path)
|
|
|
|
| 7 |
|
| 8 |
def __call__(self, data): #-> List[Dict[str, Any]]
|
| 9 |
|
|
@@ -14,7 +22,8 @@ class EndpointHandler():
|
|
| 14 |
text=input_text,
|
| 15 |
return_tensors="pt",
|
| 16 |
voice_preset = "v2/en_speaker_6"
|
| 17 |
-
)
|
|
|
|
| 18 |
speech_values = self.model.generate(**inputs, do_sample=True)
|
| 19 |
sample_rate = self.model.generation_config.sample_rate
|
| 20 |
|
|
|
|
| 1 |
from transformers import AutoProcessor, AutoModel
|
| 2 |
+
import torch
|
| 3 |
+
|
| 4 |
+
# set device
|
| 5 |
+
DEVICE = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
| 6 |
+
|
| 7 |
+
if device.type != 'cuda':
|
| 8 |
+
raise ValueError("need to run on GPU")
|
| 9 |
|
| 10 |
class EndpointHandler():
|
| 11 |
def __init__(self, path=""):
|
| 12 |
self.processor = AutoProcessor.from_pretrained(path)
|
| 13 |
self.model = AutoModel.from_pretrained(path)
|
| 14 |
+
self.model.to(DEVICE)
|
| 15 |
|
| 16 |
def __call__(self, data): #-> List[Dict[str, Any]]
|
| 17 |
|
|
|
|
| 22 |
text=input_text,
|
| 23 |
return_tensors="pt",
|
| 24 |
voice_preset = "v2/en_speaker_6"
|
| 25 |
+
).to(DEVICE)
|
| 26 |
+
|
| 27 |
speech_values = self.model.generate(**inputs, do_sample=True)
|
| 28 |
sample_rate = self.model.generation_config.sample_rate
|
| 29 |
|