|
|
|
|
|
|
|
__all__ = ['plt', 'learn', 'categories', 'description', 'image', 'label', 'examples', 'iface', 'classify_image'] |
|
|
|
|
|
from fastai.vision.all import * |
|
import pathlib |
|
import gradio as gr |
|
plt = platform.system() |
|
if plt == 'Linux': pathlib.WindowsPath = pathlib.PosixPath |
|
|
|
|
|
|
|
|
|
learn = load_learner(Path('./resnet18-albani.pkl')) |
|
categories = ('God Øl', 'Dårlig Øl') |
|
|
|
def classify_image(img): |
|
pred,idx,probs = learn.predict(img) |
|
return dict(zip(categories, map(float, probs))) |
|
|
|
description = """ |
|
## Er du i tvivl om at den øl du sidder med i hånden lige, nu er god? |
|
### Tvivl ej 68 års invotation inden for machine learning skal nok fortælle dig om øllen er god eller ej |
|
""" |
|
image = gr.Image(shape=(192, 192)) |
|
label = gr.Label() |
|
examples = ['albani.jpg', 'albani2.jpg', 'albani3.jpg', 'heineken.jpg', 'carlsberg.jpg'] |
|
|
|
iface = gr.Interface( |
|
fn=classify_image, |
|
inputs=image, |
|
outputs=label, |
|
examples=examples, |
|
description=description, |
|
) |
|
|
|
iface.launch(inline=False) |
|
|
|
|