def speclab(img): # initialize the model model = torch.hub.load('Nano1337/SpecLab', 'srdetect', force_reload=True) # for some reasons loads the model in src rather than demo model.eval() # preprocess image to be used as input transforms = A.Compose([ A.Normalize(mean=(0.5, 0.5, 0.5), std=(0.5, 0.5, 0.5)), ToTensorV2() ]) input = transforms(image=img)['image'] input = input.unsqueeze(0) # model prediction output = model(input) # overlay output onto original image img[output==255] = [0, 255, 0] return img # define app features and run title = "SpecLab Demo" description = "

Gradio demo for an ASPP model architecture trained on the SpecLab dataset. To use it, simply add your image, or click one of the examples to load them. Since this demo is run on CPU only, please allow additional time for processing.

" article = "

Github Repo

" css = "#0 {object-fit: contain;} #1 {object-fit: contain;}" demo = gr.Interface(fn=speclab, title=title, description=description, article=article, inputs=gr.Image(elem_id=0, show_label=False), outputs=gr.Image(elem_id=1, show_label=False), css=css, examples=examples, cache_examples=True, allow_flagging='never') demo.launch()