File size: 951 Bytes
79c905a
 
 
 
df3ff36
79c905a
75ffc04
79c905a
 
 
 
 
 
 
 
 
 
 
 
 
0c7bfc1
79c905a
 
0c7bfc1
79c905a
 
 
 
 
 
0c7bfc1
79c905a
 
 
 
 
 
 
0c7bfc1
 
 
79c905a
 
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
import os
import gradio as gr
import whisper

model = whisper.load_model("small")

print(model.device)
        
def inference(audio):
    audio = whisper.load_audio(audio)
    audio = whisper.pad_or_trim(audio)
    
    mel = whisper.log_mel_spectrogram(audio).to(model.device)
    
    _, probs = model.detect_language(mel)
    
    options = whisper.DecodingOptions(fp16 = False)
    result = whisper.decode(model, mel, options)
    
    print(result.text)
    return result.text


block = gr.Blocks()



with block:
    with gr.Group():
        with gr.Box():
            with gr.Row():
                audio = gr.Audio(
                    label="Input Audio",
                    source="microphone",
                    type="filepath"
                )

                btn = gr.Button("Transcribe")
        text = gr.Textbox()
                
        btn.click(inference, inputs=[audio], outputs=[text], api_name="transcribe")

block.launch()