Update handler.py
Browse files- handler.py +13 -2
handler.py
CHANGED
@@ -5,7 +5,18 @@ import torch
|
|
5 |
|
6 |
SAMPLE_RATE = 16000
|
7 |
|
8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
class EndpointHandler():
|
11 |
def __init__(self, path=""):
|
@@ -30,4 +41,4 @@ class EndpointHandler():
|
|
30 |
result = self.model.transcribe(audio_nparray)
|
31 |
|
32 |
# postprocess the prediction
|
33 |
-
return {"
|
|
|
5 |
|
6 |
SAMPLE_RATE = 16000
|
7 |
|
8 |
+
MODEL_NAME = "openai/whisper-large" #this always needs to stay in line 8 :D sorry for the hackiness
|
9 |
+
lang = "dk"
|
10 |
+
|
11 |
+
device = 0 if torch.cuda.is_available() else "cpu"
|
12 |
+
pipe = pipeline(
|
13 |
+
task="automatic-speech-recognition",
|
14 |
+
model=MODEL_NAME,
|
15 |
+
chunk_length_s=30,
|
16 |
+
device=device,
|
17 |
+
)
|
18 |
+
|
19 |
+
pipe.model.config.forced_decoder_ids = pipe.tokenizer.get_decoder_prompt_ids(language=lang, task="transcribe")
|
20 |
|
21 |
class EndpointHandler():
|
22 |
def __init__(self, path=""):
|
|
|
41 |
result = self.model.transcribe(audio_nparray)
|
42 |
|
43 |
# postprocess the prediction
|
44 |
+
return {"tekst": result["text"]}
|