File size: 694 Bytes
09c0760 d84d829 5cca245 09c0760 5cca245 d84d829 09c0760 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
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) |