File size: 734 Bytes
47ca64f
 
 
fc30322
47ca64f
fc30322
 
 
 
47ca64f
 
 
 
 
 
 
 
 
6bcb501
47ca64f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import gradio as gr
from fastai.vision.all import *

# returns dict of predictions and their probabilities sorted
def classify_img(img):
    instrument,index,probs = learn.predict(PILImage.create(img))    
    sorted_probs = sorted(zip(learn.dls.vocab, map(float,probs)), key=lambda x: x[1], reverse=True)
    return dict(sorted_probs)
    
#paths
mdl = 'minst.pk1'
samples = 'examples/'

# load pre-trained model 
learn = load_learner(mdl)

examples = [f'{samples}acoustic guitar.jpg', f'{samples}drums.jpg', f'{samples}electric guitar.jpg', f'{samples}keyboard.jpg']

demo = gr.Interface(fn=classify_img, inputs=gr.Image(width=224,height=224), outputs="label", examples=examples, title="Musical Instrument Classifier")
demo.launch()