Spaces:
Runtime error
Runtime error
Add model, interface, and example
Browse files- app.py +36 -0
- export.pkl +3 -0
- test_snapper.jpg +0 -0
app.py
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastai.learner import load_learner
|
2 |
+
from fastai.vision.core import PILImage
|
3 |
+
import gradio as gr
|
4 |
+
|
5 |
+
learn = load_learner('export.pkl')
|
6 |
+
|
7 |
+
labels = learn.dls.vocab
|
8 |
+
def predict(img):
|
9 |
+
img = PILImage.create(img)
|
10 |
+
preds, pred_idx, probs = learn.predict(img)
|
11 |
+
return {labels[i]: float(probs[i]) for i in range(len(labels))}
|
12 |
+
|
13 |
+
title = "Turtle Pleasure"
|
14 |
+
description = 'An image classifier for recognizing turtle species, created using <a href="fast.ai">FastAI</a>.'
|
15 |
+
article = """
|
16 |
+
<p>The model is a pre-trained ResNet18 fine-tuned on a dataset obtained from
|
17 |
+
<a href="https://www.inaturalist.org">iNaturalist</a> and <a href="https://www.gbif.org/">GBIF</a>.
|
18 |
+
It recognizes the following species (according to GBIF, the 50 most observed turtles in North America):</p>
|
19 |
+
|
20 |
+
<ul><li>""" + "</li><li>".join(labels) + """</li></ul>
|
21 |
+
|
22 |
+
<h3>References:</h3>
|
23 |
+
<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>
|
24 |
+
"""
|
25 |
+
|
26 |
+
iface = gr.Interface(
|
27 |
+
fn=predict,
|
28 |
+
inputs=gr.Image(shape=(400, 400)),
|
29 |
+
outputs=gr.Label(num_top_classes=3),
|
30 |
+
title=title,
|
31 |
+
description=description,
|
32 |
+
article=article,
|
33 |
+
examples=['test_snapper.jpg']
|
34 |
+
)
|
35 |
+
iface.launch()
|
36 |
+
|
export.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:02fe4aaa0034ef4e345e9791a52fa6fe5fa24fb044610b4805a26f90adef38f8
|
3 |
+
size 50040813
|
test_snapper.jpg
ADDED
![]() |