| # --- | |
| # jupyter: | |
| # jupytext: | |
| # text_representation: | |
| # extension: .py | |
| # format_name: light | |
| # format_version: '1.5' | |
| # jupytext_version: 1.15.1 | |
| # kernelspec: | |
| # display_name: Python 3 (ipykernel) | |
| # language: python | |
| # name: python3 | |
| # --- | |
| # !conda install conda=23.7.3 -y | |
| # !nbdev_migrate | |
| #|export | |
| # !pip install gradio | |
| #|export | |
| from fastai.vision.all import * | |
| import gradio as gd | |
| im = PILImage.create('car.jpg') | |
| im.thumbnail((192,192)) | |
| im | |
| #|export | |
| learn = load_learner('export.pkl') | |
| # %time learn.predict(im) | |
| # + | |
| #|export | |
| categories = ('car','motorbike') | |
| def classify_images(img): | |
| pred,idx,probs = learn.predict(img) | |
| return dict(zip(categories,map(float,probs))) | |
| # - | |
| classify_images(im) | |
| # + | |
| #|export | |
| image = gd.inputs.Image(shape=(192,192)) | |
| label = gd.outputs.Label() | |
| examples = ['car.jpg','bike.jpg'] | |
| intf = gd.Interface(fn = classify_images,inputs = image, outputs = label, examples = examples) | |
| intf.launch(inline=False) | |