helloworld / app.py
adr
fixed model name
2427c60
raw
history blame
658 Bytes
# import all the fastai stuff.
from fastai.vision.all import *
# 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(share=True)