|
|
|
|
|
|
|
__all__ = ['plt', 'learn', 'categories', 'image', 'label', 'examples', 'iface', 'is_albani', 'classify_image'] |
|
|
|
|
|
from fastai.vision.all import * |
|
import pathlib |
|
import gradio as gr |
|
plt = platform.system() |
|
if plt == 'Linux': pathlib.WindowsPath = pathlib.PosixPath |
|
|
|
def is_albani(path): |
|
return parent_label(path) == "albani" |
|
|
|
|
|
learn = load_learner(Path('./resnet18-albani.pkl')) |
|
categories = ('Dårlig Øl', 'God Øl') |
|
|
|
def classify_image(img): |
|
pred,idx,probs = learn.predict(img) |
|
return dict(zip(categories, map(float, probs))) |
|
|
|
image = gr.inputs.Image(shape=(192, 192)) |
|
label = gr.outputs.Label() |
|
examples = ['albani.jpg', 'albani2.jpg', 'heineken.jpg', 'carlsberg.jpg'] |
|
|
|
iface = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples) |
|
iface.launch(inline=False) |
|
|
|
|