Abhilashvj
commited on
Commit
•
369d422
1
Parent(s):
297708a
Update app.py
Browse files
app.py
CHANGED
@@ -1,3 +1,30 @@
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
-
|
|
|
1 |
+
# import gradio as gr
|
2 |
+
|
3 |
+
# gr.load("models/Abhilashvj/w2v-bert-2.0-malayalam-colab-CV16.0", gr.Audio(sources=["microphone"])).launch()
|
4 |
+
|
5 |
import gradio as gr
|
6 |
+
from transformers import pipeline
|
7 |
+
import numpy as np
|
8 |
+
|
9 |
+
transcriber = pipeline("automatic-speech-recognition", model="models/Abhilashvj/w2v-bert-2.0-malayalam-colab-CV16.0")
|
10 |
+
|
11 |
+
def transcribe(stream, new_chunk):
|
12 |
+
sr, y = new_chunk
|
13 |
+
y = y.astype(np.float32)
|
14 |
+
y /= np.max(np.abs(y))
|
15 |
+
|
16 |
+
if stream is not None:
|
17 |
+
stream = np.concatenate([stream, y])
|
18 |
+
else:
|
19 |
+
stream = y
|
20 |
+
return stream, transcriber({"sampling_rate": sr, "raw": stream})["text"]
|
21 |
+
|
22 |
+
|
23 |
+
demo = gr.Interface(
|
24 |
+
transcribe,
|
25 |
+
["state", gr.Audio(sources=["microphone"], streaming=True)],
|
26 |
+
["state", "text"],
|
27 |
+
live=True,
|
28 |
+
)
|
29 |
|
30 |
+
demo.launch()
|