HarshitJoshi commited on
Commit
60ca5bc
·
1 Parent(s): 299594b

1st Commit

Browse files
app.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from transformers import pipeline
3
+ import gradio as gr
4
+
5
+ MODEL_NAME = "HarshitJoshi/distilhubert-finetuned-gtzan"
6
+
7
+ device = 0 if torch.cuda.is_available() else "cpu"
8
+
9
+ pipe = pipeline(
10
+ task="audio-classification",
11
+ model=MODEL_NAME,
12
+ device=device,
13
+ )
14
+
15
+ def classify_audio(filepath):
16
+ preds = pipe(filepath, top_k = 10)
17
+ outputs = {}
18
+ for p in preds:
19
+ outputs[p["label"]] = p["score"]
20
+ return outputs
21
+
22
+ demo = gr.Interface(
23
+ fn=classify_audio,
24
+ inputs= gr.Audio(label="Audio file", type="filepath"),
25
+ outputs=gr.Label(),
26
+ title="MusicGenreClassif",
27
+ description=(
28
+ ""
29
+ ),
30
+ examples="./examples",
31
+ cache_examples=True,
32
+ allow_flagging="never",
33
+ )
34
+
35
+ demo.launch()
examples/examples_song1.ogg ADDED
Binary file (341 kB). View file
 
examples/examples_song2.ogg ADDED
Binary file (408 kB). View file
 
examples/examples_song3.ogg ADDED
Binary file (384 kB). View file
 
examples/examples_song4.ogg ADDED
Binary file (396 kB). View file
 
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ torch
2
+ transformers
3
+ gradio