Spaces:
Runtime error
Runtime error
artyomboyko
commited on
Commit
•
0f36b7e
1
Parent(s):
a97c279
Add application file
Browse files
app.py
ADDED
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import pipeline
|
2 |
+
import gradio as gr
|
3 |
+
|
4 |
+
model_id = "artyomboyko/distilhubert-finetuned-gtzan"
|
5 |
+
pipe = pipeline("audio-classification", model=model_id)
|
6 |
+
|
7 |
+
def classify_audio(filepath):
|
8 |
+
preds = pipe(filepath)
|
9 |
+
outputs = {}
|
10 |
+
for p in preds:
|
11 |
+
outputs[p["label"]] = p["score"]
|
12 |
+
return outputs
|
13 |
+
|
14 |
+
|
15 |
+
demo = gr.Blocks()
|
16 |
+
|
17 |
+
title = "Classification of music"
|
18 |
+
description = """
|
19 |
+
This demo is designed to test the music classification. It is important to remember that music classification depends very much on the quality of the recording, for example, when classifying a recording from a
|
20 |
+
microphone with poor high frequencies, the song "Evanescence - bring me to life" may not be correctly defined as classical music. But if we transfer a recording of the same song as a file, it is correctly
|
21 |
+
identified as metal music. In addition, a real problem is caused by compositions in which there is a mixture of different styles of music, or modern styles of examples of which were not in the training dataset.
|
22 |
+
"""
|
23 |
+
|
24 |
+
mic_classify_audio = gr.Interface(
|
25 |
+
fn=classify_audio,
|
26 |
+
inputs=gr.Audio(source="microphone", type="filepath"),
|
27 |
+
outputs=gr.outputs.Label(),
|
28 |
+
title=title,
|
29 |
+
description=description,
|
30 |
+
)
|
31 |
+
|
32 |
+
file_classify_audio = gr.Interface(
|
33 |
+
fn=classify_audio,
|
34 |
+
inputs=gr.Audio(source="upload", type="filepath"),
|
35 |
+
outputs=gr.outputs.Label(),
|
36 |
+
#examples=[["./example.wav"]],
|
37 |
+
title=title,
|
38 |
+
description=description,
|
39 |
+
)
|
40 |
+
|
41 |
+
with demo:
|
42 |
+
gr.TabbedInterface([mic_classify_audio, file_classify_audio], ["Microphone", "Audio File"])
|
43 |
+
|
44 |
+
demo.launch(debug=True)
|