helvekami commited on
Commit
81bde2d
·
1 Parent(s): b4d0945

Upload 14 files

Browse files
app.ipynb ADDED
The diff for this file is too large to render. See raw diff
 
app.py CHANGED
@@ -1,7 +1,35 @@
1
- import gradio as gr
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
5
 
6
- iface = gr.Interface(fn=greet, inputs="text", outputs="text")
7
- iface.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # AUTOGENERATED! DO NOT EDIT! File to edit: app.ipynb.
2
 
3
+ # %% auto 0
4
+ __all__ = ['learn', 'categories', 'aud', 'examples', 'intf', 'log_mel_spec_tfm', 'classify_aud']
5
 
6
+ # %% app.ipynb 1
7
+ def log_mel_spec_tfm(fname, src_path, dst_path):
8
+ os.makedirs(str(dst_path), exist_ok = True)
9
+ y, sr = librosa.load(str(src_path/fname), mono=True)
10
+ D = librosa.amplitude_to_db(np.abs(librosa.stft(y)), ref=np.max)
11
+ img = librosa.display.specshow(D, y_axis='linear', x_axis='time',
12
+ sr=sr)
13
+ plt.savefig(str(dst_path/fname[:-4]) + '.png')
14
+ plt.close()
15
+ return img
16
+
17
+ # %% app.ipynb 2
18
+ learn = load_learner('model.pkl')
19
+ learn.remove_cb(ProgressCallback)
20
+
21
+ # %% app.ipynb 6
22
+ categories = ('Brass', 'Flute', 'Guitar', 'Keyboard', 'Mallet', 'Reed', 'String', 'Vocal')
23
+
24
+ def classify_aud(aud):
25
+ log_mel_spec_tfm(aud, Path('.'), Path('.'))
26
+ img_fname = str(aud[:-4]) + '.png'
27
+ pred, idx, probs = learn.predict(img_fname)
28
+ return dict(zip(categories, map(float, probs)))
29
+
30
+ # %% app.ipynb 8
31
+ aud = gr.Audio(source="upload", type="numpy")
32
+ examples = ['test/' + str(f.name) for f in Path('test').iterdir()]
33
+
34
+ intf = gr.Interface(fn = classify_aud, inputs = aud, outputs = "label", examples = examples)
35
+ intf.launch(inline = False)
brass_acoustic_006-065-127.wav ADDED
Binary file (128 kB). View file
 
flute_acoustic_002-087-127.wav ADDED
Binary file (128 kB). View file
 
guitar_acoustic_021-034-127.wav ADDED
Binary file (128 kB). View file
 
keyboard_acoustic_004-033-075.wav ADDED
Binary file (128 kB). View file
 
mallet_acoustic_062-090-100.wav ADDED
Binary file (128 kB). View file
 
model.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7c5d19de8a83fe566fad633416e35cfecd410f2372f19b940d678f0942715f33
3
+ size 46992273
nsynth_instrument_classifier.ipynb ADDED
The diff for this file is too large to render. See raw diff
 
reed_acoustic_011-064-075.wav ADDED
Binary file (128 kB). View file
 
requirements.txt ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ fastbook
2
+ fastai
3
+ librosa
4
+ matplotlib
5
+ numpy
6
+ functools
7
+ pathlib
8
+ multiprocessing
9
+ os
10
+ scipy
11
+ gradio
string_acoustic_014-046-050.wav ADDED
Binary file (128 kB). View file
 
vocal_acoustic_000-059-127.wav ADDED
Binary file (128 kB). View file