Spaces:
Sleeping
Sleeping
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 = "openai/whisper-tiny" | |
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 | |
): | |
return pipe(audio, generate_kwargs={'language': 'chinese'})['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() | |