| |
|
|
| |
| __all__ = ['model_path', 'predictor', 'labels', 'image', 'label', 'title', 'description', 'examples', 'interpretation', |
| 'enable_queue', 'intf', 'is_cat', 'classify_image'] |
|
|
| |
| from fastai.vision.all import * |
| import gradio as gr |
|
|
| |
| def is_cat(x): |
| return x[0].isupper() |
|
|
| |
| model_path = 'dog_cat.pkl' |
| predictor = load_learner(Path(model_path)) |
|
|
| |
| labels = predictor.dls.vocab |
| labels |
|
|
| |
| def classify_image(img): |
| img = PILImage.create(img) |
| pred, pred_idx, probs = predictor.predict(img) |
| return dict(zip(labels, map(float, probs))) |
| |
|
|
| |
| image = gr.inputs.Image(shape=(192, 192)) |
| label = gr.outputs.Label() |
|
|
| title = 'Is The Cat?' |
| description = 'a sample of deploying model to gradio' |
| examples = ['dog_1.jpeg', 'cat_01.jpeg', 'elephant.jpeg'] |
| interpretation = 'default' |
| enable_queue = True |
|
|
| intf = gr.Interface( |
| fn=classify_image, inputs=image, outputs=label, |
| title=title, description=description, examples=examples,) |
| intf.launch(share=True, inline=False) |
|
|