juangtzi
commited on
Commit
·
9de4d3c
1
Parent(s):
30f15e2
Add application file
Browse files- .gitattributes +1 -0
- app.py +42 -0
- example/example1.mp3 +3 -0
- example/example2.mp3 +3 -0
- example/example3.mp3 +3 -0
- example/example4.mp3 +3 -0
- requirements.txt +3 -0
.gitattributes
CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
36 |
+
example/* filter=lfs diff=lfs merge=lfs -text
|
app.py
ADDED
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import pipeline
|
2 |
+
import gradio as gr
|
3 |
+
|
4 |
+
pipe = pipeline(
|
5 |
+
"audio-classification", model="juangtzi/wav2vec2-base-finetuned-gtzan"
|
6 |
+
)
|
7 |
+
|
8 |
+
def classify_audio(filepath):
|
9 |
+
import time
|
10 |
+
start_time = time.time()
|
11 |
+
|
12 |
+
preds = pipe(filepath)
|
13 |
+
outputs = {}
|
14 |
+
for p in preds:
|
15 |
+
outputs[p["label"]] = p["score"]
|
16 |
+
|
17 |
+
end_time = time.time()
|
18 |
+
prediction_time = end_time - start_time
|
19 |
+
|
20 |
+
|
21 |
+
return outputs, prediction_time
|
22 |
+
|
23 |
+
|
24 |
+
title = "🎵 Music Genre Classifier"
|
25 |
+
description = """
|
26 |
+
Music Genre Classifier model (Fine-tuned "facebook/wav2vec2-base") Dataset: [GTZAN](https://huggingface.co/datasets/marsyas/gtzan)
|
27 |
+
"""
|
28 |
+
|
29 |
+
|
30 |
+
demo = gr.Interface(
|
31 |
+
fn=classify_audio,
|
32 |
+
inputs=gr.Audio(type="filepath"),
|
33 |
+
outputs=[gr.Label(), gr.Number(label="Prediction time (s)")],
|
34 |
+
title=title,
|
35 |
+
description=description,
|
36 |
+
examples="./example",
|
37 |
+
#cache_examples=True,
|
38 |
+
allow_flagging="never",
|
39 |
+
)
|
40 |
+
demo.queue()
|
41 |
+
|
42 |
+
demo.launch(share=True)
|
example/example1.mp3
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:a57f4a9a027afbc54e125bf2863c171163ece3db93fa2fc43b03c600d71ff837
|
3 |
+
size 7356790
|
example/example2.mp3
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:3bfdd222236b7e8f9013f72020f97327a22aea59a0a7884a4b33955e9840fdad
|
3 |
+
size 7778915
|
example/example3.mp3
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:5210e00887f2ae22633af46b3b33c1d298f4b35075822319560d45287ed821ef
|
3 |
+
size 6798835
|
example/example4.mp3
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:374c3611af7a0de29d10a71f86c26feb1f18f4d4dab1bf62632184bdfc0dc148
|
3 |
+
size 6645205
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
transformers
|
2 |
+
gradio
|
3 |
+
torch
|