File size: 949 Bytes
9de4d3c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
from transformers import pipeline
import gradio as gr
pipe = pipeline(
"audio-classification", model="juangtzi/wav2vec2-base-finetuned-gtzan"
)
def classify_audio(filepath):
import time
start_time = time.time()
preds = pipe(filepath)
outputs = {}
for p in preds:
outputs[p["label"]] = p["score"]
end_time = time.time()
prediction_time = end_time - start_time
return outputs, prediction_time
title = "🎵 Music Genre Classifier"
description = """
Music Genre Classifier model (Fine-tuned "facebook/wav2vec2-base") Dataset: [GTZAN](https://huggingface.co/datasets/marsyas/gtzan)
"""
demo = gr.Interface(
fn=classify_audio,
inputs=gr.Audio(type="filepath"),
outputs=[gr.Label(), gr.Number(label="Prediction time (s)")],
title=title,
description=description,
examples="./example",
#cache_examples=True,
allow_flagging="never",
)
demo.queue()
demo.launch(share=True) |