from transformers import pipeline username = "afern24" ## Complete your username model_id = f"{username}/distilhubert-finetuned-gtzan" pipe = pipeline("audio-classification", model=model_id) def classify_audio(filepath): """ Goes from [{'score': 0.8339303731918335, 'label': 'country'}, {'score': 0.11914275586605072, 'label': 'rock'},] to {"country": 0.8339303731918335, "rock":0.11914275586605072} """ preds = pipe(filepath) outputs = {} for p in preds: outputs[p["label"]] = p["score"] return outputs import gradio as gr demo = gr.Interface( fn=classify_audio, inputs=gr.Audio(type="filepath"), outputs=[gr.Label(label="Predictions"), gr.Number(label="Prediction time (s)")], title="Distilhubert-finetuned-gtzan", description="Audio classifier based on music genres, for more check out my github ar www.github.com/Ferno22" ) demo.launch(debug=True)