Spaces:
Runtime error
Runtime error
| # AUTOGENERATED! DO NOT EDIT! File to edit: app.ipynb. | |
| # %% auto 0 | |
| __all__ = ['learner', 'categories', 'ifc', 'label_func', 'classify_image'] | |
| # %% app.ipynb 1 | |
| # import gradio as gr | |
| # # from fastai.vision.all import vision_learner | |
| # def greet(val1, val2): | |
| # return int(val1) + int(val2) | |
| # iface = gr.Interface(fn=greet, inputs=["text", "text"], outputs="text") | |
| # iface.launch(share=False) | |
| # %% app.ipynb 3 | |
| from fastai.vision.all import * | |
| def label_func(fname): | |
| return fname.name.split('_')[1].split('.')[0].strip() | |
| learner = load_learner('fruits.pkl') | |
| # %% app.ipynb 4 | |
| categories = learner.dls.vocab | |
| def classify_image(img): | |
| pred, pred_idx, probs = learner.predict(img) | |
| return dict(zip(categories, map(float, probs))) | |
| # %% app.ipynb 5 | |
| from re import I | |
| import gradio as gr | |
| ifc = gr.Interface(fn=classify_image, | |
| inputs=gr.Image(type='pil', label='Input Image'), | |
| outputs=gr.Label(num_top_classes=6) | |
| ) | |
| ifc.launch() | |