Spaces:
Runtime error
Runtime error
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 <img src="shzam.png" width=200px> finds the name of the 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.outputs.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() |