File size: 1,033 Bytes
e01dd76
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from transformers import pipeline
import gradio as gr

model_id = "Ihssane123/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.Interface(
    fn=classify_audio, inputs=gr.Audio(type="filepath"), outputs=gr.Label()
)
demo = gr.Interface(
    fn=classify_audio, 
    inputs=gr.Audio(type="filepath"), 
    outputs=gr.Label(),
    title="Music Genre Classifier",
    description="""<div style="text-align: center; margin-bottom: 10px">
        <p style="font-size: 16px; color: #555; font-style: italic;">
            This demo is based on the <span style="color: #007bff; font-weight: bold;"><a href="https://huggingface.co/learn/audio-course/en/chapter4/demo">Hugging Face audio course Unit 4</a></span>, 
            demonstrating a music genre classifier built with Gradio.
        </p>
    </div>"""
)
demo.launch(debug=True)