minima / app.py
Valentina Sanchez
fix cats and dogs
7555b10
raw
history blame contribute delete
899 Bytes
# import gradio as gr
# def greet(name):
# return "Hello " + name + "!!"
# demo = gr.Interface(fn=greet, inputs="text", outputs="text")
# demo.launch()
__all__ = ['label_func', 'learn', 'classify_image', 'categories', 'image', 'label', 'examples', 'intf']
# Cell
from fastai.vision.all import *
import gradio as gr
def label_func(x):
return "dog" if x[0].islower() else "cat"
# Cell
learn = load_learner('model.pkl')
# Cell
categories = ('Cat', 'Dog')
def classify_image(img):
pred, idx, probs = learn.predict(img)
return dict(zip(categories, map(float, probs)))
# Cell
# image = gr.inputs.Image(shape=(192, 192))
image = gr.Image(height=192, width=192)
label = gr.Label()
# label = gr.outputs.Label()
examples = ['dog1.jpeg', 'dog2.jpeg', 'dog3.jpeg','cat.jpg']
intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
intf.launch(inline=False)