File size: 683 Bytes
3d514fa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
from fastai.vision.all import *
import gradio as gr
import pathlib

plt = platform.system()
if plt == 'Linux': pathlib.WindowsPath = pathlib.PosixPath

file = open('model.pkl', 'rb')
temp = pickle.load(file)
file.close()

infer = temp['model']
data_map = [f'{item["name"]} ({item["botanical_name"]})' for item in temp['map']]

def classify(img):
    _, _, probs = infer.predict(img)
    return dict(map(lambda x: (data_map[int(infer.dls.vocab[x[0]])], float(x[1])), enumerate(probs)))

image = gr.inputs.Image(shape=(224, 224))
label = gr.outputs.Label(num_top_classes=3)
iface = gr.Interface(fn=classify, title='Indoor Plant Classifier', inputs=image, outputs=label)
iface.launch()