File size: 1,619 Bytes
bcdab85
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
cce074e
bcdab85
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
cce074e
d7385f9
95cf724
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
38
39
40
41
42
43
44
45
46
47
# AUTOGENERATED! DO NOT EDIT! File to edit: . (unless otherwise specified).

__all__ = ['repo_id', 'learn', 'classify_image', 'categories', 'title', 'description', 'article', 'image', 'label',
           'examples', 'intf']

# Cell
import timm
from fastai.vision.all import *
import gradio as gr

# Cell
from huggingface_hub import from_pretrained_fastai

repo_id = "Jimmie/identify-this-insect"

learn = from_pretrained_fastai(repo_id)

# Cell
categories = learn.dls.vocab

def classify_image(img):
    pred,idx,probs = learn.predict(img)
    return dict(zip(categories, map(float, probs)))
 
# Cell

title = "Identify This Insect"
description = """

This demo was created to distinguish between three types of insects: 'caterpillar', 'centipede', and 'millipede'.

It is just a toy app created mostly because I once got a caterpillar sting and thought that the insect was a centipede and I was scared until I
googled how different a centipede looks from a caterpillar haha! (The insect that had stung me looked more like the fourth example image below).

Enjoy!


"""

article = "Check out how the model was trained: [Training Notebook](https://github.com/jimmiemunyi/deeplearning-experiments/blob/main/notebooks/Centipede_vs_Millipede_vs_Caterpillar.ipynb)."
image = gr.inputs.Image(shape=(224,224))
label = gr.outputs.Label()
examples = ['caterpillar.jpg', 'centipede.jpg', 'millipede.jpg', 'caterpillar-2.jpg']

intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples, title = title, description = description, article = article,
enable_queue=True, cache_examples=False)
intf.launch()