Spaces:
Running
Running
Commit
Β·
9fb1282
1
Parent(s):
77511e4
Update app.py
Browse files
app.py
CHANGED
|
@@ -55,6 +55,65 @@ blend_mask_base[80:244, 32:224] = 1
|
|
| 55 |
blend_mask_base = gaussian_filter(blend_mask_base, sigma=7)
|
| 56 |
|
| 57 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
def run_inference(target, source, slider, adv_slider, settings):
|
| 59 |
try:
|
| 60 |
source = np.array(source)
|
|
@@ -193,7 +252,37 @@ article = """
|
|
| 193 |
Demo is based of recent research from my Ph.D work. Results expects to be published in the coming months.
|
| 194 |
"""
|
| 195 |
|
| 196 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 197 |
[gradio.Image(shape=None, type="pil", label='Target'),
|
| 198 |
gradio.Image(shape=None, type="pil", label='Source'),
|
| 199 |
gradio.Slider(0, 100, value=100, label="Anonymization ratio (%)"),
|
|
@@ -208,5 +297,5 @@ iface = gradio.Interface(run_inference,
|
|
| 208 |
description=description,
|
| 209 |
examples=examples,
|
| 210 |
article=article,
|
| 211 |
-
layout="vertical")
|
| 212 |
-
|
|
|
|
| 55 |
blend_mask_base = gaussian_filter(blend_mask_base, sigma=7)
|
| 56 |
|
| 57 |
|
| 58 |
+
theme = gr.themes.Monochrome(
|
| 59 |
+
secondary_hue="emerald",
|
| 60 |
+
neutral_hue="teal",
|
| 61 |
+
).set(
|
| 62 |
+
body_background_fill='*primary_950',
|
| 63 |
+
body_background_fill_dark='*secondary_950',
|
| 64 |
+
body_text_color='*primary_50',
|
| 65 |
+
body_text_color_dark='*secondary_100',
|
| 66 |
+
body_text_color_subdued='*primary_300',
|
| 67 |
+
body_text_color_subdued_dark='*primary_300',
|
| 68 |
+
background_fill_primary='*primary_600',
|
| 69 |
+
background_fill_primary_dark='*primary_400',
|
| 70 |
+
background_fill_secondary='*primary_950',
|
| 71 |
+
background_fill_secondary_dark='*primary_950',
|
| 72 |
+
border_color_accent='*secondary_600',
|
| 73 |
+
border_color_primary='*secondary_50',
|
| 74 |
+
border_color_primary_dark='*secondary_50',
|
| 75 |
+
color_accent='*secondary_50',
|
| 76 |
+
color_accent_soft='*primary_500',
|
| 77 |
+
color_accent_soft_dark='*primary_500',
|
| 78 |
+
link_text_color='*secondary_950',
|
| 79 |
+
link_text_color_dark='*primary_50',
|
| 80 |
+
link_text_color_active='*primary_50',
|
| 81 |
+
link_text_color_active_dark='*primary_50',
|
| 82 |
+
link_text_color_hover='*primary_50',
|
| 83 |
+
link_text_color_hover_dark='*primary_50',
|
| 84 |
+
link_text_color_visited='*primary_50',
|
| 85 |
+
block_background_fill='*primary_950',
|
| 86 |
+
block_background_fill_dark='*primary_950',
|
| 87 |
+
block_border_color='*secondary_500',
|
| 88 |
+
block_border_color_dark='*secondary_500',
|
| 89 |
+
block_info_text_color='*primary_50',
|
| 90 |
+
block_info_text_color_dark='*primary_50',
|
| 91 |
+
block_label_background_fill='*primary_950',
|
| 92 |
+
block_label_background_fill_dark='*secondary_950',
|
| 93 |
+
block_label_border_color='*secondary_500',
|
| 94 |
+
block_label_border_color_dark='*secondary_500',
|
| 95 |
+
block_label_text_color='*secondary_500',
|
| 96 |
+
block_label_text_color_dark='*secondary_500',
|
| 97 |
+
block_title_background_fill='*primary_950',
|
| 98 |
+
panel_background_fill='*primary_950',
|
| 99 |
+
panel_border_color='*primary_950',
|
| 100 |
+
checkbox_background_color='*primary_950',
|
| 101 |
+
checkbox_background_color_dark='*primary_950',
|
| 102 |
+
checkbox_background_color_focus='*primary_950',
|
| 103 |
+
checkbox_border_color='*secondary_500',
|
| 104 |
+
input_background_fill='*primary_800',
|
| 105 |
+
input_background_fill_focus='*primary_950',
|
| 106 |
+
input_background_fill_hover='*secondary_950',
|
| 107 |
+
input_placeholder_color='*secondary_950',
|
| 108 |
+
slider_color='*primary_950',
|
| 109 |
+
slider_color_dark='*primary_950',
|
| 110 |
+
table_even_background_fill='*primary_800',
|
| 111 |
+
table_odd_background_fill='*primary_600',
|
| 112 |
+
button_primary_background_fill='*primary_800',
|
| 113 |
+
button_primary_background_fill_dark='*primary_800'
|
| 114 |
+
)
|
| 115 |
+
|
| 116 |
+
|
| 117 |
def run_inference(target, source, slider, adv_slider, settings):
|
| 118 |
try:
|
| 119 |
source = np.array(source)
|
|
|
|
| 252 |
Demo is based of recent research from my Ph.D work. Results expects to be published in the coming months.
|
| 253 |
"""
|
| 254 |
|
| 255 |
+
with gr.Blocks(theme=theme) as blk_demo:
|
| 256 |
+
gr.Markdown(value="# Face Dancer")
|
| 257 |
+
with gr.Row():
|
| 258 |
+
with gr.Column():
|
| 259 |
+
with gr.Box():
|
| 260 |
+
trg_in = gr.Image(type="pil", label='Target').style(height=300)
|
| 261 |
+
src_in = gr.Image(type="pil", label='Source').style(height=300)
|
| 262 |
+
with gr.Row():
|
| 263 |
+
b1 = gr.Button("Face Swap")
|
| 264 |
+
with gr.Row():
|
| 265 |
+
with gr.Accordion("Options", open=False):
|
| 266 |
+
chk_in = gr.CheckboxGroup(["Compare",
|
| 267 |
+
"Anonymize",
|
| 268 |
+
"Reconstruction Attack",
|
| 269 |
+
"Adversarial Defense"],
|
| 270 |
+
label="Mode",
|
| 271 |
+
info="Anonymize mode? "
|
| 272 |
+
"Apply reconstruction attack? "
|
| 273 |
+
"Apply defense against reconstruction attack?")
|
| 274 |
+
def_in = gr.Slider(0, 100, value=100,
|
| 275 |
+
label='Anonymization ratio (%)')
|
| 276 |
+
mrg_in = gr.Slider(0, 100, value=100,
|
| 277 |
+
label='Adversarial defense ratio (%)')
|
| 278 |
+
with gr.Column():
|
| 279 |
+
with gr.Box():
|
| 280 |
+
ano_out = gr.Image(type="pil", label='Output').style(height=300)
|
| 281 |
+
|
| 282 |
+
b1.click(run_inference, inputs=[trg_in, src_in, def_in, mrg_in, chk_in],
|
| 283 |
+
outputs=[ano_out])
|
| 284 |
+
|
| 285 |
+
"""iface = gradio.Interface(run_inference,
|
| 286 |
[gradio.Image(shape=None, type="pil", label='Target'),
|
| 287 |
gradio.Image(shape=None, type="pil", label='Source'),
|
| 288 |
gradio.Slider(0, 100, value=100, label="Anonymization ratio (%)"),
|
|
|
|
| 297 |
description=description,
|
| 298 |
examples=examples,
|
| 299 |
article=article,
|
| 300 |
+
layout="vertical")"""
|
| 301 |
+
blk_demo.launch()
|