lewtun HF staff commited on
Commit
80600ce
1 Parent(s): bab3d26

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -0
app.py ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import librosa
3
+ from transformers import pipeline
4
+
5
+ pipe = pipeline("audio-classification", model="lewtun/distilhubert-finetuned-gtzan-og")
6
+
7
+
8
+ def classify_audio(filepath):
9
+ audio, sampling_rate = librosa.load(filepath, sr=16_000)
10
+ preds = pipe(audio)
11
+ outputs = {}
12
+ for p in preds:
13
+ outputs[p["label"]] = p["score"]
14
+ return outputs
15
+
16
+
17
+ label = gr.outputs.Label()
18
+
19
+ demo = gr.Interface(fn=classify_audio, inputs=gr.Audio(type="filepath"), outputs=label)
20
+ demo.launch()