MUSIC_MAJOR / app.py
asutosh09's picture
Update app.py
acfcbda verified
raw
history blame
796 Bytes
import torch
from transformers import pipeline
import gradio as gr
MODEL_NAME = "Music Genre classification_NIST"
device = 0 if torch.cuda.is_available() else "cpu"
pipe = pipeline(
task="audio-classification",
model=MODEL_NAME,
device=device,
)
def classify_audio(filepath):
preds = pipe(filepath, top_k = 10)
outputs = {}
for p in preds:
outputs[p["label"]] = p["score"]
return outputs
demo = gr.Interface(
fn=classify_audio,
inputs= gr.Audio(label="Audio file", type="filepath"),
outputs=gr.Label(),
title="Music Genre Classification",
description=(
"Project by-Asutosh Panda and Bismaytosh Malik."
),
examples="./examples",
cache_examples=True,
allow_flagging="never",
)
share=True in launch()
demo.launch()