Spaces:
Sleeping
Sleeping
import gradio as gr | |
from fastai.vision.all import * | |
import skimage | |
# I was too lazy to re-export the model using a lambda so I defined the is_cat method here before unpickling | |
def is_cat(x): return x[0].isupper() | |
learn = load_learner('dog_or_cat.pkl') | |
labels = learn.dls.vocab | |
def predict(img): | |
img = PILImage.create(img) | |
pred,pred_idx,probs = learn.predict(img) | |
return {labels[i]: float(probs[i]) for i in range(len(labels))} | |
title = "Is it a Cat?" | |
examples = ['cat_ex.jpg', 'dog_ex.jpg'] | |
gr.Interface( | |
fn=predict, | |
inputs=gr.components.Image(height=512, width=512), | |
outputs=gr.components.Label(), | |
title=title, | |
examples=examples, | |
).launch() |