import gradio as gr from fastai.vision.core import PILImage import fastai.vision.all as fav import os import sys def is_cat(x): return x[0].isupper() # Used by model sys.modules["__main__"].is_cat = is_cat if os.name != "posix": print("Converting PosixPath to WindowsPath") import pathlib pathlib.PosixPath = pathlib.WindowsPath learn = fav.load_learner("model.pkl") labels = ["That's a dog", "That's a cat"] def predict(img): img = PILImage.create(img) pred, pred_idx, probs = learn.predict(img) pred = "That's a cat" if pred else "That's a dog" return {labels[i]: float(probs[i]) for i in range(len(labels))} iface = gr.Interface( fn=predict, inputs="image", outputs="label", live=True, title="My first Gradio", description="Well it's really all been said in the title", ) iface.launch()