Spaces:
Sleeping
Sleeping
File size: 1,291 Bytes
34d8803 253867d 34d8803 3528c71 47e7707 e1e2511 713bc64 253867d fd5d828 e1e2511 02ad7fc fd5d828 3528c71 e1e2511 02ad7fc 3528c71 fd5d828 3528c71 e3e8720 3528c71 e1e2511 3528c71 e1e2511 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
import gradio as gr
from transformers import pipeline
# Load the model and processor
model_id = "openai/whisper-small"
device = "cpu"
BATCH_SIZE = 8
pipe = pipeline(
task="automatic-speech-recognition",
model=model_id,
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 transcribelocal(microphone, file_upload):
# Check which input is not None
if microphone is not None:
audio = microphone
else:
audio = file_upload
return transcribe(audio, "transcribe")
# Create a Gradio interface with two modes: realtime and file upload
iface = gr.Interface(
fn=transcribelocal,
inputs=[
gr.inputs.Audio(source="microphone", type="filepath", label="Realtime Mode"),
gr.inputs.Audio(source="upload", type="filepath", label="File Upload Mode")
],
outputs=[
gr.outputs.Textbox(label="Transcription")
],
title="Whisper Transcription App",
description="A Gradio app that uses OpenAI's whisper model to transcribe audio"
)
# Launch the app
iface.launch() |