Surya commited on
Commit
99422fc
·
unverified ·
1 Parent(s): a9ef84c

initial commit

Browse files
Files changed (1) hide show
  1. app.py +25 -0
app.py CHANGED
@@ -1,7 +1,32 @@
1
  import gradio as gr
 
 
2
 
3
  def greet(name):
4
  return "Hello " + name + "!!"
5
 
6
  iface = gr.Interface(fn=greet, inputs="text", outputs="text")
7
  iface.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
+ from transformers import pipeline
3
+ import numpy as np
4
 
5
  def greet(name):
6
  return "Hello " + name + "!!"
7
 
8
  iface = gr.Interface(fn=greet, inputs="text", outputs="text")
9
  iface.launch()
10
+ transcriber = pipeline("automatic-speech-recognition", model="openai/whisper-base.en")
11
+
12
+ def transcribe(stream, new_chunk):
13
+ sr, y = new_chunk
14
+ y = y.astype(np.float32)
15
+ y /= np.max(np.abs(y))
16
+
17
+ if stream is not None:
18
+ stream = np.concatenate([stream, y])
19
+ else:
20
+ stream = y
21
+ return stream, transcriber({"sampling_rate": sr, "raw": stream})["text"]
22
+
23
+
24
+ demo = gr.Interface(
25
+ transcribe,
26
+ ["state", gr.Audio(sources=["microphone"], streaming=True)],
27
+ ["state", "text"],
28
+ live=True,
29
+ )
30
+
31
+ demo.launch()
32
+