| | import platform |
| | import pathlib |
| |
|
| | plt = platform.system() |
| | if plt == 'Linux': |
| | pathlib.WindowsPath = pathlib.PosixPath |
| |
|
| | import gradio as gr |
| | from fastai.vision.all import * |
| | from PIL import Image |
| |
|
| | |
| | learn = load_learner('model.pkl') |
| |
|
| | def classify_bear(image): |
| | |
| | img = PILImage.create(image) |
| | |
| | |
| | pred, idx, probs = learn.predict(img) |
| | |
| | return {learn.dls.vocab[i]: float(probs[i]) for i in range(len(probs))} |
| |
|
| | example_images = [ |
| | 'images/black.jpg', |
| | 'images/teddy.jpg', |
| | 'images/grizzly.jpg', |
| | 'images/black2.jpg', |
| | 'images/grizzly2.jpg' |
| | ] |
| |
|
| | iface = gr.Interface( |
| | fn=classify_bear, |
| | inputs=gr.Image(type='pil'), |
| | outputs=gr.Label(num_top_classes=3), |
| | examples=example_images, |
| | description="Classify bear images as grizzly, black or teddy:" |
| | ) |
| | iface.launch() |