- change handler
Browse files- handler.py +8 -3
handler.py
CHANGED
@@ -1,7 +1,10 @@
|
|
1 |
from typing import Dict, List, Any
|
2 |
|
3 |
import torch as torch
|
4 |
-
from transformers import pipeline
|
|
|
|
|
|
|
5 |
|
6 |
|
7 |
class EndpointHandler():
|
@@ -16,7 +19,8 @@ class EndpointHandler():
|
|
16 |
chunk_length_s=30,
|
17 |
device=device,
|
18 |
)
|
19 |
-
|
|
|
20 |
|
21 |
def __call__(self, data: Dict[str, Any]) -> List[Dict[str, Any]]:
|
22 |
"""
|
@@ -29,7 +33,8 @@ class EndpointHandler():
|
|
29 |
#print request
|
30 |
print("request")
|
31 |
print(data)
|
32 |
-
#
|
|
|
33 |
inputs = data.pop("inputs", data)
|
34 |
|
35 |
text = self.pipe(inputs)["text"]
|
|
|
1 |
from typing import Dict, List, Any
|
2 |
|
3 |
import torch as torch
|
4 |
+
from transformers import pipeline, WhisperProcessor
|
5 |
+
|
6 |
+
from scipy.io.wavfile import read
|
7 |
+
|
8 |
|
9 |
|
10 |
class EndpointHandler():
|
|
|
19 |
chunk_length_s=30,
|
20 |
device=device,
|
21 |
)
|
22 |
+
processor = WhisperProcessor.from_pretrained("openai/whisper-large")
|
23 |
+
self.pipe.model.config.forced_decoder_ids = processor.get_decoder_prompt_ids(language="nl", task="transcribe")
|
24 |
|
25 |
def __call__(self, data: Dict[str, Any]) -> List[Dict[str, Any]]:
|
26 |
"""
|
|
|
33 |
#print request
|
34 |
print("request")
|
35 |
print(data)
|
36 |
+
# audio_data = read(io.BytesIO(data))
|
37 |
+
# get inputs, inputs in request body is possible equal to wav or mp3 file
|
38 |
inputs = data.pop("inputs", data)
|
39 |
|
40 |
text = self.pipe(inputs)["text"]
|