Spaces:
Sleeping
Sleeping
| __all__ = ['learn', 'categories', 'examples', 'image', 'label', 'intf', 'classify_image'] | |
| from fastai.vision.all import * | |
| import gradio as gr | |
| import timm | |
| # the get_y function | |
| def has_tori_logo_parent(o): | |
| p = Path(o).parent.name | |
| return p == 'tori-logo' | |
| learn = load_learner('tori-model.pkl') | |
| categories = ['Something else', 'Tori logo'] | |
| def classify_image(img): | |
| is_tori_logo, idx, probs = learn.predict(img) | |
| return dict(zip(categories, map(float,probs))) | |
| image_dir = 'images' | |
| examples = list(map(lambda image_name: f"{image_dir}/{image_name}", os.listdir(image_dir))) | |
| image = gr.Image() | |
| label = gr.Label() | |
| intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples) | |
| intf.launch() |