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) classification = [{"label": p["label"], "score": p["score"]} for p in preds] return {"classification": classification} interface_options = { "title": "Music Genre Classification", "description": "The audio classifier for those who are the best and only want and require the best", "interpretation": "default", "layout": "horizontal", # Audio from validation file "allow_flagging": "never" } demo = gr.Interface( fn=classify_audio, inputs=gr.Audio(type="filepath"), outputs=[gr.outputs.Label(), gr.Number(label="Prediction time (s)")], **interface_options ) demo.launch(debug=True)