Download app.py from ValNeu/pets: direct link, hf CLI and curl.
- Browser
- Download file 980 Bytes
-
https://huggingface.co/spaces/ValNeu/pets/resolve/main/app.py
- Command line
-
hf download hf://spaces/ValNeu/pets/app.py
-
curl -L -o app.py https://huggingface.co/spaces/ValNeu/pets/resolve/main/app.py
980 Bytes
| __all__ = ['learn', 'classify_image', 'categories', 'image', 'label', 'examples', 'intf'] | |
| # Cell | |
| from fastai.vision.all import * | |
| import gradio as gr | |
| import timm | |
| # Cell | |
| # Check if AMPMode exists in the current fastai version | |
| try: | |
| from fastai.callback.fp16 import AMPMode | |
| except ImportError: | |
| # Define AMPMode if not found (you need to replace this with the actual implementation) | |
| class AMPMode: | |
| def __init__(self): | |
| pass | |
| # Cell | |
| learn = load_learner('model.pkl') | |
| # Cell | |
| categories = learn.dls.vocab | |
| def classify_image(img): | |
| # Ensure img is transformed into a tensor in the right shape | |
| img = PILImage.create(img) | |
| pred, idx, probs = learn.predict(img) | |
| return dict(zip(categories, map(float, probs))) | |
| # Cell | |
| image = gr.components.Image() | |
| label = gr.components.Label() | |
| examples = ['Maine_Coon.jpg', 'Beagle.jpg'] | |
| # Cell | |
| intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples) | |
| intf.launch(inline=False) | |