# AUTOGENERATED! DO NOT EDIT! File to edit: ../app.ipynb. # %% auto 0 __all__ = ['EXPORT_PATH', 'categories', 'inp_img', 'labels', 'example_img', 'intf', 'set_posix_windows', 'classify_images'] # %% ../app.ipynb 3 import fastai from fastai.vision.all import * import gradio as gr # %% ../app.ipynb 5 from contextlib import contextmanager import pathlib '''@contextmanager def set_posix_windows(): posix_backup = pathlib.PosixPath try: pathlib.PosixPath = pathlib.WindowsPath yield finally: pathlib.PosixPath = posix_backup # %% ../app.ipynb 6 #Exporting our model file: EXPORT_PATH = pathlib.Path('model.pkl') with set_posix_windows(): learn = load_learner(EXPORT_PATH)''' learn = load_learner('model.pkl') # %% ../app.ipynb 9 '''categories = ('EASTERN TOWEE', 'RING-BILLED GULL', 'LILAC ROLLER', 'CACTUS WREN', 'MALACHITE KINGFISHER', 'EURASIAN MAGPIE', 'TRUMPTER SWAN', 'HOODED MERGANSER', 'RAZORBILL', 'TREE SWALLOW', 'MOURNING DOVE', 'TURKEY VULTURE', 'PEREGRINE FALCON', 'BAR-TAILED GODWIT', 'BLACK SWAN', 'BALTIMORE ORIOLE', 'BLUE HERON', 'MIKADO PHEASANT', 'WHITE CHEEKED TURACO', 'GOLDEN CHLOROPHONIA')''' categories = learn.dls.vocab print(categories) def classify_images(image): pred, idx, probs = learn.predict(image) return dict(zip(categories, map(float, probs))) # %% ../app.ipynb 11 # Building the gradio application interface: inp_img = gr.inputs.Image(shape=(192, 192)) labels = gr.outputs.Label() example_img = [ 'baltimore_oriole.jpg', 'bar_tailed_godwit.jpg', 'black_swan.jpg', 'blue_heron.jpg', 'cactus_wren.jpg', 'eastern_towee.jpg', 'golden_chlorophonia.jpg', 'lilac_roller.jpg', 'malachite_kingfisher.jpg', 'mikado_pheasant.jpg', 'mourning_dove.jpg', 'peregine_falcon.jpg', 'razorbill.jpg', 'ring_billed_gull.jpg', 'tree_swallow.jpg', 'trumpter_swan.jpg', 'white_cheeked_turaco.jpg'] intf = gr.Interface(fn=classify_images, inputs=inp_img, outputs=labels, examples=example_img) intf.launch(inline=False)