import gradio as gr from transformers import pipeline 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." example_samples = [ ("path_to_audio_file_1.wav",), ("path_to_audio_file_2.wav",), # Add more example samples as needed ] def classify_audio(audio): preds = pipe(audio) outputs = {} for p in preds: outputs[p["label"]] = p["score"] return outputs iface = gr.Interface( fn=classify_audio, inputs=gr.inputs.Audio(source="microphone", type="filepath", label="Record your audio"), outputs=gr.outputs.Label(), title=title, description=description ) iface.test_examples(example_samples) iface.launch(debug=True, share=True)