Spaces:
Runtime error
Runtime error
| __all__ = ['animal', 'learn', 'classify_image', 'categories', 'image', 'label', 'examples', 'intf'] | |
| # cell | |
| from fastai.vision.all import * | |
| import gradio as gr | |
| # cell | |
| learn = load_learner('model.pkl') | |
| # cell | |
| categories = ('antelope', 'badger', 'bat', 'bear', 'bee', 'beetle', 'bison', 'boar', | |
| 'butterfly', 'cat', 'caterpillar', 'chimpanzee', 'cockroach', 'cow', | |
| 'coyote', 'crab', 'crow', 'deer', 'dog', 'dolphin', 'donkey', 'dragonfly', | |
| 'duck', 'eagle', 'elephant', 'flamingo', 'fly', 'fox', 'goat', 'goldfish', | |
| 'goose', 'gorilla', 'grasshopper', 'hamster', 'hare', 'hedgehog', | |
| 'hippopotamus', 'hornbill', 'horse', 'hummingbird', 'hyena', 'jellyfish', | |
| 'kangaroo', 'koala', 'ladybugs', 'leopard', 'lion', 'lizard', 'lobster', | |
| 'mosquito', 'moth', 'mouse', 'octopus', 'okapi', 'orangutan', 'otter', | |
| 'owl', 'ox', 'oyster', 'panda', 'parrot', 'pelecaniformes', 'penguin', | |
| 'pig', 'pigeon', 'porcupine', 'possum', 'raccoon', 'rat', 'reindeer', | |
| 'rhinoceros', 'sandpiper', 'seahorse', 'seal', 'shark', 'sheep', 'snake', | |
| 'sparrow', 'squid', 'squirrel', 'starfish', 'swan', 'tiger', 'turkey', | |
| 'turtle', 'whale', 'wolf', 'wombat', 'woodpecker', 'zebra') | |
| def classify_image(img): | |
| preds, idx, probs = learn.predict(img) | |
| return dict(zip(categories, map(float, probs))) | |
| # cell | |
| image = gr.components.Image() | |
| label = gr.components.Label(num_top_classes=3) | |
| examples = ['5a094c5a36.jpg', '6c28066ea3.jpg', '6dd3ba7825.jpg', '6f634d9a5f.jpg', | |
| '7b04dad848.jpg', '7b9f3d9464.jpg', '7c43d5ca9e.jpg', '7cc3758d67.jpg', | |
| '7f995e322c.jpg', '8aefee4c2c.jpg', '0041c9ff2c.jpg'] | |
| intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples) | |
| intf.launch(inline=False, share=True) |