Spaces:
Runtime error
Runtime error
from transformers import pipeline | |
import gradio as gr | |
from timeit import default_timer as timer | |
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} | |
""" | |
start_time = timer() | |
preds = pipe(filepath) | |
outputs = {} | |
for p in preds: | |
outputs[p["label"]] = p["score"] | |
pred_time = round(timer() - start_time, 5) | |
return outputs, pred_time | |
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) |