testing2 / app.py
klathan's picture
Final push after fixing fastai version
77ddd05
Raw
History Blame Contribute Delete
813 Bytes
#| export
from fastai.vision.all import *
import gradio as gr
def is_cat(x): return x[0].isupper()
#| export
learn = load_learner('model.pkl')
#| export
categories = ('Dog', 'Cat')
def classify_images(img):
#'Is it a car?', 'Is it a car? but as zero or one', 'probabillity of [dog, cat]'
pred, idx, probs = learn.predict(img)
#return dictionary
#zip together the categories and the
#turn probs to float
return dict(zip(categories, map(float, probs)))
examples = ['dog.jpg', 'cat.jpg', 'catdog.jpg', 'he-s-a-catdog-or-dogcat.jpeg']
intf = gr.Interface(
fn=classify_images,
inputs=gr.Image(type="pil", image_mode="RGB", height=192, width=192),
outputs=gr.Label(),
examples=examples
)
intf.launch()