| import gradio as gr | |
| from fastbook import * | |
| from fastai.vision.widgets import * | |
| learn_inf = load_learner('numsimple.pkl') | |
| def classify_image(img): | |
| pred, idx, probs = learn_inf.predict(img) | |
| categories = learn_inf.dls.vocab | |
| return { c: val for c,val in zip(categories, | |
| map(float, probs)) | |
| if val >= 0.05 } | |
| # classify_image(xx) | |
| image = gr.inputs.Image(shape=(224,244)) | |
| label = gr.outputs.Label() | |
| #examples = ['/kaggle/input/images-2023-04-26/four.png'] | |
| worker = gr.Interface(fn=classify_image, | |
| inputs=image, | |
| outputs=label | |
| #, | |
| # examples=examples | |
| ) | |
| worker.launch() | |