whisper_gradio / app.py
demavior's picture
Update app.py
7b17bed verified
raw
history blame
877 Bytes
import gradio as gr
from transformers import pipeline
device = "cuda:0" if torch.cuda.is_available() else "CPU"
def transcribe(audio):
pipe = pipeline(
"automatic-speech-recognition",
model="openai/whisper-small",
chunk_length_s=30,
device=device,
)
ds = load_dataset("hf-internal-testing/librispeech_asr_dummy", "clean", split="validation")
sample = ds[0]["audio"]
prediction = pipe(sample.copy(), batch_size=8)["text"]
" Mr. Quilter is the apostle of the middle classes, and we are glad to welcome his gospel."
return prediction
gradio_app = gr.Interface(
prediction,
inputs=gr.Image(label="Input", sources=['audio'], type="pil"),
outputs=[gr.Image(label="Ouput"), gr.Label(label="Result", num_top_classes=2)],
title="Transcribed",
)
if __name__ == "__main__":
gradio_app.launch()