Spaces:
Running
Running
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) | |