operablepattern's picture
Update app.py
126bdd3
raw
history blame
1.22 kB
import gradio as gr
import torch
from transformers import pipeline
MODEL_NAME = "openai/whisper-tiny"
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(inputs, task):
if inputs is None:
raise gr.Error("No audio file submitted! Please upload or record an audio file before submitting your request.")
text = pipe(inputs, batch_size=BATCH_SIZE, generate_kwargs={"task": task}, return_timestamps=True)["text"]
return text
def greet(name):
return "Hello " + name + "!!"
iface = gr.Interface(
fn=transcribe,
inputs=[
gr.inputs.Audio(source="microphone", type="filepath", optional=True),
],
outputs="text",
layout="horizontal",
theme="huggingface",
title="test",
description=(
"Transcribe long-form microphone or audio inputs with the click of a button! Demo uses the OpenAI Whisper"
f" checkpoint [{MODEL_NAME}](https://huggingface.co/{MODEL_NAME}) and πŸ€— Transformers to transcribe audio files"
" of arbitrary length."
),
allow_flagging="never",
)
iface.launch()