from fastai.vision import * from fastai.learner import load_learner from PIL import Image import gradio as gr import pathlib, platform plt = platform.system() if plt == 'Linux': pathlib.WindowsPath = pathlib.PosixPath learn = load_learner("model.pkl") categories = list(learn.dls.vocab) def classify_image(img): pred, ix, probs = learn.predict(img) return dict(zip(categories, map(float, probs))) # Whats the gradio input type? Image image = gr.inputs.Image(shape=(192,192)) # Whats the gradio output type? Label label = gr.outputs.Label() # Set up some examples examples = ["examples/kairi.jpg", "examples/riku.jpg", "examples/sora.jpg"] intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples) intf.launch(inline=False)