Spaces:
Sleeping
Sleeping
Commit
·
e01dd76
1
Parent(s):
7f4b545
adding the app file
Browse files
app.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import pipeline
|
| 2 |
+
import gradio as gr
|
| 3 |
+
|
| 4 |
+
model_id = "Ihssane123/distilhubert-finetuned-gtzan"
|
| 5 |
+
pipe = pipeline("audio-classification", model=model_id)
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
def classify_audio(filepath):
|
| 9 |
+
preds = pipe(filepath)
|
| 10 |
+
outputs = {}
|
| 11 |
+
for p in preds:
|
| 12 |
+
outputs[p["label"]] = p["score"]
|
| 13 |
+
return outputs
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
demo = gr.Interface(
|
| 18 |
+
fn=classify_audio, inputs=gr.Audio(type="filepath"), outputs=gr.Label()
|
| 19 |
+
)
|
| 20 |
+
demo = gr.Interface(
|
| 21 |
+
fn=classify_audio,
|
| 22 |
+
inputs=gr.Audio(type="filepath"),
|
| 23 |
+
outputs=gr.Label(),
|
| 24 |
+
title="Music Genre Classifier",
|
| 25 |
+
description="""<div style="text-align: center; margin-bottom: 10px">
|
| 26 |
+
<p style="font-size: 16px; color: #555; font-style: italic;">
|
| 27 |
+
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>,
|
| 28 |
+
demonstrating a music genre classifier built with Gradio.
|
| 29 |
+
</p>
|
| 30 |
+
</div>"""
|
| 31 |
+
)
|
| 32 |
+
demo.launch(debug=True)
|