Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -90,13 +90,11 @@ def transparent(fg, bg, alpha_factor):
|
|
| 90 |
|
| 91 |
return background
|
| 92 |
|
| 93 |
-
def show_img(
|
| 94 |
|
| 95 |
idx = target_list_all.index(label)
|
| 96 |
|
| 97 |
-
|
| 98 |
-
foreground = Image.open(mask_path).convert("RGBA")
|
| 99 |
-
|
| 100 |
background = bg.convert("RGBA")
|
| 101 |
|
| 102 |
foreground.putalpha(int(255 * alpha))
|
|
@@ -209,15 +207,15 @@ with gr.Blocks(title=title) as app:
|
|
| 209 |
dropdown = gr.Dropdown(choices=target_list_all, label="Select Label", value="All")
|
| 210 |
slider = gr.Slider(minimum=0, maximum=1, value=0.4, label="Alpha Factor")
|
| 211 |
|
| 212 |
-
|
| 213 |
-
|
| 214 |
|
| 215 |
gr.Button("1) Generate Masks").click(fn=inference,
|
| 216 |
inputs=[input_img],
|
| 217 |
-
outputs=[img,
|
| 218 |
|
| 219 |
submit_transparent_img = gr.Button("2) Generate Transparent Mask (with Alpha Factor)")
|
| 220 |
-
submit_transparent_img.click(fn=show_img, inputs=[
|
| 221 |
|
| 222 |
|
| 223 |
app.launch()
|
|
|
|
| 90 |
|
| 91 |
return background
|
| 92 |
|
| 93 |
+
def show_img(mask_images, label, bg, alpha):
|
| 94 |
|
| 95 |
idx = target_list_all.index(label)
|
| 96 |
|
| 97 |
+
foreground = mask_images[idx].convert("RGBA")
|
|
|
|
|
|
|
| 98 |
background = bg.convert("RGBA")
|
| 99 |
|
| 100 |
foreground.putalpha(int(255 * alpha))
|
|
|
|
| 207 |
dropdown = gr.Dropdown(choices=target_list_all, label="Select Label", value="All")
|
| 208 |
slider = gr.Slider(minimum=0, maximum=1, value=0.4, label="Alpha Factor")
|
| 209 |
|
| 210 |
+
mask_state = gr.State()
|
| 211 |
+
background_state = gr.State()
|
| 212 |
|
| 213 |
gr.Button("1) Generate Masks").click(fn=inference,
|
| 214 |
inputs=[input_img],
|
| 215 |
+
outputs=[img, mask_state, background_state])
|
| 216 |
|
| 217 |
submit_transparent_img = gr.Button("2) Generate Transparent Mask (with Alpha Factor)")
|
| 218 |
+
submit_transparent_img.click(fn=show_img, inputs=[mask_state, dropdown, background_state, slider], outputs=[transparent_img])
|
| 219 |
|
| 220 |
|
| 221 |
app.launch()
|