Basic inference testing
parent
1c5ee1fc27
commit
c4b3738a24
@ -0,0 +1,26 @@
|
|||||||
|
import os
|
||||||
|
from threading import Lock
|
||||||
|
|
||||||
|
import torch
|
||||||
|
import whisper
|
||||||
|
|
||||||
|
# TODO use pydantic config
|
||||||
|
model_name = os.getenv("ASR_MODEL", "base")
|
||||||
|
if torch.cuda.is_available():
|
||||||
|
model = whisper.load_model(model_name).cuda()
|
||||||
|
else:
|
||||||
|
model = whisper.load_model(model_name)
|
||||||
|
model_lock = Lock()
|
||||||
|
|
||||||
|
# TODO move transcribe to a modeling worker
|
||||||
|
def transcribe(audio):
|
||||||
|
# options_dict = {"task" : task}
|
||||||
|
# if language:
|
||||||
|
# options_dict["language"] = language
|
||||||
|
# if initial_prompt:
|
||||||
|
# options_dict["initial_prompt"] = initial_prompt
|
||||||
|
with model_lock:
|
||||||
|
# result = model.transcribe(audio, **options_dict)
|
||||||
|
result = model.transcribe(audio)
|
||||||
|
|
||||||
|
return result
|
@ -0,0 +1,9 @@
|
|||||||
|
from local_whisper.inference import transcribe
|
||||||
|
from local_whisper.audio import load_audio
|
||||||
|
|
||||||
|
|
||||||
|
def test_transcribe(sample_audio):
|
||||||
|
with open(sample_audio, mode="rb") as af:
|
||||||
|
audio = load_audio(af)
|
||||||
|
result = transcribe(audio)
|
||||||
|
assert result["text"].strip() == "Let's see, right now I'm playing Horizon Zero Dawn. I also had just recently finished BioShock Infinite."
|
Loading…
Reference in New Issue