| from fastai.vision.all import * | |
| import gradio as gr | |
| # import pathlib ### use this trick https://stackoverflow.com/questions/57286486/i-cant-load-my-model-because-i-cant-put-a-posixpath | |
| # temp = pathlib.PosixPath | |
| # pathlib.PosixPath = pathlib.WindowsPath | |
| learn = load_learner('model.pkl') | |
| # pathlib.PosixPath = temp | |
| categories = ('Morocco', 'Usa') | |
| def classify_image(img): | |
| pred, idx, probs = learn.predict(img) | |
| return dict(zip(categories, map(float, probs))) | |
| image = gr.Image(height=192, width=192) | |
| label = gr.Label() | |
| examples = ['usa.jpg', 'morocco.jpg', 'spain.jpg'] | |
| demo = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples) | |
| demo.launch(inline=False) |