| from transformers import pipeline, Wav2Vec2Processor, Wav2Vec2ForSequenceClassification | |
| import gradio as gr | |
| model_id = "Tirath5504/distilhubert-finetuned-gtzan" | |
| processor = Wav2Vec2Processor.from_pretrained(model_id) | |
| model = Wav2Vec2ForSequenceClassification.from_pretrained(model_id) | |
| pipe = pipeline("audio-classification", model=model, processor=processor) | |
| def classify_audio(filepath): | |
| preds = pipe(filepath) | |
| outputs = {} | |
| for p in preds: | |
| outputs[p["label"]] = p["score"] | |
| return outputs | |
| demo = gr.Interface( | |
| fn=classify_audio, inputs=gr.Audio(type="filepath"), outputs=gr.outputs.Label() | |
| ) | |
| demo.launch(debug=True) |