from fastai.vision.all import * import gradio as gr import spaces learn = load_learner('model.pkl') labels = learn.dls.vocab @spaces.GPU def predict(img): # Wrap the incoming PIL image as a fastai PILImage so the model's # item/batch transforms (which turn it into a tensor) actually fire. img = PILImage.create(img) pred, pred_idx, probs = learn.predict(img) return {labels[i]: float(probs[i]) for i in range(len(labels))} gr.Interface( fn=predict, inputs=gr.Image(type='pil'), outputs=gr.Label(num_top_classes=3), title="Board Classifier", description="Classifies Arduino, ESP32, and Raspberry Pi boards from a photo.", ).launch()