Download app.py from Grimyow/3rdtry: direct link, hf CLI and curl.
- Browser
- Download file 706 Bytes
-
https://huggingface.co/spaces/Grimyow/3rdtry/resolve/main/app.py
- Command line
-
hf download hf://spaces/Grimyow/3rdtry/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Grimyow/3rdtry/resolve/main/app.py
706 Bytes
| from fastai.vision.all import * | |
| import gradio as gr | |
| from fastai.learner import load_learner | |
| # Load the exported learner | |
| learn = load_learner('model.pkl') | |
| # Categories (must match your model's label order) | |
| categories = ('dog', 'cat') | |
| # Prediction function | |
| def classify_image(img): | |
| pred, idx, probs = learn.predict(img) | |
| return dict(zip(categories, map(float, probs))) | |
| # Gradio interface setup | |
| image = gr.Image(height=192, width=192) | |
| label = gr.Label() | |
| examples = ['dog.jpg', 'cat.jpg', 'whatever.jpg'] # These must exist in the same folder | |
| intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples) | |
| # Launch app (Hugging Face Spaces will handle this) | |
| intf.launch() | |