__all__ = ["is_cat" , "learn", "classify_image", "image", "outputs", "labels", "examples", "intf"] | |
from fastai.vision.all import * | |
import gradio as gr | |
import skimage | |
def is_cat(x): return x[0].isupper() | |
learn = load_learner("model.pkl") | |
labels = learn.dls.vocab | |
def classify_image(img): | |
img = PILImage.create(img) | |
pred,idx,probs = learn.predict(img) | |
return { labels[i]: float(probs[i]) for i in range(len(labels)) } | |
image = gr.inputs.Image(shape=(192, 192)) | |
outputs = gr.outputs.Label(num_top_classes=3) | |
examples = ["dog.jpg", "cat.jpg", "dunno.jpg"] | |
intf = gr.Interface(fn=classify_image, inputs=image, outputs=outputs, examples=examples) | |
intf.launch() |