Spaces:
Sleeping
Sleeping
Eric Guan
commited on
Commit
·
2c18b36
1
Parent(s):
9aa4283
Updated app.py
Browse files
app.py
CHANGED
@@ -4,9 +4,30 @@ from transformers import pipeline
|
|
4 |
model = "openai/whisper-small"
|
5 |
pipe = pipeline("automatic-speech-recognition", model=model)
|
6 |
|
7 |
-
def
|
8 |
-
|
9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
-
demo = gr.
|
12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
model = "openai/whisper-small"
|
5 |
pipe = pipeline("automatic-speech-recognition", model=model)
|
6 |
|
7 |
+
def transcribe_speech(filepath):
|
8 |
+
output = pipe(
|
9 |
+
filepath,
|
10 |
+
max_new_tokens=256,
|
11 |
+
generate_kwargs={
|
12 |
+
"task": "transcribe",
|
13 |
+
},
|
14 |
+
chunk_length_s=30,
|
15 |
+
batch_size=8,
|
16 |
+
)
|
17 |
+
return output["text"]
|
18 |
|
19 |
+
demo = gr.Blocks()
|
20 |
+
|
21 |
+
mic_transcribe = gr.Interface(
|
22 |
+
fn=transcribe_speech,
|
23 |
+
inputs=gr.Audio(sources="microphone", type="filepath"),
|
24 |
+
outputs=gr.outputs.Textbox(),
|
25 |
+
)
|
26 |
+
|
27 |
+
with demo:
|
28 |
+
gr.TabbedInterface(
|
29 |
+
[mic_transcribe],
|
30 |
+
["Transcribe Microphone"],
|
31 |
+
)
|
32 |
+
|
33 |
+
demo.launch(debug=True)
|