jpbello commited on
Commit
9d9118e
1 Parent(s): 8aab983
Files changed (7) hide show
  1. .gitattributes +1 -0
  2. app.py +51 -0
  3. cut_hk.mp3 +3 -0
  4. cut_hm.mp3 +3 -0
  5. cut_mc.mp3 +3 -0
  6. cut_rdr.mp3 +3 -0
  7. requirements.txt +3 -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
+ *.mp3 filter=lfs diff=lfs merge=lfs -text
app.py ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import torch
3
+ from transformers import pipeline
4
+
5
+ username = "jpbello" ## 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
+ # def predict_trunc(filepath):
11
+ # preprocessed = pipe.preprocess(filepath)
12
+ # truncated = pipe.feature_extractor.pad(preprocessed,truncation=True, max_length = 16_000*30)
13
+ # model_outputs = pipe.forward(truncated)
14
+ # outputs = pipe.postprocess(model_outputs)
15
+
16
+ # return outputs
17
+
18
+
19
+ def classify_audio(filepath):
20
+ """
21
+ Goes from
22
+ [{'score': 0.8339303731918335, 'label': 'country'},
23
+ {'score': 0.11914275586605072, 'label': 'rock'},]
24
+ to
25
+ {"country": 0.8339303731918335, "rock":0.11914275586605072}
26
+ """
27
+ preds = pipe(filepath)
28
+ # preds = predict_trunc(filepath)
29
+ outputs = {}
30
+ for p in preds:
31
+ outputs[p["label"]] = p["score"]
32
+ return outputs
33
+
34
+
35
+ title = "🎵 Music Genre Classifier"
36
+ description = """
37
+ demo to showcase the music
38
+ classification model that we just trained on the [GTZAN](https://huggingface.co/datasets/marsyas/gtzan)
39
+ """
40
+
41
+ filenames = ['blues.00098.wav', "disco.00020.wav", "metal.00014.wav", "reggae.00021.wav", "rock.00058.wav"]
42
+ filenames = [[f"./{f}"] for f in filenames]
43
+ demo = gr.Interface(
44
+ fn=classify_audio,
45
+ inputs=gr.Audio(type="filepath"),
46
+ outputs=gr.outputs.Label(),
47
+ title=title,
48
+ description=description,
49
+ examples=filenames,
50
+ )
51
+ demo.launch()
cut_hk.mp3 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d861c40d1cae2ddca0c905915ce03ce6362574600519452918bd9e0ddc524b13
3
+ size 1052822
cut_hm.mp3 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:bd1de98dea2179f42bb8e96ceb5e59fd64e30173f09f37395a1f48b032c4b4e9
3
+ size 957983
cut_mc.mp3 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:250461b4aa61cf6d7ca1d671d4f98825dc9e2a6d615fd85a5291d9f9172698d3
3
+ size 624539
cut_rdr.mp3 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:369799ca9accded654d1c3d1c378a811f86555451da3b4199b7a5d0abf70c5bf
3
+ size 1063311
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ gradio==3.44.3
2
+ torch==2.0.1
3
+ transformers==4.33.2