Spaces:
Runtime error
Runtime error
Update syntax
Browse files
app.py
CHANGED
@@ -7,24 +7,38 @@ BATCH_SIZE = 8
|
|
7 |
|
8 |
device = 0 if torch.cuda.is_available() else "cpu"
|
9 |
|
10 |
-
|
11 |
task="automatic-speech-recognition",
|
12 |
model=MODEL_NAME,
|
13 |
chunk_length_s=30,
|
14 |
device=device,
|
15 |
)
|
16 |
|
17 |
-
def transcribe(
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
|
24 |
demo = gr.Blocks()
|
25 |
|
26 |
-
app = gr.Interface(fn=transcribe, inputs=gr.inputs.Audio(source="microphone", type="filepath"), outputs="textbox")
|
27 |
with demo:
|
28 |
-
|
29 |
-
|
30 |
-
|
|
|
|
|
|
7 |
|
8 |
device = 0 if torch.cuda.is_available() else "cpu"
|
9 |
|
10 |
+
asr = pipeline(
|
11 |
task="automatic-speech-recognition",
|
12 |
model=MODEL_NAME,
|
13 |
chunk_length_s=30,
|
14 |
device=device,
|
15 |
)
|
16 |
|
17 |
+
def transcribe(filepath):
|
18 |
+
if filepath is None:
|
19 |
+
gr.Warning("No audio found, please retry.")
|
20 |
+
return ""
|
21 |
+
output = asr(
|
22 |
+
filepath,
|
23 |
+
max_new_tokens=256,
|
24 |
+
chunk_length_s=30,
|
25 |
+
batch_size=8,
|
26 |
+
)
|
27 |
+
return output["text"]
|
28 |
+
|
29 |
+
mic_transcribe = gr.Interface(
|
30 |
+
fn=transcribe,
|
31 |
+
inputs=gr.Audio(sources="microphone",
|
32 |
+
type="filepath"),
|
33 |
+
outputs=gr.Textbox(label="Transcription",
|
34 |
+
lines=3),
|
35 |
+
allow_flagging="never")
|
36 |
|
37 |
demo = gr.Blocks()
|
38 |
|
|
|
39 |
with demo:
|
40 |
+
gr.TabbedInterface(
|
41 |
+
[mic_transcribe],
|
42 |
+
["Transcribe Microphone"],
|
43 |
+
)
|
44 |
+
demo.launch(share=True)
|