#|default_exp app | |
# %% [code] {"execution":{"iopub.status.busy":"2023-01-17T14:41:33.341222Z","iopub.execute_input":"2023-01-17T14:41:33.341652Z","iopub.status.idle":"2023-01-17T14:41:34.776787Z","shell.execute_reply.started":"2023-01-17T14:41:33.341595Z","shell.execute_reply":"2023-01-17T14:41:34.775663Z"}} | |
#|export | |
from fastai.vision.all import * | |
import gradio as gr | |
# %% [code] {"execution":{"iopub.status.busy":"2023-01-17T14:43:57.890571Z","iopub.execute_input":"2023-01-17T14:43:57.891069Z","iopub.status.idle":"2023-01-17T14:43:58.607922Z","shell.execute_reply.started":"2023-01-17T14:43:57.891028Z","shell.execute_reply":"2023-01-17T14:43:58.606710Z"}} | |
#|export | |
learn = load_learner('/minima/model.pkl') | |
# %% [code] {"execution":{"iopub.status.busy":"2023-01-17T14:45:36.880658Z","iopub.execute_input":"2023-01-17T14:45:36.881241Z","iopub.status.idle":"2023-01-17T14:45:36.890302Z","shell.execute_reply.started":"2023-01-17T14:45:36.881102Z","shell.execute_reply":"2023-01-17T14:45:36.889172Z"}} | |
labels = learn.dls.vocab | |
def predict(img): | |
img = PILImage.create(img) | |
pred,pred_idx,probs = learn.predict(img) | |
return {labels[i]: float(probs[i]) for i in range(len(labels))} | |
# %% [code] {"execution":{"iopub.status.busy":"2023-01-17T14:46:08.717339Z","iopub.execute_input":"2023-01-17T14:46:08.717913Z","iopub.status.idle":"2023-01-17T14:46:15.759750Z","shell.execute_reply.started":"2023-01-17T14:46:08.717858Z","shell.execute_reply":"2023-01-17T14:46:15.758401Z"}} | |
gr.Interface(fn=predict, inputs=gr.inputs.Image(shape=(512, 512)), outputs=gr.outputs.Label(num_top_classes=3)).launch(share=True) |