ismaeltorres00 commited on
Commit
63fefa8
1 Parent(s): 9b9bcc9

Create app2.py

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