Commit ·
3f407e8
1
Parent(s): b7e96b9
Allow for multiple objects
Browse files12 unmodified lines13141516171819202122232425262728293031329 unmodified lines42434445464748495012 unmodified linesmodel = Model()def run(image_path, threshold):image = Image.open(image_path).convert('RGB')canvas = Image.new('RGB', image.size, (0, 0, 0))# We copy the image that and fill it with black, to get the dimensionsrgb = np.array(canvas)masks = model(image_path, threshold, 1)mask = masks[0]fg = mask > 0.5rgb[fg] = 255img = Image.fromarray(rgb)return imgTITLE = 'MaskCut'9 unmodified linesmaximum=1,value=0.15,step=0.01),],outputs=gr.Image(label='Output image', type="pil"),examples=[[path.as_posix(), 0.15] for path in paths],title=TITLE,description=DESCRIPTION)demo.queue(concurrency_count=3, api_open=True)12 unmodified lines131415161718192021222324252627282930319 unmodified lines41424344454647484950515253545512 unmodified linesmodel = Model()def run(image_path, threshold, num_objects):image = Image.open(image_path).convert('RGB')canvas = Image.new('RGB', image.size, (0, 0, 0))# We copy the image that and fill it with black, to get the dimensionsrgb = np.array(canvas)masks = model(image_path, threshold, num_objects)for mask in masks:fg = mask > 0.5rgb[fg] = 255return Image.fromarray(rgb)TITLE = 'MaskCut'9 unmodified linesmaximum=1,value=0.15,step=0.01),gr.Slider(label='Number of objects in the image',minimum=1,maximum=10,value=1,step=1)],outputs=gr.Image(label='Output image', type="pil"),examples=[[path.as_posix(), 0.15, 2] for path in paths],title=TITLE,description=DESCRIPTION)demo.queue(concurrency_count=3, api_open=True)
app.py+13-8