from fastai.vision.all import * import gradio as gr import pathlib # Load the trained model learn = load_learner('export.pkl') # Categories for the prediction categories = ('black', 'grizzly', 'teddy') # Image classification function def classify_image(img): img = PILImage.create(img) # Convert image to fastai's PILImage format img = img.resize((192, 192)) pred, idx, probs = learn.predict(img) return dict(zip(categories, map(float,probs))) # Define the Gradio interface image = gr.Image() # Define the image input with shape label = gr.Label() # Output label for the classification result examples = ['grizzly.jpg', 'black.jpg', 'teddy.jpg', 'dunno.jpg'] # Create the interface inft = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples) # Launch the interface inft.launch(inline=False)