MUSIC_MAJOR / app.py
JackismyShephard's picture
fix spelling error and remove redundant argument
22f7a69
raw
history blame
987 Bytes
import torch
from transformers import pipeline
import gradio as gr
MODEL_NAME = "JackismyShephard/whisper-medium.en-finetuned-gtzan"
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=(
"Classify long-form audio or microphone inputs with the click of a button! Demo uses the"
f" checkpoint [{MODEL_NAME}](https://huggingface.co/{MODEL_NAME}) and 🤗 Transformers to classify audio files"
" of arbitrary length."
),
examples="./examples",
cache_examples=True,
allow_flagging="never",
)
demo.launch()