Spaces:
Runtime error
Runtime error
import gradio as gr | |
import torch | |
from transformers import pipeline | |
import numpy as np | |
MODEL_NAME = "biodatlab/whisper-th-medium-combined" | |
DEVICE = 0 if torch.cuda.is_available() else "cpu" | |
transcriber = pipeline( | |
"automatic-speech-recognition", | |
model=MODEL_NAME, | |
chunk_length_s=30, | |
device=DEVICE | |
) | |
def transcribe(audio): | |
sr, y = audio | |
y = y.astype(np.float32) | |
y /= np.max(np.abs(y)) | |
return transcriber( | |
{"sampling_rate": sr, "raw": y}, | |
generate_kwargs={"language":"<|th|>", "task":"transcribe"}, | |
return_timestamps=False, | |
batch_size=16 | |
)["text"] | |
demo = gr.Interface( | |
transcribe, | |
gr.Audio(sources=["microphone"]), | |
"text", | |
) | |
demo.launch() |