ball-classifier / app.py
irakli-ff
first version
b9c80a4
raw
history blame contribute delete
881 Bytes
# AUTOGENERATED! DO NOT EDIT! File to edit: ../app.ipynb.
# %% auto 0
__all__ = ['learn', 'categories', 'image', 'label', 'examples', 'intf', 'pet_class', 'classify_image']
# %% ../app.ipynb 1
from fastai.vision.all import *
import gradio as gr
import io
from PIL import Image
def pet_class(x): return x
# %% ../app.ipynb 3
learn = load_learner('model.pkl')
# %% ../app.ipynb 6
categories = ('basketball ball','golf ball', 'rugby ball', 'soccer ball')
def classify_image(img):
pred_class, pred_idx, probs = learn.predict(img)
return dict(zip(categories, map(float,probs)))
# %% ../app.ipynb 8
image = gr.components.Image(shape=(192,192))
label = gr.components.Label()
examples = ['basketball.png', 'golf_ball.jpg', 'rugby_ball.jpg', 'soccer_ball.jpg']
intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
intf.launch(inline=False)