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()