File size: 1,308 Bytes
55c76b2 a8bedcb 55c76b2 a395eae 55c76b2 db43008 55c76b2 6206a08 55c76b2 236d1d5 55c76b2 a79ccf8 a8bedcb 2855663 55c76b2 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | # import gradio as gr
# def greet(name):
# return "Hello " + name + "!!"
# demo = gr.Interface(fn=greet, inputs="text", outputs="text")
# demo.launch()
from fastai.vision.all import *
import gradio as gr
# We need to re-define the functions used in the models as the learner in the .pkl file uses these external functions and sousnt have the source code to the function
def is_cat(x): return x[0].isupper()
# we are loading the learner in the .pkl file to now do our project
learn = load_learner('model.pkl')
#N/b gradio does not handle pytorch tensors hence the need to convert to float
categories = ('Dog,','Cat')
def classify_image(img):
pred,idx,probs = learn.predict(img)
# Read more on dict(zip())
return dict(zip(categories, map(float,probs)))
# dog = '/Users/izd/Library/Mobile Documents/com~apple~CloudDocs/Documents/fastai_course/minimal/doggy.jpg'
# cat = '/Users/izd/Library/Mobile Documents/com~apple~CloudDocs/Documents/fastai_course/minimal/gato.jpg'
image = gr.Image(height=192, width=192)
label = gr.Label()
examples = ['/app/doggy.jpg','/app/gatto.jpg']
# intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
# intf.launch(inline=False)
intf = gr.Interface(fn=classify_image, inputs=image, outputs=label)
intf.launch(inline=False) |