File size: 966 Bytes
2b19354
 
 
 
 
 
 
 
 
 
6cf033e
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
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/abdalnassir/chicken-breeds.\n
Due to the limitations of the data, only the following breeds are currently recognised: American Gamefowl, Sapphire Gem, Speckled Sussex, Wyandotte, chick (all chicks recognised as 'Chick').
"""
EXAMPLES = ["wyandotte.jpg"]


learn = load_learner("export.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)