babel-fish / app.py
hexular's picture
.
24e0e26
raw
history blame
621 Bytes
import gradio as gr
from transformers import pipeline
import torch
MODEL_NAME = "openai/whisper-large-v3"
BATCH_SIZE = 8
device = 0 if torch.cuda.is_available() else "cpu"
pipe = pipeline(
task="automatic-speech-recognition",
model=MODEL_NAME,
chunk_length_s=30,
device=device,
)
def transcribe(audio):
print(audio)
result = pipe(audio, batch_size=BATCH_SIZE)["text"]
print(result)
return result
demo = gr.Blocks()
app = gr.Interface(fn=transcribe, inputs=gr.inputs.Audio(source="microphone", type="filepath"), outputs="textbox")
with demo:
gr.TabbedInterface([app], "Mic")
demo.launch()