Spaces:
Runtime error
Runtime error
Download app.py from AgastyaPatel/FastAI-Ch02-BearClassifier: direct link, hf CLI and curl.
- Browser
- Download file 922 Bytes
-
https://huggingface.co/spaces/AgastyaPatel/FastAI-Ch02-BearClassifier/resolve/main/app.py
- Command line
-
hf download hf://spaces/AgastyaPatel/FastAI-Ch02-BearClassifier/app.py
-
curl -L -o app.py https://huggingface.co/spaces/AgastyaPatel/FastAI-Ch02-BearClassifier/resolve/main/app.py
922 Bytes
| # AUTOGENERATED! DO NOT EDIT! File to edit: 02_BearClassifierDeployment.ipynb. | |
| # %% auto 0 | |
| __all__ = ['learn', 'categories', 'image', 'label', 'examples', 'intf', 'classify_image'] | |
| # %% 02_BearClassifierDeployment.ipynb 4 | |
| # importing dependencies | |
| from fastai.vision.all import * | |
| import gradio as gr | |
| # %% 02_BearClassifierDeployment.ipynb 5 | |
| # creating inference | |
| learn = load_learner('content/bearClassifier.pkl') | |
| # %% 02_BearClassifierDeployment.ipynb 6 | |
| categories = ('Black', 'Grizzly', 'Teddy') | |
| def classify_image(img): | |
| pred, idx, probs = learn.predict(img) | |
| return dict(zip(categories, map(float, probs))) | |
| # %% 02_BearClassifierDeployment.ipynb 7 | |
| # gradio interface Setup | |
| image = gr.Image() | |
| label = gr.Label() | |
| examples = ['content/bear1.jpg', 'content/bear2.jpg', 'content/bear3.jpg', 'content/bear4.jpg'] | |
| intf = gr.Interface(fn = classify_image, inputs = image, outputs = label, examples = examples).launch() | |