|
|
|
|
|
|
|
__all__ = ['plt', 'path', 'learn', 'image', 'label', 'examples', 'intf', 'is_Bear', 'show_predict'] |
|
|
|
|
|
from fastai.vision.all import * |
|
import gradio as gr |
|
import platform |
|
|
|
def is_Bear(x): return x[0].isupper() |
|
|
|
|
|
import pathlib |
|
plt = platform.system() |
|
if plt != 'Windows': |
|
pathlib.WindowsPath = pathlib.PosixPath |
|
path = Path('images_to_test/') |
|
|
|
|
|
learn = load_learner('model.pkl') |
|
|
|
|
|
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 |
|
|
|
|
|
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) |
|
|