imageclassify / app.py
kolappan's picture
updated
f1a7c66 verified
raw
history blame contribute delete
963 Bytes
# AUTOGENERATED! DO NOT EDIT! File to edit: testing.ipynb.
# %% auto 0
__all__ = ['learn', 'categories', 'image', 'label', 'examples', 'inf', 'classify_images']
# %% testing.ipynb 3
from fastai.vision.all import *
import gradio as gr
# %% testing.ipynb 4
learn = load_learner('export.pkl')
# %% testing.ipynb 9
categories = learn.dls.vocab
def classify_images(img):
pred, pred_idx, probs = learn.predict(img)
return dict(zip(categories, map(float, probs)))
# %% testing.ipynb 12
image = gr.Image()
label = gr.Label()
examples = ['black2.jpeg', 'grizzly2.jpeg', 'grizzly.jpeg', 'cat.jpeg']
# inf = gr.Interface(fn=classify_images, inputs=image, outputs=label, examples=examples)
inf = gr.Interface(fn=classify_images, inputs=image, outputs=label, examples=examples,title = "Bear Classifier",
description = "A bear classifier trained on the internet images with fastai. Created as a demo for Gradio and HuggingFace Spaces.")
inf.launch(inline=False)