pksx01 commited on
Commit
e78c067
·
1 Parent(s): 99eba70

Updated with wandb settings

Browse files
Files changed (1) hide show
  1. app.py +16 -3
app.py CHANGED
@@ -2,9 +2,14 @@ from fastai.vision.all import *
2
  import librosa
3
  import gradio as gr
4
  import numpy as np
 
 
 
 
 
5
 
6
  learn = load_learner('audio_mnist_classifier_v1.pkl')
7
- categories = ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9')
8
 
9
  def mel_spectrogram_tfm(file):
10
  y, sr = librosa.load(file)
@@ -15,8 +20,16 @@ def mel_spectrogram_tfm(file):
15
 
16
  def classify(audio):
17
  spec_db = mel_spectrogram_tfm(audio)
18
- img = PILImage.create(spec_db).resize((225,225))
19
  pred, idx, prob = learn.predict(img)
20
  return dict(zip(categories, map(float, prob)))
21
 
22
- gr.Interface(fn=classify, inputs=gr.Audio(source="microphone", type="filepath"), outputs="text", title="Identify digits between 0 and 9 from audio clips").launch()
 
 
 
 
 
 
 
 
 
2
  import librosa
3
  import gradio as gr
4
  import numpy as np
5
+ import wandb
6
+ from fastai.callback.wandb import *
7
+
8
+ os.environ["WANDB_API_KEY"] = WANDB_API_KEY
9
+ wandb.init()
10
 
11
  learn = load_learner('audio_mnist_classifier_v1.pkl')
12
+ categories = learn.dls.vocab
13
 
14
  def mel_spectrogram_tfm(file):
15
  y, sr = librosa.load(file)
 
20
 
21
  def classify(audio):
22
  spec_db = mel_spectrogram_tfm(audio)
23
+ img = PILImage.create(spec_db)
24
  pred, idx, prob = learn.predict(img)
25
  return dict(zip(categories, map(float, prob)))
26
 
27
+ interface = gr.Interface(fn=classify,
28
+ inputs=gr.Audio(source="microphone", type="filepath"),
29
+ outputs=gr.outputs.Label(num_top_classes=10),
30
+ title='Audio MNIST Classification',
31
+ description='Identifying digits (from 0 to 9) from an audio clip')
32
+
33
+ interface.launch()
34
+
35
+ interface.integrate(wandb=wandb)