David GG commited on
Commit
1917f1f
1 Parent(s): ec1bc82
Files changed (3) hide show
  1. .gitattributes +1 -0
  2. app.py +45 -0
  3. requirements.txt +2 -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
+ *.wav filter=lfs diff=lfs merge=lfs -text
app.py ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import torch
3
+ from transformers import pipeline
4
+
5
+ username = "davidggphy" ## Complete your username
6
+ model_id = f"{username}/distilhubert-finetuned-gtzan"
7
+ device = "cuda:0" if torch.cuda.is_available() else "cpu"
8
+ pipe = pipeline("audio-classification", model=model_id, device=device)
9
+
10
+
11
+ def classify_audio(filepath):
12
+ """
13
+ Goes from
14
+ [{'score': 0.8339303731918335, 'label': 'country'},
15
+ {'score': 0.11914275586605072, 'label': 'rock'},]
16
+
17
+ to
18
+ {"country": 0.8339303731918335, "rock":0.11914275586605072}
19
+ """
20
+ preds = pipe(filepath)
21
+ outputs = {}
22
+ for p in preds:
23
+ outputs[p["label"]] = p["score"]
24
+ return outputs
25
+
26
+
27
+ title = "🎵 Music Genre Classifier"
28
+ description = """
29
+ demo to showcase the music
30
+ classification model that we just trained on the [GTZAN](https://huggingface.co/datasets/marsyas/gtzan)
31
+ """
32
+
33
+ filenames = ['blues.00098.wav', "disco.00020.wav", "metal.00014.wav", "reggae.00021.wav", "rock.00058.wav"]
34
+ filenames = [[f"./{f}"] for f in filenames]
35
+ demo = gr.Interface(
36
+ fn=classify_audio,
37
+ inputs=gr.Audio(type="filepath"),
38
+ outputs=gr.outputs.Label(),
39
+ title=title,
40
+ description=description,
41
+ examples=filenames,
42
+ )
43
+ demo.launch()
44
+
45
+
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ torch
2
+ git+https://github.com/huggingface/transformers