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()