Spaces:
Build error
Build error
Download app.py from timkral/pdlfc_bears: direct link, hf CLI and curl.
- Browser
- Download file 889 Bytes
-
https://huggingface.co/spaces/timkral/pdlfc_bears/resolve/main/app.py
- Command line
-
hf download hf://spaces/timkral/pdlfc_bears/app.py
-
curl -L -o app.py https://huggingface.co/spaces/timkral/pdlfc_bears/resolve/main/app.py
889 Bytes
| # AUTOGENERATED! DO NOT EDIT! File to edit: drive/MyDrive/PDLfC/PDLfC_Chap2.ipynb. | |
| # %% auto 0 | |
| __all__ = ['learn_inf', 'categories', 'image', 'label', 'examples', 'intf', 'classify_image'] | |
| # %% drive/MyDrive/PDLfC/PDLfC_Chap2.ipynb 27 | |
| from fastai.vision.all import load_learner | |
| learn_inf = load_learner('pdlfc_bears.pkl') | |
| # %% drive/MyDrive/PDLfC/PDLfC_Chap2.ipynb 28 | |
| categories = ('black', 'grizzly', 'teddy') | |
| def classify_image(img): | |
| img = img.resize((224, 224)) | |
| pred, idx, probs = learn_inf.predict(img) | |
| return dict(zip(categories, map(float, probs))) | |
| # %% drive/MyDrive/PDLfC/PDLfC_Chap2.ipynb 30 | |
| import gradio as gr | |
| image = gr.Image(type="pil") | |
| label = gr.Label() | |
| examples = ['images/grizzly.jpg', 'images/black.jpg', 'images/plant.jpg', 'images/teddy.jpg'] | |
| intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples) | |
| intf.launch(inline=False) | |