onnx-asr / app.py
istupakov's picture
Update app.py
bc2c733 verified
raw
history blame
3.85 kB
from importlib.metadata import version
import gradio as gr
import numpy as np
import onnx_asr
print(f"onnx_asr version: {version('onnx_asr')}")
models = {
name: onnx_asr.load_model(name)
for name in [
"gigaam-v2-ctc",
"gigaam-v2-rnnt",
"nemo-fastconformer-ru-ctc",
"nemo-fastconformer-ru-rnnt",
"alphacep/vosk-model-ru",
"alphacep/vosk-model-small-ru",
"whisper-base",
]
}
def recoginize(audio: tuple[int, np.ndarray]):
sample_rate, waveform = audio
try:
waveform = waveform.astype(np.float32) / 2 ** (8 * waveform.itemsize - 1)
return [[name, model.recognize(waveform, sample_rate=sample_rate, language="ru")] for name, model in models.items()]
except Exception as e:
raise gr.Error(f"{e} Audio: sample_rate: {sample_rate}, waveform.shape: {waveform.shape}.") from e
demo = gr.Interface(
fn=recoginize,
title="ASR demo using onnx-asr (Russian models)",
description="""
# ONNX ASR
[![PyPI - Version](https://img.shields.io/pypi/v/onnx-asr.svg)](https://pypi.org/project/onnx-asr)
[![PyPI - Downloads](https://img.shields.io/pypi/dm/onnx-asr)](https://pypi.org/project/onnx-asr)
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/onnx-asr.svg)](https://pypi.org/project/onnx-asr)
[![PyPI - Types](https://img.shields.io/pypi/types/onnx-asr)](https://pypi.org/project/onnx-asr)
[![GitHub License](https://img.shields.io/github/license/istupakov/onnx-asr)](https://github.com/istupakov/onnx-asr/blob/main/LICENSE)
[![CI](https://github.com/istupakov/onnx-asr/actions/workflows/python-package.yml/badge.svg)](https://github.com/istupakov/onnx-asr/actions/workflows/python-package.yml)
**[onnx-asr](https://github.com/istupakov/onnx-asr)** is a Python package for Automatic Speech Recognition using ONNX models. The package is written in pure Python with minimal dependencies (*PyTorch is not required*):
[![numpy](https://img.shields.io/badge/numpy-required-blue?logo=numpy)](https://pypi.org/project/numpy/)
[![onnxruntime](https://img.shields.io/badge/onnxruntime-required-blue?logo=onnx)](https://pypi.org/project/onnxruntime/)
[![huggingface-hub](https://img.shields.io/badge/huggingface--hub-optional-blue?logo=huggingface)](https://pypi.org/project/huggingface-hub/)
## Models used in demo:
* `gigaam-v2-ctc` - Sber GigaAM v2 CTC ([origin](https://github.com/salute-developers/GigaAM), [onnx](https://huggingface.co/istupakov/gigaam-v2-onnx))
* `gigaam-v2-rnnt` - Sber GigaAM v2 RNN-T ([origin](https://github.com/salute-developers/GigaAM), [onnx](https://huggingface.co/istupakov/gigaam-v2-onnx))
* `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))
* `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))
* `alphacep/vosk-model-ru` - Alpha Cephei Vosk 0.54-ru ([origin](https://huggingface.co/alphacep/vosk-model-ru))
* `alphacep/vosk-model-small-ru` - Alpha Cephei Vosk 0.52-small-ru ([origin](https://huggingface.co/alphacep/vosk-model-small-ru))
* `whisper-base` - OpenAI Whisper Base exported with onnxruntime ([origin](https://huggingface.co/openai/whisper-base), [onnx](https://huggingface.co/istupakov/whisper-base-onnx))
""",
inputs=[gr.Audio(min_length=1, max_length=20)],
outputs=[gr.Dataframe(headers=["Model", "result"], wrap=True, show_fullscreen_button=True)],
flagging_mode="never",
)
demo.launch()