Download app.py from Kimirrors/Minima: direct link, hf CLI and curl.
- Browser
- Download file 727 Bytes
-
https://huggingface.co/spaces/Kimirrors/Minima/resolve/main/app.py
- Command line
-
hf download hf://spaces/Kimirrors/Minima/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Kimirrors/Minima/resolve/main/app.py
727 Bytes
| import os | |
| os.system("pip install fastai gradio torch") | |
| __all__ = ['is_cat', 'learn', 'classify_image', 'image', 'label', 'examples', 'intf'] | |
| #导包 | |
| from fastai.vision.all import * | |
| import gradio as gr | |
| import pathlib | |
| def is_cat(x): return x[1].isupper() | |
| #从模型中获取数据 | |
| learn = load_learner('model.pkl') | |
| #当前的分类 | |
| categories = ('Dog', 'Cat','Rabbit') | |
| def classify_image(img): | |
| img = PILImage.create(img) | |
| pred, idx, probs = learn.predict(img) | |
| return dict(zip(categories, map(float, probs))) | |
| image = gr.Image(type="pil") | |
| label = gr.Label() | |
| examples = ['dog.jpg', 'cat.jpg', 'dunno.jpg'] | |
| intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples) | |
| intf.launch() |