import gradio as gr from fastai.vision.all import load_learner from PIL import Image model = load_learner('./export.pkl') def classify_image(img): # Convert the image to a format the model expects img = Image.fromarray(img.astype('uint8'), 'RGB') # Make a prediction pred, idx, probs = model.predict(img) # Return the result return {model.dls.vocab[i]: float(probs[i]) for i in range(len(model.dls.vocab))} demo = gr.Interface(fn=classify_image, inputs=gr.Image(label = 'Upload an image of a dung beetle, a dolphin, or an elephant!'), outputs="label") if __name__ == "__main__": demo.launch()