minimal / app.py
IZDixit's picture
removed examples from the gr.Interface
2855663
# 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)