Spaces:
Runtime error
Runtime error
File size: 1,094 Bytes
bbb0227 309aede 10bbaeb 309aede bbb0227 a0de893 bbb0227 bcf1972 bbb0227 ecc352f bbb0227 bcf1972 |
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 |
import gradio as gr
import librosa
from transformers import pipeline
pipe = pipeline("audio-classification", model="Shamik/whisper-base.en-finetuned-gtzan")
title = """
๐ถ Music Genre Classifier ๐ถ
"""
description = """
Next time you think of how **Shazam** finds the name of a song, well it might certainly be classifying the genre of the music too.
This tool classifies music based
on pre-defined genre from the [GTZAN](https://huggingface.co/datasets/marsyas/gtzan) dataset,
which contains music from the following genres:
`blues, classical, country, disco, hiphop, jazz, metal, pop, reggae, and rock`.
"""
def classify_audio(filepath):
audio, sampling_rate = librosa.load(filepath, sr=16_000)
preds = pipe(audio)
outputs = {}
for p in preds:
outputs[p["label"]] = p["score"]
return outputs
label = gr.Label()
demo = gr.Interface(
fn=classify_audio,
inputs=gr.Audio(type="filepath"),
outputs=label,
title=title,
description=description,
examples=[["song1.ogg"], ["song2.ogg"], ["song3.ogg"], ["song4.ogg"]],
)
demo.launch()
|