helloworld / app.py
adr
hello
aad814b
# import all the fastai stuff.
from fastai.vision.all import *
def is_cat(x): return x[0].isupper()
# load our model.
learn = load_learner('model.pkl')
# define a prediction function, not sure what this means.
labels = learn.dls.vocab
def predict(img):
img = PILImage.create(img)
# this returns
# predicted category
# index
# probabilities of each category
pred,pred_idx,probs = learn.predict(img)
# we return a weird dictionary or JSON?
return {labels[i]: float(probs[i]) for i in range(len(labels))}
import gradio as gr
gr.Interface(fn=predict, inputs=gr.inputs.Image(shape=(512, 512)), outputs=gr.outputs.Label(num_top_classes=3)).launch()