Spaces:
Runtime error
Runtime error
import os | |
import tempfile | |
import torch | |
import gradio as gr | |
from transformers import pipeline | |
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(inputs, task="transcribe"): | |
if inputs is None: | |
raise gr.Error("No audio file submitted!") | |
output = pipe( | |
inputs, | |
batch_size=BATCH_SIZE, | |
generate_kwargs={"task": task}, | |
return_timestamps=True | |
) | |
return output["text"] | |
demo = gr.Interface( | |
fn=transcribe, | |
inputs=["audio"], | |
outputs="text", | |
title="Transcribe Audio to Text", # Give our demo a title | |
) | |
demo.launch() |