from fastai.vision.all import * import gradio as gr # Load the Fastai model learn = load_learner('resnet50_30_categories.pkl') # Prediction function def classify_image(img): pred, idx, probs = learn.predict(img) return {learn.dls.vocab[i]: float(probs[i]) for i in range(len(probs))} # Gradio Interface iface = gr.Interface( fn=classify_image, inputs=gr.Image(type="pil"), outputs=gr.Label(num_top_classes=3), title="Flower Classifier", description="Upload an image of a flower and the model will predict its category." ) # Launch the app if __name__ == "__main__": iface.launch()