Jessica Walkenhorst
Initial app
72e97d4
from fastai.vision.learner import load_learner
import gradio as gr
MODELPATH = Path().cwd().parent/'model'/'cygnet-vs-duckling.pkl'
EXAMPLEPATH = Path().cwd().parent/'example-images'
learn = load_learner(MODELPATH)
categories = learn.dls.vocab
def classify_image(image):
_, _, probs = learn.predict(image)
return dict(zip(categories, map(float, probs)))
title = 'Mirror, mirror on the wall am I a duckling or a cygnet after all?'
description = """Hans Christian Andersen's tale of the ugly duckling tells us about the sad youth of a cygnet acidentally being brought up in a family of ducks and being ostrized for its ugliness.\n But what if the poor cygnet had a magic mirror to tell it that it was in fact a young swan after all? Machine learning to the rescue!"""
examples = EXAMPLEPATH.glob('*.jpg')
app = gr.Interface(fn=classify_image,
inputs=gr.components.Image(),
outputs=gr.components.Label(),
examples=examples,
title=title,
description=description,
allow_flagging='never')
app.launch()