Maulik Madhavi commited on
Commit
69c5acc
1 Parent(s): 38e5434

add app file

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