File size: 855 Bytes
42a4f0a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
from fastai.vision.all import *
import gradio as gr

learn = load_learner('export.pkl')
labels = learn.dls.vocab

def predict(img):
    img = PILImage.create(img)
    preds,preds_idx,probs = learn.predict(img)
    return {labels[i]: float(probs[i]) for i in range(len(labels))}

title = 'Horse vs Donkey Classifier'
description = 'A Horse versus Donkey classifier trained on using DuckDuckGo search engine. Created a demo as part of fastai course'

examples = [Path('examples')/'donkey.jpg', Path('examples')/'horse.jpg', Path('examples')/'animated_horse.jpg', Path('examples')/'animated_donkey.jpg', Path('examples')/'hybrid.jpg']

iface = gr.Interface(fn=predict, inputs=gr.inputs.Image(type='pil', shape=(224, 224)), title=title, description=description, outputs=gr.outputs.Label(num_top_classes=2), examples=examples, enable_queue=True)
iface.launch()