Spaces:
Sleeping
Sleeping
File size: 1,067 Bytes
365d3a1 e91b2cd 365d3a1 ee8c172 365d3a1 e91b2cd 365d3a1 e91b2cd 365d3a1 298d6a8 5484d0f 365d3a1 4f40b30 365d3a1 7038cf7 365d3a1 fd62b09 e91b2cd 365d3a1 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
import gradio as gr
import numpy as np
# import spaces #[uncomment to use ZeroGPU]
import torch
from transformers import pipeline
device = "cuda" if torch.cuda.is_available() else "cpu"
model_repo_id = "emlinking/wav2vec2-large-xls-r-300m-tsm-asr-v6"
if torch.cuda.is_available():
torch_dtype = torch.float16
else:
torch_dtype = torch.float32
pipe = pipeline(task="automatic-speech-recognition", model=model_repo_id, device=device)
# @spaces.GPU #[uncomment to use ZeroGPU]
def infer(
audio
):
sampling_rate, wav = audio
if wav.ndim > 1:
wav = wav.mean(axis=1)
wav = wav.astype(np.float32)
wav /= np.max(np.abs(wav))
return pipe(wav)['text']
css = """
#col-container {
margin: 0 auto;
max-width: 640px;
}
"""
with gr.Blocks(css=css) as demo:
gr.Markdown(" # PhonoLearn")
input_audio = gr.Audio(
sources=["microphone", "upload"]
)
output = gr.Textbox(label='Output')
input_audio.input(fn=infer, inputs=input_audio, outputs=output)
if __name__ == "__main__":
demo.launch()
|