| from fastai.vision.all import * |
| import gradio as gr |
|
|
| def get_x(): return _ |
| def get_y(): return _ |
|
|
| learn = load_learner("export.pkl") |
|
|
| labels = learn.dls.vocab |
| def infer(img): |
| img = PILImage.create(img) |
| _pred, _pred_w_idx, probs = learn.predict(img) |
| |
| labels_probs = {labels[i]: float(probs[i]) for i, _ in enumerate(labels)} |
| return labels_probs |
|
|
| |
| inputs = gr.inputs.Image(shape=(192, 192)) |
|
|
| |
| outputs = gr.outputs.Label(num_top_classes=3) |
|
|
| EXAMPLES_PATH = Path('./examples') |
| examples = [f'{EXAMPLES_PATH}/{f.name}' for f in EXAMPLES_PATH.iterdir()] |
|
|
| |
| title = 'Multiple Object Detector' |
| description = 'This app detects objects that appear in the image' |
| article = "Author: <a href=\"https://huggingface.co/archietram\">Archie Tram</a>. " |
| intf = gr.Interface(fn=infer, inputs=inputs, outputs=outputs, examples=examples, title=title, description=description, article=article) |
| intf.launch(inline=False) |
|
|