Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -24,35 +24,6 @@ def image_objects(image):
|
|
| 24 |
pred = model(image)
|
| 25 |
pred_object_list = [str(i)+'_'+x['label'] for i, x in enumerate(pred)]
|
| 26 |
return gr.Dropdown.update(choices = pred_object_list, interactive = True)
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
def blurr_object(image, object, blur_strength):
|
| 31 |
-
image = img_resize(image)
|
| 32 |
-
|
| 33 |
-
object_number = int(object.split('_')[0])
|
| 34 |
-
mask_array = np.asarray(pred[object_number]['mask'])/255
|
| 35 |
-
image_array = np.asarray(image)
|
| 36 |
-
|
| 37 |
-
mask_array_three_channel = np.zeros_like(image_array)
|
| 38 |
-
mask_array_three_channel[:,:,0] = mask_array
|
| 39 |
-
mask_array_three_channel[:,:,1] = mask_array
|
| 40 |
-
mask_array_three_channel[:,:,2] = mask_array
|
| 41 |
-
|
| 42 |
-
segmented_image = image_array*mask_array_three_channel
|
| 43 |
-
|
| 44 |
-
blur_image = np.asarray(image.filter(ImageFilter.GaussianBlur(radius=blur_strength)))
|
| 45 |
-
mask_array_three_channel_invert = 1-mask_array_three_channel
|
| 46 |
-
blur_image_reverse_mask = blur_image*mask_array_three_channel_invert
|
| 47 |
-
|
| 48 |
-
#seg_out=image_array.astype(np.uint8)
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
blurred_output_image = Image.fromarray((blur_image_reverse_mask).astype(np.uint8)+segmented_image.astype(np.uint8))
|
| 52 |
-
for _ in range(int(blur_strength//2.5)):
|
| 53 |
-
blurred_output_image = blurred_output_image.filter(ImageFilter.SMOOTH_MORE)
|
| 54 |
-
return blurred_output_image
|
| 55 |
-
|
| 56 |
|
| 57 |
def get_seg(image, object):
|
| 58 |
image = img_resize(image)
|
|
@@ -94,30 +65,14 @@ with app:
|
|
| 94 |
### Input Image
|
| 95 |
""")
|
| 96 |
image_input = gr.Image(type="pil")
|
| 97 |
-
|
| 98 |
-
|
| 99 |
with gr.Column():
|
| 100 |
-
with gr.Row():
|
| 101 |
-
gr.Markdown(
|
| 102 |
-
"""
|
| 103 |
-
### Found Objects
|
| 104 |
-
""")
|
| 105 |
-
with gr.Row():
|
| 106 |
-
blur_slider = gr.Slider(minimum=0.5, maximum=10, value=3, label="Adject Blur Strength")
|
| 107 |
-
with gr.Row():
|
| 108 |
object_output = gr.Dropdown(label="Select Object From Dropdown")
|
| 109 |
-
|
| 110 |
|
| 111 |
with gr.Row():
|
| 112 |
-
with gr.Column():
|
| 113 |
-
gr.Markdown(
|
| 114 |
-
"""
|
| 115 |
-
### Blurred Image Output
|
| 116 |
-
""")
|
| 117 |
-
image_output = gr.Image()
|
| 118 |
with gr.Column():
|
| 119 |
seg_btn = gr.Button(label="Run")
|
| 120 |
-
gal1=gr.Gallery(type="filepath").style(grid=
|
| 121 |
|
| 122 |
seg_btn.click(get_seg, inputs=[image_input,object_output], outputs=gal1)
|
| 123 |
|
|
@@ -131,9 +86,4 @@ with app:
|
|
| 131 |
inputs=[image_input, object_output, blur_slider],
|
| 132 |
outputs=[image_output])
|
| 133 |
|
| 134 |
-
blur_slider.change(fn=blurr_object,
|
| 135 |
-
inputs=[image_input, object_output, blur_slider],
|
| 136 |
-
outputs=[image_output])
|
| 137 |
-
|
| 138 |
-
|
| 139 |
app.launch()
|
|
|
|
| 24 |
pred = model(image)
|
| 25 |
pred_object_list = [str(i)+'_'+x['label'] for i, x in enumerate(pred)]
|
| 26 |
return gr.Dropdown.update(choices = pred_object_list, interactive = True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
def get_seg(image, object):
|
| 29 |
image = img_resize(image)
|
|
|
|
| 65 |
### Input Image
|
| 66 |
""")
|
| 67 |
image_input = gr.Image(type="pil")
|
| 68 |
+
with gr.Row():
|
|
|
|
| 69 |
with gr.Column():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
object_output = gr.Dropdown(label="Select Object From Dropdown")
|
|
|
|
| 71 |
|
| 72 |
with gr.Row():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
with gr.Column():
|
| 74 |
seg_btn = gr.Button(label="Run")
|
| 75 |
+
gal1=gr.Gallery(type="filepath").style(grid=4)
|
| 76 |
|
| 77 |
seg_btn.click(get_seg, inputs=[image_input,object_output], outputs=gal1)
|
| 78 |
|
|
|
|
| 86 |
inputs=[image_input, object_output, blur_slider],
|
| 87 |
outputs=[image_output])
|
| 88 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
app.launch()
|