from fastai.learner import load_learner from fastai.vision.core import PILImage import gradio as gr learn = load_learner('export.pkl') labels = learn.dls.vocab def predict(img): img = PILImage.create(img) preds, pred_idx, probs = learn.predict(img) return {labels[i]: float(probs[i]) for i in range(len(labels))} title = "Turtle Pleasure" description = 'An image classifier for recognizing turtle species, created using FastAI.' article = """

The model is a pre-trained ResNet18 fine-tuned on a dataset obtained from iNaturalist and GBIF. It recognizes the following species (according to GBIF, the 50 most observed turtles in North America):

References:

GBIF.org (8 September 2023) GBIF Occurrence Download "https://doi.org/10.15468/dl.mvss9v"

""" iface = gr.Interface( fn=predict, inputs=gr.Image(shape=(400, 400)), outputs=gr.Label(num_top_classes=3), title=title, description=description, article=article, examples=['test_snapper.jpg'] ) iface.launch()