Spaces:
Build error
Build error
| import gradio as gr | |
| from fastai.vision.all import load_learner, PILImage | |
| # Load your learner | |
| learn = load_learner('export.pkl') | |
| # Define the prediction function | |
| def predict(img): | |
| img = PILImage.create(img) # Convert image into PILImage | |
| pred, pred_idx, probs = learn.predict(img) # Make prediction | |
| labels = learn.dls.vocab # Get the labels | |
| return {labels[i]: float(probs[i]) for i in range(len(labels))} | |
| # Define the Gradio interface | |
| interface = gr.Interface(fn=predict, inputs=gr.Image(), outputs=gr.Label(num_top_classes=3)) | |
| # Launch the interface | |
| interface.launch(share=True) | |