import gradio as gr from fastai.vision.all import * # Load your trained model def load_model(): path = 'export.pkl' learn = load_learner(path) return learn learn = load_model() # Define prediction function def predict_image(img): pred, pred_idx, probs = learn.predict(img) return {learn.dls.vocab[i]: float(probs[i]) for i in range(len(learn.dls.vocab))} # Ensure this matches the function name used in the Interface interface = gr.Interface(fn=predict_image, inputs=gr.Image(type="pil"), # Corrected to use gr.Image outputs=gr.Label(num_top_classes=3), title="Image Classifier", description="Upload an image to classify.") # Use the defined 'interface' variable to launch the Gradio interface if __name__ == "__main__": interface.launch()