File size: 809 Bytes
e07643f
 
 
 
 
 
98fe8e8
7b17bed
f7f7365
7b17bed
42aa5ee
 
 
 
7b17bed
538e95e
a2978c1
 
b783d61
a2978c1
 
538e95e
b783d61
7b17bed
9ad5b8c
e07643f
 
b881b82
e07643f
 
 
 
 
6dc8dcd
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

import gradio as gr
from transformers import pipeline
import torch

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"]
    prediction = pipe(audio)["text"]
    print(prediction)
    
    return prediction
    
gradio_app = gr.Interface(
    fn=transcribe,
    inputs=gr.Audio(type="filepath"),
    outputs=gr.Textbox(label="Result"),
    title="Transcribed",
)

if __name__ == "__main__":
    gradio_app.launch(share=True)