bvallegc commited on
Commit
d810b2a
·
1 Parent(s): 6c60380

upload app.py

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