Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
from importlib.metadata import version
|
|
|
|
| 2 |
|
| 3 |
import gradio as gr
|
| 4 |
import numpy as np
|
|
@@ -20,46 +21,43 @@ models = {
|
|
| 20 |
}
|
| 21 |
|
| 22 |
|
| 23 |
-
def
|
| 24 |
sample_rate, waveform = audio
|
| 25 |
try:
|
| 26 |
waveform = waveform.astype(np.float32) / 2 ** (8 * waveform.itemsize - 1)
|
| 27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
except Exception as e:
|
| 29 |
raise gr.Error(f"{e} Audio: sample_rate: {sample_rate}, waveform.shape: {waveform.shape}.") from e
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
#
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
* `alphacep/vosk-model-ru` - Alpha Cephei Vosk 0.54-ru ([origin](https://huggingface.co/alphacep/vosk-model-ru))
|
| 57 |
-
* `alphacep/vosk-model-small-ru` - Alpha Cephei Vosk 0.52-small-ru ([origin](https://huggingface.co/alphacep/vosk-model-small-ru))
|
| 58 |
-
* `whisper-base` - OpenAI Whisper Base exported with onnxruntime ([origin](https://huggingface.co/openai/whisper-base), [onnx](https://huggingface.co/istupakov/whisper-base-onnx))
|
| 59 |
-
""",
|
| 60 |
-
inputs=[gr.Audio(min_length=1, max_length=20)],
|
| 61 |
-
outputs=[gr.Dataframe(headers=["Model", "result"], wrap=True, show_fullscreen_button=True)],
|
| 62 |
-
flagging_mode="never",
|
| 63 |
-
)
|
| 64 |
|
| 65 |
demo.launch()
|
|
|
|
| 1 |
from importlib.metadata import version
|
| 2 |
+
from timeit import default_timer as timer
|
| 3 |
|
| 4 |
import gradio as gr
|
| 5 |
import numpy as np
|
|
|
|
| 21 |
}
|
| 22 |
|
| 23 |
|
| 24 |
+
def recognize(audio: tuple[int, np.ndarray]):
|
| 25 |
sample_rate, waveform = audio
|
| 26 |
try:
|
| 27 |
waveform = waveform.astype(np.float32) / 2 ** (8 * waveform.itemsize - 1)
|
| 28 |
+
results = []
|
| 29 |
+
for name, model in models.items():
|
| 30 |
+
start = timer()
|
| 31 |
+
result = model.recognize(waveform, sample_rate=sample_rate, language="ru")
|
| 32 |
+
time = timer() - start
|
| 33 |
+
results.append([name, result, f"{time:.3f} s."])
|
| 34 |
except Exception as e:
|
| 35 |
raise gr.Error(f"{e} Audio: sample_rate: {sample_rate}, waveform.shape: {waveform.shape}.") from e
|
| 36 |
+
else:
|
| 37 |
+
return results
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
with gr.Blocks() as demo:
|
| 41 |
+
gr.Markdown("""
|
| 42 |
+
# ASR demo using onnx-asr (Russian models)
|
| 43 |
+
**[onnx-asr](https://github.com/istupakov/onnx-asr)** is a Python package for Automatic Speech Recognition using ONNX models.
|
| 44 |
+
The package is written in pure Python with minimal dependencies (no `pytorch` or `transformers`).
|
| 45 |
+
""")
|
| 46 |
+
input = gr.Audio(min_length=1, max_length=20)
|
| 47 |
+
with gr.Row():
|
| 48 |
+
gr.ClearButton(input)
|
| 49 |
+
btn = gr.Button("Recognize", variant="primary")
|
| 50 |
+
output = gr.Dataframe(headers=["model", "result", "time"], wrap=True)
|
| 51 |
+
btn.click(fn=recognize, inputs=input, outputs=output)
|
| 52 |
+
with gr.Accordion("ASR models used in this demo", open=False):
|
| 53 |
+
gr.Markdown("""
|
| 54 |
+
* `gigaam-v2-ctc` - Sber GigaAM v2 CTC ([origin](https://github.com/salute-developers/GigaAM), [onnx](https://huggingface.co/istupakov/gigaam-v2-onnx))
|
| 55 |
+
* `gigaam-v2-rnnt` - Sber GigaAM v2 RNN-T ([origin](https://github.com/salute-developers/GigaAM), [onnx](https://huggingface.co/istupakov/gigaam-v2-onnx))
|
| 56 |
+
* `nemo-fastconformer-ru-ctc` - Nvidia FastConformer-Hybrid Large (ru) with CTC decoder ([origin](https://huggingface.co/nvidia/stt_ru_fastconformer_hybrid_large_pc), [onnx](https://huggingface.co/istupakov/stt_ru_fastconformer_hybrid_large_pc_onnx))
|
| 57 |
+
* `nemo-fastconformer-ru-rnnt` - Nvidia FastConformer-Hybrid Large (ru) with RNN-T decoder ([origin](https://huggingface.co/nvidia/stt_ru_fastconformer_hybrid_large_pc), [onnx](https://huggingface.co/istupakov/stt_ru_fastconformer_hybrid_large_pc_onnx))
|
| 58 |
+
* `alphacep/vosk-model-ru` - Alpha Cephei Vosk 0.54-ru ([origin](https://huggingface.co/alphacep/vosk-model-ru))
|
| 59 |
+
* `alphacep/vosk-model-small-ru` - Alpha Cephei Vosk 0.52-small-ru ([origin](https://huggingface.co/alphacep/vosk-model-small-ru))
|
| 60 |
+
* `whisper-base` - OpenAI Whisper Base exported with onnxruntime ([origin](https://huggingface.co/openai/whisper-base), [onnx](https://huggingface.co/istupakov/whisper-base-onnx))
|
| 61 |
+
""")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
|
| 63 |
demo.launch()
|