File size: 769 Bytes
2a0abef
16fe4c6
2a0abef
 
16fe4c6
2a0abef
 
 
 
 
16fe4c6
2a0abef
 
 
 
 
 
 
 
e0a82fe
2a0abef
8d97771
 
 
 
2a0abef
 
 
 
8445fe7
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
from transformers import pipeline
import torch
import gradio as gr

device = "cuda:0" if torch.cuda.is_available() else "cpu"

pipe = pipeline(
    "automatic-speech-recognition",
    model="openai/whisper-small.en",
    chunk_length_s=30,
    device=device,
)

# Function to transcribe audio
def transcribe(audio):
    text = pipe(audio)["text"]
    return text

# Create the interface
with gr.Blocks() as demo:
    with gr.Row():
      with gr.Column(scale=1):  
        audio_input = gr.Audio(sources=["microphone"], type="filepath", label="Record Audio")
        submit_button = gr.Button("Transcribe")
        text_output = gr.Textbox(label="Transcription")

    submit_button.click(fn=transcribe, inputs=audio_input, outputs=text_output)


demo.launch(share=True)