Fruit_or_not / app.py
Jay Suh
Add images and updated app.py
d2046d6
# AUTOGENERATED! DO NOT EDIT! File to edit: Deployment.ipynb.
# %% auto 0
__all__ = ['learn', 'categories', 'image', 'label', 'examples', 'inf', 'get_y', 'classify_images']
# %% Deployment.ipynb 2
from fastai.vision.all import *
import gradio as gr
def get_y(path):
return parent_label(path).split(' and ')
# %% Deployment.ipynb 3
learn = load_learner('export.pkl')
# %% Deployment.ipynb 8
categories = learn.dls.vocab
def classify_images(img):
"""classifies images and returns the probabilities on each categories."""
pred, pred_idx, probs = learn.predict(img)
return dict(zip(categories, map(float, probs)))
# %% Deployment.ipynb 10
image = gr.inputs.Image(shape=(192, 192))
label = gr.outputs.Label()
# If you have more or less examples, edit this list.
examples = ['apple.jpg', 'orange.jpg', 'apple and orange.jpg',
'pear and orange.jpg', 'apple and pear.jpg', 'apple and pear and orange.jpg',
'random images.jpg']
inf = gr.Interface(fn=classify_images, inputs=image, outputs=label, examples=examples)
inf.launch(inline=False)