Spaces:
Sleeping
Sleeping
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 | |
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 | |
"examples": ["000003.ogg", "000032.ogg", "000038.ogg", "000050.ogg", "000103.ogg"], | |
"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) |