Spaces:
Build error
Build error
Download app.py from numericite/fastbook-02: direct link, hf CLI and curl.
- Browser
- Download file 748 Bytes
-
https://huggingface.co/spaces/numericite/fastbook-02/resolve/main/app.py
- Command line
-
hf download hf://spaces/numericite/fastbook-02/app.py
-
curl -L -o app.py https://huggingface.co/spaces/numericite/fastbook-02/resolve/main/app.py
748 Bytes
| # AUTOGENERATED! DO NOT EDIT! File to edit: notebook.ipynb. | |
| # %% auto 0 | |
| __all__ = ['im', 'learn', 'categories', 'examples', 'intf', 'is_cat', 'classify_image'] | |
| # %% notebook.ipynb 0 | |
| import gradio as gr | |
| from fastai.vision.all import * | |
| def is_cat(x): return x[0].isupper() | |
| im = PILImage.create("dog.jpg") | |
| im.thumbnail((128,128)) | |
| im | |
| # %% notebook.ipynb 1 | |
| learn = load_learner('model.pkl') | |
| # %% notebook.ipynb 3 | |
| categories = ('Dog', 'Cat') | |
| def classify_image(img): | |
| pred,idx,probs = learn.predict(img) | |
| return dict(zip(categories, map(float, probs))) | |
| # %% notebook.ipynb 5 | |
| examples = ['dog.jpg', 'cat.jpg', 'dunno.jpg'] | |
| intf = gr.Interface(fn=classify_image, inputs="image", outputs="label", examples=examples) | |
| intf.launch(inline=False) | |