File size: 519 Bytes
97598cb
 
 
 
 
 
 
 
 
 
 
 
 
b178faa
 
 
 
 
97598cb
b178faa
97598cb
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
from transformers import pipeline
import gradio as gr

model_id = "terps/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

examples = [
    ["blues.mp3"],
    ["hiphop.mp3"],
]

demo = gr.Interface(
    fn=classify_audio, inputs=gr.Audio(type="filepath"), outputs=gr.outputs.Label(), examples=examples
)
demo.launch(debug=True)