Spaces:
Runtime error
Runtime error
adds mic or file
Browse files
app.py
CHANGED
@@ -5,18 +5,48 @@ model = nemo_asr.models.ASRModel.restore_from("CnLgGm025_SpeUni1024_DI_EATL.nemo
|
|
5 |
model.eval()
|
6 |
|
7 |
|
8 |
-
def transcribe(audio_file):
|
9 |
-
#
|
10 |
-
#
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
model.eval()
|
6 |
|
7 |
|
8 |
+
def transcribe(audio_mic, audio_file, models_names):
|
9 |
+
# transcribe audio_mic and audio_file separately
|
10 |
+
# because transcribe() fails is path is empty
|
11 |
+
transcription_mic = "\n".join(
|
12 |
+
[
|
13 |
+
f"{model_name} => {model.transcribe([audio_mic])[0]}"
|
14 |
+
for model_name in models_names
|
15 |
+
]
|
16 |
+
if audio_mic
|
17 |
+
else ""
|
18 |
+
)
|
19 |
+
transcription_file = "\n".join(
|
20 |
+
[
|
21 |
+
f"{model_name} => {model.transcribe([audio_file])[0]}"
|
22 |
+
for model_name in models_names
|
23 |
+
]
|
24 |
+
if audio_file
|
25 |
+
else ""
|
26 |
+
)
|
27 |
+
return transcription_mic, transcription_file
|
28 |
+
|
29 |
+
|
30 |
+
selection = ["a", "b", "c"]
|
31 |
+
|
32 |
+
demo = gr.Blocks()
|
33 |
+
|
34 |
+
with demo:
|
35 |
+
models_names = gr.CheckboxGroup(selection)
|
36 |
+
with gr.Row():
|
37 |
+
audio_mic = gr.Audio(source="microphone", type="filepath", label="Microphone")
|
38 |
+
audio_file = gr.Audio(source="upload", type="filepath", label="File")
|
39 |
+
|
40 |
+
with gr.Row():
|
41 |
+
output_mic = gr.TextArea(label="Microphone Transcription")
|
42 |
+
output_file = gr.TextArea(label="Audio Transcription")
|
43 |
+
|
44 |
+
b1 = gr.Button("Transcribe")
|
45 |
+
|
46 |
+
b1.click(
|
47 |
+
transcribe,
|
48 |
+
inputs=[audio_mic, audio_file, models_names],
|
49 |
+
outputs=[output_mic, output_file],
|
50 |
+
)
|
51 |
+
|
52 |
+
demo.launch()
|