Sulav commited on
Commit
befe725
·
1 Parent(s): 68c142d

replacing transformers pipeline with whisper python library

Browse files
Files changed (1) hide show
  1. app.py +29 -7
app.py CHANGED
@@ -1,14 +1,36 @@
 
1
  import gradio as gr
2
- from transformers import pipeline
3
 
4
- p = pipeline("automatic-speech-recognition", model='openai/whisper-small')
5
 
6
  def transcribe(audio):
7
- text = p(audio)["text"]
8
- return text
 
 
 
9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  gr.Interface(
 
11
  fn=transcribe,
12
- inputs=gr.Audio(source="microphone", type="filepath"),
13
- outputs="text").launch()
14
-
 
 
 
 
 
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()