Lightmourne's picture
Add application file
bb2ea49
raw
history blame
1.27 kB
from transformers import pipeline
import gradio as gr
model_id = "Lightmourne/distilhubert-finetuned-gtzan"
pipe = pipeline("audio-classification", model=model_id)
def classify_audio(filepath):
preds = pipe(filepath)
outputs = {}
for p in preds:
outputs[p["label"]] = p["score"]
return outputs
demo = gr.Blocks()
title = "Simple music genre classifier"
description = """
A simple music genre classifier allows you to categorize a music track into one of ten music genres, such as: "blues", "classical", "country", "disco", "hiphop", "jazz", "metal", "pop", "reggae", "rock". Link to the fine-tuned model checkpoint: https://huggingface.co/Lightmourne/distilhubert-finetuned-gtzan
"""
mic_classify_audio = gr.Interface(
fn=classify_audio,
inputs=gr.Audio(source="microphone", type="filepath"),
outputs=gr.outputs.Label(),
title=title,
description=description,
)
file_classify_audio = gr.Interface(
fn=classify_audio,
inputs=gr.Audio(source="upload", type="filepath"),
outputs=gr.outputs.Label(),
#examples=[["./example.wav"]],
title=title,
description=description,
)
with demo:
gr.TabbedInterface([mic_classify_audio, file_classify_audio], ["Microphone", "Audio File"])
demo.launch(debug=True)