Spaces:
Runtime error
Runtime error
Update app.py
Browse files21 unmodified lines2223242526272811 unmodified lines404142434445464748495051523 unmodified lines5657585960616216 unmodified lines7980818283848521 unmodified linesconf_threshold=0.25,better_quality=False,use_retina=True,text="",wider=False,mask_random_color=True,):11 unmodified linesconf=conf_threshold,imgsz=input_size,)if len(text) > 0:results = format_results(results[0], 0)annotations, _ = text_prompt(results, text, input, device=device, wider=wider)annotations = np.array([annotations])else:annotations = results[0].masks.datafig = fast_process(annotations=annotations,image=input,device=device,3 unmodified linesbbox=None,use_retina=use_retina,withContours=withContours,)return figtitle = "<center><strong><font size='8'>π Fast Segment Anything π€</font></strong></center>"description = """ # π― Instructions for points mode """16 unmodified linesgr.Checkbox(value=True, label='withContours', info='draw the edges of the masks')],outputs = [gr.Image(label="Segmented Image", interactive=False, type='pil')],title = title,description = description,21 unmodified lines22232425262711 unmodified lines39404142434445463 unmodified lines5051525354555657585960616263646566676869707172737475767778798016 unmodified lines97989910010110210310421 unmodified linesconf_threshold=0.25,better_quality=False,use_retina=True,wider=False,mask_random_color=True,):11 unmodified linesconf=conf_threshold,imgsz=input_size,)annotations = results[0].masks.datafig = fast_process(annotations=annotations,image=input,device=device,3 unmodified linesbbox=None,use_retina=use_retina,withContours=withContours,)bboxes = results[0].boxes.dataareas = (bboxes[:, 2] - bboxes[:, 0]) * (bboxes[:, 3] - bboxes[:, 1])_, largest_indices = torch.topk(areas, 2)largest_boxes = bboxes[largest_indices]for i, box in enumerate(largest_boxes):print(f"Largest Box {i+1}: {box.tolist()}")fig, ax = plt.subplots(1)ax.imshow(image)for box in largest_boxes:x1, y1, x2, y2 = box[:4]rect = patches.Rectangle((x1, y1), x2-x1, y2-y1, linewidth=2, edgecolor='r', facecolor='none')ax.add_patch(rect)ax.axis('off')buf = io.BytesIO()plt.savefig(buf, format='png', bbox_inches='tight', pad_inches=0)plt.close(fig)buf.seek(0)cropped_image = Image.open(buf)return fig,cropped_imagetitle = "<center><strong><font size='8'>π Fast Segment Anything π€</font></strong></center>"description = """ # π― Instructions for points mode """16 unmodified linesgr.Checkbox(value=True, label='withContours', info='draw the edges of the masks')],outputs = [gr.Image(label="Segmented Image", interactive=False, type='pil'),gr.Image(label="Cropped Image", interactive=False, type='pil')],title = title,description = description,
app.py+28-9