Spaces:
Runtime error
Runtime error
| # AUTOGENERATED! DO NOT EDIT! File to edit: 02_spider_deploy.ipynb. | |
| # %% auto 0 | |
| __all__ = ['learn', 'path', 'categories', 'image', 'output', 'examples', 'intf', 'second', 'classify_image'] | |
| # %% 02_spider_deploy.ipynb 0 | |
| from fastbook import * | |
| # %% 02_spider_deploy.ipynb 2 | |
| import gradio as gr | |
| # %% 02_spider_deploy.ipynb 3 | |
| learn = load_learner("spider.pkl") | |
| # %% 02_spider_deploy.ipynb 4 | |
| path = Path("data/spiders") | |
| categories = learn.dls.vocab | |
| # %% 02_spider_deploy.ipynb 5 | |
| def second(x): | |
| a, b = x | |
| return b | |
| def classify_image(img): | |
| image = Image.fromarray(img) | |
| image.thumbnail(size=(224,224)) | |
| img = np.asarray(img) | |
| ans,idx,preds = learn.predict(img) | |
| results = zip(categories, map(float, preds)) | |
| results = sorted(results, key=second, reverse=True) | |
| return dict(results[:10]) | |
| # %% 02_spider_deploy.ipynb 7 | |
| image = gr.inputs.Image() | |
| output = gr.outputs.Label() | |
| examples = ["data/spider1.jpg", "data/spider2.jpg"] | |
| intf = gr.Interface(fn=classify_image, inputs=image, outputs=output, examples=examples) | |
| intf.launch(inline=False) | |