Download app.py from vietngth/testing: direct link, hf CLI and curl.
- Browser
- Download file 954 Bytes
-
https://huggingface.co/spaces/vietngth/testing/resolve/main/app.py
- Command line
-
hf download hf://spaces/vietngth/testing/app.py
-
curl -L -o app.py https://huggingface.co/spaces/vietngth/testing/resolve/main/app.py
954 Bytes
| # AUTOGENERATED! DO NOT EDIT! File to edit: app.ipynb. | |
| # %% auto 0 | |
| __all__ = ['path', 'dls', 'learn', 'loaded_learn', 'categories', 'image', 'label', 'examples', 'intf', 'is_cat', 'classify_image'] | |
| # adding to requirements doesn't work | |
| import os | |
| os.system("pip uninstall -y gradio") | |
| os.system("pip install gradio==3.50.0") | |
| # %% app.ipynb 1 | |
| from fastai.vision.all import * | |
| import gradio as gr | |
| path = untar_data(URLs.PETS)/'images' | |
| def is_cat(x): return x[0].isupper() | |
| # %% app.ipynb 3 | |
| loaded_learn = load_learner('model.pkl') | |
| categories = ("Dog", "Cat") | |
| def classify_image(img): | |
| pred, idx, probs = loaded_learn.predict(img) | |
| return dict(zip(categories, map(float, probs))) | |
| image = gr.inputs.Image(shape=(192, 192)) | |
| label = gr.outputs.Label() | |
| examples = ["doggo.jpg", "catto.jpg", "test.jpg"] | |
| intf = gr.Interface( | |
| fn=classify_image, | |
| inputs=image, | |
| outputs=label, | |
| examples=examples | |
| ) | |
| intf.launch(inline=False, share=True) | |