Spaces:
Runtime error
Runtime error
Updated with wandb settings
Browse files
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 =
|
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)
|
19 |
pred, idx, prob = learn.predict(img)
|
20 |
return dict(zip(categories, map(float, prob)))
|
21 |
|
22 |
-
gr.Interface(fn=classify,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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)
|