| import pathlib | |
| import platform | |
| if platform.system()=='Linux': pathlib.WindowsPath=pathlib.PosixPath | |
| import dill | |
| import gradio as gr | |
| with open('model_dill.pkl','rb') as f: learn=dill.load(f) | |
| labels=['Dog','Cat'] | |
| def predict(img): | |
| from fastai.vision.all import PILImage | |
| img=PILImage.create(img) | |
| pred,pred_idx,probs=learn.predict(img) | |
| return {labels[i]:float(probs[i]) for i in range(len(labels))} | |
| gr.Interface( | |
| fn=predict, | |
| inputs=gr.Image(type="pil"), | |
| outputs=gr.Label(num_top_classes=2), | |
| examples=['dog.jpg','cat.jpg','dcat.jpg'] | |
| ).launch() |