Spaces:
Runtime error
Runtime error
mahimairaja
commited on
Commit
•
6c7b6ff
1
Parent(s):
f2d702e
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""Awesome UI for the Music Genre Classifier"""
|
2 |
+
import gradio as gr
|
3 |
+
|
4 |
+
from transformers import pipeline
|
5 |
+
|
6 |
+
classifier = pipeline(
|
7 |
+
"audio-classification",
|
8 |
+
model="mahimairaja/distilhubert-music-classifier-finetuned-gtzan",
|
9 |
+
)
|
10 |
+
|
11 |
+
|
12 |
+
def classifiy_music(audio):
|
13 |
+
"""
|
14 |
+
Outputs the label for the given audio
|
15 |
+
"""
|
16 |
+
label = classifier(audio)
|
17 |
+
outputs = {}
|
18 |
+
for pred_value in label:
|
19 |
+
outputs[pred_value["label"]] = pred_value["score"]
|
20 |
+
return outputs
|
21 |
+
|
22 |
+
|
23 |
+
TITLE = "Music Genre Classifier"
|
24 |
+
|
25 |
+
demo = gr.Blocks()
|
26 |
+
|
27 |
+
mic_translate = gr.Interface(
|
28 |
+
fn=classifiy_music,
|
29 |
+
inputs=gr.Audio(source="microphone", type="filepath"),
|
30 |
+
outputs=gr.outputs.Label(),
|
31 |
+
title=TITLE,
|
32 |
+
)
|
33 |
+
|
34 |
+
file_translate = gr.Interface(
|
35 |
+
fn=classifiy_music,
|
36 |
+
inputs=gr.Audio(source="upload", type="filepath"),
|
37 |
+
outputs=gr.outputs.Label(),
|
38 |
+
examples=[
|
39 |
+
"assets/song_01.wav",
|
40 |
+
"assets/song_02.wav",
|
41 |
+
"assets/song_03.wav",
|
42 |
+
"assets/song_04.wav",
|
43 |
+
],
|
44 |
+
title=TITLE,
|
45 |
+
)
|
46 |
+
|
47 |
+
with demo:
|
48 |
+
gr.TabbedInterface(
|
49 |
+
[mic_translate, file_translate],
|
50 |
+
["Microphone", "Audio File"]
|
51 |
+
)
|
52 |
+
|
53 |
+
demo.launch()
|