Spaces:
Running
Running
import gradio as gr | |
import timm | |
import numpy as np | |
from operator import itemgetter | |
from fastai.vision.all import * | |
learn = load_learner("./plants_10_epochs.pkl") | |
categories = learn.dls.vocab | |
def classify_image(img): | |
pred, idx, probs = learn.predict(img) | |
dict_all = dict(zip(categories, map(float,probs))) | |
n = 5 | |
dict_n = dict(sorted(dict_all.items(), key=itemgetter(1), reverse=True)[:n]) | |
return dict_n | |
image = gr.inputs.Image(shape=(192,192)) | |
label = gr.outputs.Label() | |
intf = gr.Interface(fn=classify_image,inputs=image,outputs=label) | |
intf.launch() |