sotirios-slv's picture
Added required tokenizer arg
50a8cbc
raw
history blame
1.3 kB
import logging
import gradio as gr
import torch
from transformers import AutoModelForSpeechSeq2Seq, AutoProcessor, pipeline
device = "cuda:0" if torch.cuda.is_available() else "cpu"
torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32
model_id = "openai/whisper-large-v3"
model = AutoModelForSpeechSeq2Seq.from_pretrained(
model_id, torch_dtype=torch_dtype, low_cpu_mem_usage=True, use_safetensors=True
)
model.to(device)
processor = AutoProcessor.from_pretrained(model_id)
pipe = pipeline(
task="automatic-speech-recognition",
model=model,
tokenizer=processor.tokenizer,
# feature_extractor=processor.feature_extractor,
# max_new_tokens=128,
chunk_length_s=30,
batch_size=8,
# return_timestamps=True,
# torch_dtype=torch_dtype,
device=device,
)
def transcribe_audio(audio):
result = pipe(audio)
logging.info(f'TRANSCRIPTION {result["text"]}')
return result
input_audio = gr.Audio(
sources=["microphone"],
waveform_options=gr.WaveformOptions(
waveform_color="#01C6FF",
waveform_progress_color="#0066B4",
skip_length=2,
show_controls=False,
),
)
demo = gr.Interface(fn=transcribe_audio, inputs=input_audio, outputs="text")
if __name__ == "__main__":
demo.launch()