Eric Guan commited on
Commit
8bea008
·
1 Parent(s): 0340380

Updated app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -5
app.py CHANGED
@@ -1,11 +1,25 @@
1
  import gradio as gr
2
  from transformers import pipeline
 
3
 
4
- # model = "openai/whisper-small"
5
- # pipe = pipeline("automatic-speech-recognition", model=model)
6
 
7
- def greet(name):
8
- return "Hello " + name + "!!"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
 
10
- demo = gr.Interface(fn=greet, inputs="text", outputs="text")
11
  demo.launch()
 
1
  import gradio as gr
2
  from transformers import pipeline
3
+ import numpy as np
4
 
5
+ transcriber = pipeline("automatic-speech-recognition", model="openai/whisper-small")
 
6
 
7
+ def transcribe(audio):
8
+ sr, y = audio
9
+
10
+ # Convert to mono if stereo
11
+ if y.ndim > 1:
12
+ y = y.mean(axis=1)
13
+
14
+ y = y.astype(np.float32)
15
+ y /= np.max(np.abs(y))
16
+
17
+ return transcriber({"sampling_rate": sr, "raw": y})["text"]
18
+
19
+ demo = gr.Interface(
20
+ transcribe,
21
+ gr.Audio(sources="microphone"),
22
+ "text",
23
+ )
24
 
 
25
  demo.launch()