Abhilashvj's picture
Update app.py
369d422 verified
# import gradio as gr
# gr.load("models/Abhilashvj/w2v-bert-2.0-malayalam-colab-CV16.0", gr.Audio(sources=["microphone"])).launch()
import gradio as gr
from transformers import pipeline
import numpy as np
transcriber = pipeline("automatic-speech-recognition", model="models/Abhilashvj/w2v-bert-2.0-malayalam-colab-CV16.0")
def transcribe(stream, new_chunk):
sr, y = new_chunk
y = y.astype(np.float32)
y /= np.max(np.abs(y))
if stream is not None:
stream = np.concatenate([stream, y])
else:
stream = y
return stream, transcriber({"sampling_rate": sr, "raw": stream})["text"]
demo = gr.Interface(
transcribe,
["state", gr.Audio(sources=["microphone"], streaming=True)],
["state", "text"],
live=True,
)
demo.launch()