road_or_gravel / app.py
lucasvw's picture
bugfix
7036bea
raw
history blame
667 Bytes
# AUTOGENERATED! DO NOT EDIT! File to edit: ../01.ipynb.
# %% auto 0
__all__ = ['learner', 'labels', 'image', 'predict']
# %% ../01.ipynb 3
from fastai.vision.all import *
# %% ../01.ipynb 4
learner = load_learner('model.pkl')
# %% ../01.ipynb 5
labels = learner.dls.vocab
def predict(img):
img = PILImage.create(img)
pred,pred_idx,probs = learner.predict(img)
return {labels[i]: float(probs[i]) for i in range(len(labels))}
# %% ../01.ipynb 7
import gradio as gr
# %% ../01.ipynb 8
image = gr.inputs.Image(shape=(512, 512))
outputs = gr.outputs.Label(num_top_classes=3)
gr.Interface(fn=predict, inputs=image, outputs=outputs).launch(inline=False)