from fastai.vision.all import * import gradio as gr # any external function used for labeling needs to be included in here def is_cat(x): return x[0].isupper() # this learner 'pkl' file is exactly the same as what you get when you trained it # example : learn = vision_learner(dls,resnet18,metrics=error_rate) # example : learn.fine_tune(3) learn=load_learner('catsdogsmodel.pkl') # Preping data for gradio, We are creating a dictionary for gradio. # One of the annoying things about 'gradio' is that it does not recognize tensor number and probabilities. # In fact, numpy either categories = ('Dog', 'Cat') # prediction, index & probabilities, gradio expects a dictinoary def classify_image(img): pred,idx,probs = learn.predict(img) return dict(zip(categories,map(float, probs))) image = gr.inputs.Image(shape=(192,192)) label = gr.outputs.Label() examples = ['dog.jpg','dog2.jpg','cat.jpg'] intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples) # to create a public link, set 'share=True' in 'launch()' intf.launch(inline=False)