aditya0701's picture
added a not a bear option
da95f53
# AUTOGENERATED! DO NOT EDIT! File to edit: Bear_gradio_app.ipynb.
# %% auto 0
__all__ = ['plt', 'path', 'learn', 'image', 'label', 'examples', 'intf', 'is_Bear', 'show_predict']
# %% Bear_gradio_app.ipynb 1
from fastai.vision.all import *
import gradio as gr
import platform
def is_Bear(x): return x[0].isupper()
# %% Bear_gradio_app.ipynb 2
import pathlib
plt = platform.system()
if plt != 'Windows':
pathlib.WindowsPath = pathlib.PosixPath
path = Path('images_to_test/')
# %% Bear_gradio_app.ipynb 4
learn = load_learner('model.pkl')
# %% Bear_gradio_app.ipynb 6
def show_predict(img):
l = learn.predict(img)
if l[0] == ['a','d','n','p']:
res = 'Panda bear'
elif l[0] == ['g','i','l','r','y','z']:
res = 'Grizzly Bear'
elif l[0] == ['d','e','t','y']:
res = 'Teddy Bear'
elif l[0] == ['a','l','o','p','r']:
res = 'Polar Bear'
elif l[0] == ['a','b','c','k','l']:
res = 'Black Bear'
else:
res = "Not a Bear"
return res
# %% Bear_gradio_app.ipynb 8
image = gr.Image(shape=(192,192))
label = gr.Label()
examples = [path/'polar1.jpg', path/'griz.jpg',path/'donno.jpg',path/'black.jpg',path/'panda1.jpg',path/'images.jpg',path/'polar2.jpg',path/'many_mug.jpg']
intf = gr.Interface(fn=show_predict, inputs=image, outputs=label, examples=examples,
title = "Bear Classifier Using Multilabel Classification")
intf.launch(inline = False)