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: Archie Tram. " intf = gr.Interface(fn=infer, inputs=inputs, outputs=outputs, examples=examples, title=title, description=description, article=article) intf.launch(inline=False)