File size: 1,090 Bytes
2b19354
 
 
 
 
47ff0a2
 
 
2b19354
 
 
6cf033e
3537852
1b90f8c
6cf033e
 
1b90f8c
 
 
 
 
 
2b19354
1b90f8c
2b19354
 
 
 
 
1b90f8c
6cf033e
2b19354
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
from fastai.vision.all import PILImage, load_learner
from gradio import Interface
from gradio.components import Image, Label

TITLE = "Chicken Breed Classifier"
DESCRIPTION = """A chicken breed classifier trained using the dataset here: https://www.kaggle.com/datasets/edkenthazledine/chicken-breeds
There are many breeds of chicken, and getting lots of pictures of them is hard!
This can identify (to varying degrees of accuracy, the model is ~90% accurate): American Gamefowl, Australorp, Burford Brown, Crevecoeur, Derbyshire Redcap, Easter Egger, Light Sussex, Sapphire Gem, Speckled Sussex, Wyandotte
"""
EXAMPLES = ["wyandotte.jpg"]


learn = load_learner("export_10b_90p.pkl")
labels = learn.dls.vocab


def predict(img):
    img = PILImage.create(img)
    pred, pred_idx, probs = learn.predict(img)
    return {labels[i]: float(probs[i]) for i in range(len(labels))}


iface = Interface(
    fn=predict,
    inputs=Image(shape=(512, 512)),
    outputs=Label(num_top_classes=3),
    title=TITLE,
    description=DESCRIPTION,
    examples=EXAMPLES,
)

iface.launch(enable_queue=True)