Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -58,18 +58,17 @@ def segment_everything(
|
|
58 |
withContours=withContours,)
|
59 |
|
60 |
print('Figure',fig)
|
61 |
-
|
62 |
bboxes = results[0].boxes.data
|
63 |
areas = (bboxes[:, 2] - bboxes[:, 0]) * (bboxes[:, 3] - bboxes[:, 1])
|
64 |
_, largest_indices = torch.topk(areas, 2)
|
65 |
largest_boxes = bboxes[largest_indices]
|
66 |
for i, box in enumerate(largest_boxes):
|
67 |
print(f"Largest Box {i+1}: {box.tolist()}")
|
68 |
-
|
69 |
-
|
70 |
fig, ax = plt.subplots(1)
|
71 |
ax.imshow(input)
|
72 |
-
|
73 |
for box in largest_boxes:
|
74 |
x1, y1, x2, y2 = box[:4]
|
75 |
rect = patches.Rectangle((x1, y1), x2-x1, y2-y1, linewidth=2, edgecolor='r', facecolor='none')
|
@@ -84,8 +83,9 @@ def segment_everything(
|
|
84 |
cropped_img = Image.open(buf).convert("RGBA")
|
85 |
cropped_img = cropped_img.resize((1024, 682))
|
86 |
print('Crop type',cropped_img)
|
|
|
87 |
|
88 |
-
return fig
|
89 |
|
90 |
title = "<center><strong><font size='8'>π Fast Segment Anything π€</font></strong></center>"
|
91 |
description = """ # π― Instructions for points mode """
|
@@ -93,9 +93,6 @@ examples = [["examples/sa_8776.jpg"], ["examples/sa_414.jpg"], ["examples/sa_130
|
|
93 |
["examples/sa_561.jpg"], ["examples/sa_192.jpg"], ["examples/sa_10039.jpg"], ["examples/sa_862.jpg"]]
|
94 |
default_example = examples[0]
|
95 |
|
96 |
-
cond_img_e = gr.Image(label="Input", value=default_example[0], type='pil')
|
97 |
-
segm_img_e = gr.Image(label="Segmented Image", interactive=False, type='pil')
|
98 |
-
|
99 |
input_size_slider = gr.components.Slider(minimum=512,maximum=1024,value=1024,step=64,label='Input_size',info='Our model was trained on a size of 1024')
|
100 |
|
101 |
css = "h1 { text-align: center } .about { text-align: justify; padding-left: 10%; padding-right: 10%; }"
|
@@ -108,8 +105,7 @@ demo = gr.Interface(
|
|
108 |
gr.Checkbox(value=True, label='withContours', info='draw the edges of the masks')
|
109 |
],
|
110 |
outputs = [
|
111 |
-
gr.Image(label="Segmented Image", interactive=False, type='pil')
|
112 |
-
gr.Image(label="Cropped Image", interactive=False, type='pil')
|
113 |
],
|
114 |
title = title,
|
115 |
description = description,
|
|
|
58 |
withContours=withContours,)
|
59 |
|
60 |
print('Figure',fig)
|
61 |
+
print('-----------')
|
62 |
bboxes = results[0].boxes.data
|
63 |
areas = (bboxes[:, 2] - bboxes[:, 0]) * (bboxes[:, 3] - bboxes[:, 1])
|
64 |
_, largest_indices = torch.topk(areas, 2)
|
65 |
largest_boxes = bboxes[largest_indices]
|
66 |
for i, box in enumerate(largest_boxes):
|
67 |
print(f"Largest Box {i+1}: {box.tolist()}")
|
68 |
+
print('-----------')
|
69 |
+
|
70 |
fig, ax = plt.subplots(1)
|
71 |
ax.imshow(input)
|
|
|
72 |
for box in largest_boxes:
|
73 |
x1, y1, x2, y2 = box[:4]
|
74 |
rect = patches.Rectangle((x1, y1), x2-x1, y2-y1, linewidth=2, edgecolor='r', facecolor='none')
|
|
|
83 |
cropped_img = Image.open(buf).convert("RGBA")
|
84 |
cropped_img = cropped_img.resize((1024, 682))
|
85 |
print('Crop type',cropped_img)
|
86 |
+
print('-----------')
|
87 |
|
88 |
+
return fig
|
89 |
|
90 |
title = "<center><strong><font size='8'>π Fast Segment Anything π€</font></strong></center>"
|
91 |
description = """ # π― Instructions for points mode """
|
|
|
93 |
["examples/sa_561.jpg"], ["examples/sa_192.jpg"], ["examples/sa_10039.jpg"], ["examples/sa_862.jpg"]]
|
94 |
default_example = examples[0]
|
95 |
|
|
|
|
|
|
|
96 |
input_size_slider = gr.components.Slider(minimum=512,maximum=1024,value=1024,step=64,label='Input_size',info='Our model was trained on a size of 1024')
|
97 |
|
98 |
css = "h1 { text-align: center } .about { text-align: justify; padding-left: 10%; padding-right: 10%; }"
|
|
|
105 |
gr.Checkbox(value=True, label='withContours', info='draw the edges of the masks')
|
106 |
],
|
107 |
outputs = [
|
108 |
+
gr.Image(label="Segmented Image", interactive=False, type='pil')
|
|
|
109 |
],
|
110 |
title = title,
|
111 |
description = description,
|