from transformers import pipeline import gradio as gr username = 'bvallegc' ## 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 demo = gr.Interface( fn=classify_audio, inputs=gr.Audio(type="filepath"), outputs=[gr.outputs.Label(), gr.Number(label="Prediction time (s)")] ) demo.launch(debug=True)