import gradio as gr from fastai.vision.all import load_learner, PILImage # Load your exported fastai model model_path = "export.pkl" # your exported .pkl learn = load_learner(model_path) # Prediction function def predict(image): img = PILImage.create(image) # ensure it's a fastai PILImage pred_class, pred_idx, outputs = learn.predict(img) return (str(pred_class)) # Gradio interface iface = gr.Interface( fn=predict, inputs=gr.Image(type="pil"), outputs=gr.Textbox(label="Prediction"), title="FastAI Image Classification", description="Upload an image to get prediction from your exported fastai model." ) if __name__ == "__main__": iface.launch(server_name="0.0.0.0", server_port=7860)