Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -43,8 +43,35 @@ def blurr_object(image, object, blur_strength):
|
|
43 |
blur_image = np.asarray(image.filter(ImageFilter.GaussianBlur(radius=blur_strength)))
|
44 |
mask_array_three_channel_invert = 1-mask_array_three_channel
|
45 |
blur_image_reverse_mask = blur_image*mask_array_three_channel_invert
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
seg_box=[]
|
47 |
-
for i in range(
|
48 |
object_number = int(object.split('i')[0])
|
49 |
mask_array = np.asarray(pred[object_number]['mask'])/255
|
50 |
image_array = np.asarray(image)
|
@@ -56,14 +83,11 @@ def blurr_object(image, object, blur_strength):
|
|
56 |
|
57 |
segmented_image = image_array*mask_array_three_channel
|
58 |
seg_out=segmented_image.astype(np.uint8)
|
59 |
-
seg_box.append(seg_out)
|
60 |
-
|
|
|
|
|
61 |
|
62 |
-
|
63 |
-
blurred_output_image = Image.fromarray((blur_image_reverse_mask).astype(np.uint8)+segmented_image.astype(np.uint8))
|
64 |
-
for _ in range(int(blur_strength//2.5)):
|
65 |
-
blurred_output_image = blurred_output_image.filter(ImageFilter.SMOOTH_MORE)
|
66 |
-
return blurred_output_image, seg_box
|
67 |
|
68 |
app = gr.Blocks()
|
69 |
|
@@ -104,8 +128,12 @@ with app:
|
|
104 |
""")
|
105 |
image_output = gr.Image()
|
106 |
with gr.Column():
|
|
|
107 |
gal1=gr.Gallery(type="filepath").style(grid=10)
|
108 |
|
|
|
|
|
|
|
109 |
image_input.change(fn=image_objects,
|
110 |
inputs=image_input,
|
111 |
outputs=object_output
|
@@ -113,11 +141,11 @@ with app:
|
|
113 |
|
114 |
object_output.change(fn=blurr_object,
|
115 |
inputs=[image_input, object_output, blur_slider],
|
116 |
-
outputs=[image_output
|
117 |
|
118 |
blur_slider.change(fn=blurr_object,
|
119 |
inputs=[image_input, object_output, blur_slider],
|
120 |
-
outputs=[image_output
|
121 |
|
122 |
|
123 |
app.launch()
|
|
|
43 |
blur_image = np.asarray(image.filter(ImageFilter.GaussianBlur(radius=blur_strength)))
|
44 |
mask_array_three_channel_invert = 1-mask_array_three_channel
|
45 |
blur_image_reverse_mask = blur_image*mask_array_three_channel_invert
|
46 |
+
|
47 |
+
#seg_out=image_array.astype(np.uint8)
|
48 |
+
|
49 |
+
|
50 |
+
blurred_output_image = Image.fromarray((blur_image_reverse_mask).astype(np.uint8)+segmented_image.astype(np.uint8))
|
51 |
+
for _ in range(int(blur_strength//2.5)):
|
52 |
+
blurred_output_image = blurred_output_image.filter(ImageFilter.SMOOTH_MORE)
|
53 |
+
return blurred_output_image
|
54 |
+
|
55 |
+
|
56 |
+
def get_seg(image, object):
|
57 |
+
image = img_resize(image)
|
58 |
+
|
59 |
+
object_number = int(object.split('_')[0])
|
60 |
+
mask_array = np.asarray(pred[object_number]['mask'])/255
|
61 |
+
image_array = np.asarray(image)
|
62 |
+
|
63 |
+
mask_array_three_channel = np.zeros_like(image_array)
|
64 |
+
mask_array_three_channel[:,:,0] = mask_array
|
65 |
+
mask_array_three_channel[:,:,1] = mask_array
|
66 |
+
mask_array_three_channel[:,:,2] = mask_array
|
67 |
+
|
68 |
+
segmented_image = image_array*mask_array_three_channel
|
69 |
+
|
70 |
+
#blur_image = np.asarray(image.filter(ImageFilter.GaussianBlur(radius=blur_strength)))
|
71 |
+
mask_array_three_channel_invert = 1-mask_array_three_channel
|
72 |
+
#blur_image_reverse_mask = blur_image*mask_array_three_channel_invert
|
73 |
seg_box=[]
|
74 |
+
for i in range(len(object)):
|
75 |
object_number = int(object.split('i')[0])
|
76 |
mask_array = np.asarray(pred[object_number]['mask'])/255
|
77 |
image_array = np.asarray(image)
|
|
|
83 |
|
84 |
segmented_image = image_array*mask_array_three_channel
|
85 |
seg_out=segmented_image.astype(np.uint8)
|
86 |
+
seg_box.append(seg_out)
|
87 |
+
|
88 |
+
return(seg_box)
|
89 |
+
|
90 |
|
|
|
|
|
|
|
|
|
|
|
91 |
|
92 |
app = gr.Blocks()
|
93 |
|
|
|
128 |
""")
|
129 |
image_output = gr.Image()
|
130 |
with gr.Column():
|
131 |
+
seg_btn.click(label="Run")
|
132 |
gal1=gr.Gallery(type="filepath").style(grid=10)
|
133 |
|
134 |
+
seg_btn.click(get_seg, inputs=[image_input,object_output], outputs=gal1)
|
135 |
+
|
136 |
+
|
137 |
image_input.change(fn=image_objects,
|
138 |
inputs=image_input,
|
139 |
outputs=object_output
|
|
|
141 |
|
142 |
object_output.change(fn=blurr_object,
|
143 |
inputs=[image_input, object_output, blur_slider],
|
144 |
+
outputs=[image_output])
|
145 |
|
146 |
blur_slider.change(fn=blurr_object,
|
147 |
inputs=[image_input, object_output, blur_slider],
|
148 |
+
outputs=[image_output])
|
149 |
|
150 |
|
151 |
app.launch()
|