allispaul commited on
Commit
df7a6c1
·
1 Parent(s): 50b385c

Add local files for interface

Browse files
.gitattributes CHANGED
@@ -10,10 +10,12 @@
10
  *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
  *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
  *.model filter=lfs diff=lfs merge=lfs -text
 
13
  *.msgpack filter=lfs diff=lfs merge=lfs -text
14
  *.npy filter=lfs diff=lfs merge=lfs -text
15
  *.npz filter=lfs diff=lfs merge=lfs -text
16
  *.onnx filter=lfs diff=lfs merge=lfs -text
 
17
  *.ot filter=lfs diff=lfs merge=lfs -text
18
  *.parquet filter=lfs diff=lfs merge=lfs -text
19
  *.pb filter=lfs diff=lfs merge=lfs -text
@@ -29,6 +31,7 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
29
  *.tflite filter=lfs diff=lfs merge=lfs -text
30
  *.tgz filter=lfs diff=lfs merge=lfs -text
31
  *.wasm filter=lfs diff=lfs merge=lfs -text
 
32
  *.xz 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
 
10
  *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
  *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
  *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.mp3 filter=lfs diff=lfs, merge=lfs -text
14
  *.msgpack filter=lfs diff=lfs merge=lfs -text
15
  *.npy filter=lfs diff=lfs merge=lfs -text
16
  *.npz filter=lfs diff=lfs merge=lfs -text
17
  *.onnx filter=lfs diff=lfs merge=lfs -text
18
+ *.opus filter=lfs diff=lfs, merge=lfs -text
19
  *.ot filter=lfs diff=lfs merge=lfs -text
20
  *.parquet filter=lfs diff=lfs merge=lfs -text
21
  *.pb filter=lfs diff=lfs merge=lfs -text
 
31
  *.tflite filter=lfs diff=lfs merge=lfs -text
32
  *.tgz filter=lfs diff=lfs merge=lfs -text
33
  *.wasm filter=lfs diff=lfs merge=lfs -text
34
+ *.wav filter=lfs diff=lfs, merge=lfs -text
35
  *.xz filter=lfs diff=lfs merge=lfs -text
36
  *.zip filter=lfs diff=lfs merge=lfs -text
37
  *.zst filter=lfs diff=lfs merge=lfs -text
README.md CHANGED
@@ -1,6 +1,6 @@
1
  ---
2
  title: Audiobot
3
- emoji: 📉
4
  colorFrom: blue
5
  colorTo: yellow
6
  sdk: gradio
 
1
  ---
2
  title: Audiobot
3
+ emoji: 🎵
4
  colorFrom: blue
5
  colorTo: yellow
6
  sdk: gradio
app.py ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from pathlib import Path
2
+
3
+ import gradio as gr
4
+ import librosa
5
+ from transformers import (AutoFeatureExtractor,
6
+ AutoModelForAudioClassification, pipeline)
7
+
8
+ feature_extractor = AutoFeatureExtractor.from_pretrained(
9
+ "sanchit-gandhi/whisper-medium-fleurs-lang-id",
10
+ do_normalize=True
11
+ )
12
+ SR = 16_000
13
+
14
+ label2id = {
15
+ 'blues': '0',
16
+ 'classical': '1',
17
+ 'country': '2',
18
+ 'disco': '3',
19
+ 'hiphop': '4',
20
+ 'jazz': '5',
21
+ 'metal': '6',
22
+ 'pop': '7',
23
+ 'reggae': '8',
24
+ 'rock': '9'
25
+ }
26
+ num_labels = len(label2id)
27
+
28
+ path = "best_Whisper-Small_model_92"
29
+ model = AutoModelForAudioClassification.from_pretrained("allispaul/whisper-small-gtzan")
30
+ classifier = pipeline("audio-classification", model=model, feature_extractor=feature_extractor)
31
+
32
+ def predict(audio):
33
+ if isinstance(audio, str) or isinstance(audio, Path):
34
+ audio, sr = librosa.load(audio, sr=16_000)
35
+ else:
36
+ sr, audio = audio
37
+ preds = classifier({"array": audio, "sampling_rate": sr})
38
+ probs = {k: 0.0 for k in label2id}
39
+ for pred in preds:
40
+ probs[pred["label"]] = pred["score"]
41
+ return probs
42
+
43
+ title = "🤖 🎵 Audiobot 🎹 ⚡"
44
+ description = "<h2>♯ The superpowered music genre classifier ♭</h2>"
45
+ article = """
46
+ <p>🤖 This model is a version of <a href="https://huggingface.co/openai/whisper-medium">Whisper Medium</a>,
47
+ fine-tuned on the <a href="https://huggingface.co/datasets/marsyas/gtzan">GTZAN</a> dataset.</p>
48
+ <p>🎹 It recognizes 10 genres: blues, classical, country, hip-hop, jazz, metal, pop, reggae, and rock.</p>
49
+ <p>🎵 Upload a song or click one of the examples to try it out!</p>
50
+ <p>⚡ Part of a project for the <a href="https://www.erdosinstitute.org/">Erdős Institute</a> Deep Learning bootcamp,
51
+ by Dylan Bates, Muhammed Cifci, Aycan Katitas, Johann Thiel, Soheyl Anbouhi, and Paul VanKoughnett.</p>
52
+ """
53
+ iface = gr.Interface(
54
+ fn=predict,
55
+ inputs=gr.Audio(type="filepath"),
56
+ outputs=gr.Label(num_top_classes=3),
57
+ title=title,
58
+ description=description,
59
+ article=article,
60
+ examples=["examples/country.00008.wav", "examples/hiphop.00057.wav", "examples/gamblersblues.opus"]
61
+ )
62
+ iface.launch()
examples/country.00008.wav ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:dbfd35f47e913737b62baab8dc75d4e362be1e2b1a63533b1850ff1746652a7d
3
+ size 1327524
examples/gamblersblues.opus ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7dc17b447eeb37cb5d4aaa3c2014d58a9f8434d057ee8c62789cdb0ac23672cf
3
+ size 2260647
examples/hiphop.00057.wav ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1152e98c15f222c972f4f6426fa53586775097c6e599c4165c7faf3d20c0db60
3
+ size 1323632