Tri4 commited on
Commit
9ff8a4f
1 Parent(s): cd37d9b

Create gradio-test.py

Browse files
Files changed (1) hide show
  1. gradio-test.py +36 -0
gradio-test.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import whisper
2
+ import gradio as gr
3
+
4
+ model = whisper.load_model("small")
5
+
6
+ def transcribe(audio):
7
+
8
+ #time.sleep(3)
9
+ # load audio and pad/trim it to fit 30 seconds
10
+ audio = whisper.load_audio(audio)
11
+ audio = whisper.pad_or_trim(audio)
12
+
13
+ # make log-Mel spectrogram and move to the same device as the model
14
+ mel = whisper.log_mel_spectrogram(audio).to(model.device)
15
+
16
+ # detect the spoken language
17
+ _, probs = model.detect_language(mel)
18
+ print(f"Detected language: {max(probs, key=probs.get)}")
19
+
20
+ # decode the audio
21
+ options = whisper.DecodingOptions(fp16 = False)
22
+ result = whisper.decode(model, mel, options)
23
+ return result.text
24
+
25
+
26
+
27
+ gr.Interface(
28
+ title = 'OpenAI Whisper ASR Gradio Web UI',
29
+ fn=transcribe,
30
+ inputs=[
31
+ gr.inputs.Audio(source="microphone", type="filepath")
32
+ ],
33
+ outputs=[
34
+ "textbox"
35
+ ],
36
+ live=True).launch()