from transformers import pipeline import gradio as gr model_id = "Teapack1/model_KWS" # update with your model id pipe = pipeline("audio-classification", model=model_id) title = "Keyword Spotting Wav2Vec2" description = "Gradio demo for finetuned Wav2Vec2 model on a custom dataset to perform keyword spotting task. Classes are scene 1, scene 2, scene 3, yes, no and stop." def classify_audio(filepath): preds = pipe(filepath) outputs = {} for p in preds: outputs[p["label"]] = p["score"] return outputs demo = gr.Blocks() mic_classify = gr.Interface( fn=classify_audio, inputs=gr.Audio(sources="microphone", type="filepath"), outputs=gr.outputs.Label() ) file_classify = gr.Interface( fn=classify_audio, inputs=gr.Audio(sources="upload", type="filepath"), outputs=gr.outputs.Label() ) with demo: gr.TabbedInterface( [mic_classify, file_classify], ["Transcribe Microphone", "Transcribe Audio File"], )