File size: 1,103 Bytes
c1a13fc 09a1107 c1a13fc d9ed304 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
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)
# gradio doesn't support tensors, so converting to float
labels_probs = {labels[i]: float(probs[i]) for i, _ in enumerate(labels)}
return labels_probs
# get the inputs
inputs = gr.inputs.Image(shape=(192, 192))
# the app outputs two segmented images
outputs = gr.outputs.Label(num_top_classes=3)
EXAMPLES_PATH = Path('./examples')
examples = [f'{EXAMPLES_PATH}/{f.name}' for f in EXAMPLES_PATH.iterdir()]
# it's good practice to pass examples, description and a title to guide users
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)
|