Spaces:
Runtime error
Runtime error
File size: 1,269 Bytes
b72af57 6c07295 b72af57 0a7affa b72af57 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
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 <a href="fast.ai">FastAI</a>.'
article = """
<p>The model is a pre-trained ResNet18 fine-tuned on a dataset obtained from
<a href="https://www.inaturalist.org">iNaturalist</a> and <a href="https://www.gbif.org/">GBIF</a>.
It recognizes the following species (according to GBIF, the 50 most observed turtles in North America):</p>
<ul><li>""" + "</li><li>".join(labels) + """</li></ul>
<h3>References:</h3>
<p>GBIF.org (8 September 2023) GBIF Occurrence Download <a href="https://doi.org/10.15468/dl.mvss9v">https://doi.org/10.15468/dl.mvss9v</a></p>
"""
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=['florida_softshell.jpg', 'hawksbill.jpg', 'blandings.jpg']
)
iface.launch()
|