File size: 1,168 Bytes
f6ed4b1
 
 
 
 
9f4cea2
87d05df
9f4cea2
f6ed4b1
 
 
281f845
f6ed4b1
 
 
 
 
 
 
 
 
 
2ccb463
f6ed4b1
 
e5a107b
f6ed4b1
 
 
 
2ccb463
f6ed4b1
 
e5a107b
f6ed4b1
 
 
 
 
 
 
 
 
2ccb463
f6ed4b1
83af583
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
from transformers import pipeline

asr = pipeline(task="automatic-speech-recognition",
               model="distil-whisper/distil-small.en")

import gradio as gr
demo = gr.Blocks()

# now ho to make the demo take long time audio
def transcribe_long_form(filepath):
    if filepath is None:
        gr.Warning("Please submit again <3 ")
        return ""
    output = asr(
      filepath,
      max_new_tokens=256,
      chunk_length_s=30,
      batch_size=8,
    )
    return output["text"]

mic_transcribe = gr.Interface(
    fn=transcribe_long_form,
    inputs=gr.Audio(sources="microphone",
                    type="filepath"),
    outputs=gr.Textbox(label="Transcription",
                       lines=3),
    allow_flagging="never")

file_transcribe = gr.Interface(
    fn=transcribe_long_form,
    inputs=gr.Audio(sources="upload",
                    type="filepath"),
    outputs=gr.Textbox(label="Transcription",
                       lines=3),
    allow_flagging="never",
)

with demo:
    gr.TabbedInterface(
        [mic_transcribe,
         file_transcribe],
        ["Transcribe Microphone",
         "Transcribe Audio File"])

demo.launch(share=True)