helloworld / app.py
adr
deploy to huggingface spaces
5b609f4
raw
history blame
No virus
659 Bytes
# import all the fastai stuff.
from fastai.vision.all import *
# load our model.
learn = load_learner('export.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)