Spaces:
Runtime error
Runtime error
Ant
commited on
Commit
•
d1f1420
1
Parent(s):
ec03e8a
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import pipeline
|
2 |
+
|
3 |
+
username = "afern24" ## Complete your username
|
4 |
+
model_id = f"{username}/distilhubert-finetuned-gtzan"
|
5 |
+
pipe = pipeline("audio-classification", model=model_id)
|
6 |
+
|
7 |
+
def classify_audio(filepath):
|
8 |
+
"""
|
9 |
+
Goes from
|
10 |
+
[{'score': 0.8339303731918335, 'label': 'country'},
|
11 |
+
{'score': 0.11914275586605072, 'label': 'rock'},]
|
12 |
+
|
13 |
+
to
|
14 |
+
{"country": 0.8339303731918335, "rock":0.11914275586605072}
|
15 |
+
"""
|
16 |
+
preds = pipe(filepath)
|
17 |
+
outputs = {}
|
18 |
+
for p in preds:
|
19 |
+
outputs[p["label"]] = p["score"]
|
20 |
+
return outputs
|
21 |
+
|
22 |
+
import gradio as gr
|
23 |
+
|
24 |
+
demo = gr.Interface(
|
25 |
+
fn=classify_audio, inputs=gr.Audio(type="filepath"), outputs=gr.outputs.Label()
|
26 |
+
)
|
27 |
+
demo.launch(debug=True)
|