Spaces:
Running
Running
File size: 573 Bytes
2fd875f 4f11969 93df725 2fd875f 93df725 2fd875f 4f11969 93df725 be9ef9d 0e683f9 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
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() |