File size: 883 Bytes
bd4c503 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# AUTOGENERATED! DO NOT EDIT! File to edit: test.ipynb.
# %% auto 0
__all__ = ['learn', 'categories', 'image', 'label', 'examples', 'inf', 'classify_img']
# %% test.ipynb 2
from fastai.vision.all import *
import gradio as gr
# %% test.ipynb 4
learn = load_learner('model.pkl')
# %% test.ipynb 5
categories = ('Art Deco', 'Baroque', 'Classical', 'Craftsman', 'Gothic', 'Renaissance', 'Tudor', 'Victorian')
def classify_img(img):
pred,idx,probs = learn.predict(img)
# Convert each tensor probability to a float properly
return dict(zip(categories, map(float, probs)))
# %% test.ipynb 8
# Define Gradio interface
image = gr.Image(image_mode="RGB", type="pil")
label = gr.Label()
examples = ['classical.jpg', 'artdec.jpg', 'victorian.jpeg']
inf = gr.Interface(fn=classify_img, inputs=image, outputs=label, examples=examples)
# Launch the app
inf.launch(inline=False)
|