Spaces:
Runtime error
Runtime error
Commit
·
47010d6
1
Parent(s):
87c9d81
QOL improvements (hopefuly)
Browse files
app.py
CHANGED
|
@@ -171,7 +171,14 @@ def randomize_seed_fn(seed, randomize_seed):
|
|
| 171 |
torch.manual_seed(seed)
|
| 172 |
return seed
|
| 173 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 174 |
|
|
|
|
| 175 |
def get_example():
|
| 176 |
case = [
|
| 177 |
[
|
|
@@ -233,23 +240,18 @@ def get_example():
|
|
| 233 |
|
| 234 |
intro = """
|
| 235 |
<h1 style="font-weight: 1400; text-align: center; margin-bottom: 7px;">
|
| 236 |
-
LEDITS
|
| 237 |
</h1>
|
| 238 |
-
<
|
| 239 |
-
|
| 240 |
-
</h2>
|
| 241 |
-
|
| 242 |
-
<h3 style="font-weight: 600; text-align: center; margin-bottom: 7px;">
|
| 243 |
-
This is a demo for LEDITS - a combined approach for real image editing introduced in:
|
| 244 |
-
<a href="https://editing-images-project.hf.space/" style="text-decoration: underline;" target="_blank"> Project Page </a>
|
| 245 |
</h3>
|
| 246 |
-
|
| 247 |
-
|
|
|
|
| 248 |
|
| 249 |
<p style="font-size: 0.9rem; margin: 0rem; line-height: 1.2em; margin-top:1em">
|
| 250 |
-
For faster inference without waiting in queue, you may duplicate the space and upgrade to GPU in settings.
|
| 251 |
<a href="https://huggingface.co/spaces/editing-images/edit_friendly_ddpm_x_sega?duplicate=true">
|
| 252 |
-
<img style="margin-top: 0em; margin-bottom: 0em" src="
|
| 253 |
<p/>"""
|
| 254 |
|
| 255 |
help_text = """
|
|
@@ -388,72 +390,73 @@ with gr.Blocks(css="style.css") as demo:
|
|
| 388 |
)
|
| 389 |
# caption_button = gr.Button("Caption Image")
|
| 390 |
# with gr.TabItem('2. Add SEGA edit concepts', id=1):
|
| 391 |
-
|
| 392 |
-
|
| 393 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 394 |
with gr.Column(scale=3, min_width=100):
|
| 395 |
-
|
| 396 |
-
|
| 397 |
-
|
| 398 |
-
|
| 399 |
-
|
| 400 |
-
|
| 401 |
with gr.Column(scale=1, min_width=100):
|
| 402 |
-
|
| 403 |
-
|
| 404 |
-
|
| 405 |
-
|
| 406 |
-
|
| 407 |
-
# step=0.5, interactive=True)
|
| 408 |
with gr.Column(scale=1, min_width=100):
|
| 409 |
-
|
| 410 |
-
|
| 411 |
-
|
| 412 |
-
|
| 413 |
-
|
| 414 |
-
with gr.
|
| 415 |
-
|
| 416 |
-
label="Edit Concept",
|
| 417 |
-
show_label=False,
|
| 418 |
-
max_lines=1,
|
| 419 |
-
placeholder="Enter your 2st edit prompt",
|
| 420 |
-
)
|
| 421 |
-
with gr.Column(scale=1, min_width=100):
|
| 422 |
-
neg_guidance_2 = gr.Checkbox(
|
| 423 |
-
label='Negative Guidance',visible=True)
|
| 424 |
-
# guidnace_scale_2 = gr.Slider(label='Concept Guidance Scale', minimum=1, maximum=30,
|
| 425 |
-
# value=DEFAULT_SEGA_CONCEPT_GUIDANCE_SCALE,
|
| 426 |
-
# step=0.5, interactive=True)
|
| 427 |
-
with gr.Column(scale=1, min_width=100):
|
| 428 |
-
add_2 = gr.Button('Add')
|
| 429 |
-
|
| 430 |
-
# 3rd SEGA concept
|
| 431 |
-
with gr.Row(visible=False).style(equal_height=True) as row3:
|
| 432 |
-
with gr.Column(scale=3, min_width=100):
|
| 433 |
-
edit_concept_3 = gr.Textbox(
|
| 434 |
-
label="Edit Concept",
|
| 435 |
-
show_label=False,
|
| 436 |
-
max_lines=1,
|
| 437 |
-
placeholder="Enter your 3rd edit prompt",
|
| 438 |
-
)
|
| 439 |
-
with gr.Column(scale=1, min_width=100):
|
| 440 |
-
neg_guidance_3 = gr.Checkbox(
|
| 441 |
-
label='Negative Guidance',visible=True)
|
| 442 |
-
# guidnace_scale_3 = gr.Slider(label='Concept Guidance Scale', minimum=1, maximum=30,
|
| 443 |
-
# value=DEFAULT_SEGA_CONCEPT_GUIDANCE_SCALE,
|
| 444 |
-
# step=0.5, interactive=True)
|
| 445 |
-
with gr.Column(scale=1, min_width=100):
|
| 446 |
-
add_3 = gr.Button('Add')
|
| 447 |
-
|
| 448 |
-
|
| 449 |
-
|
| 450 |
-
|
| 451 |
-
with gr.Row().style(mobile_collapse=False, equal_height=True):
|
| 452 |
-
add_concept_button = gr.Button("+")
|
| 453 |
|
| 454 |
|
| 455 |
with gr.Row():
|
| 456 |
-
run_button = gr.Button("Edit", visible=True)
|
| 457 |
|
| 458 |
|
| 459 |
with gr.Accordion("Advanced Options", open=False):
|
|
@@ -506,7 +509,7 @@ with gr.Blocks(css="style.css") as demo:
|
|
| 506 |
# inputs = [input_image],
|
| 507 |
# outputs = [tar_prompt]
|
| 508 |
# )
|
| 509 |
-
|
| 510 |
add_1.click(fn = update_display_concept_1, inputs=[add_1, edit_concept_1, neg_guidance_1], outputs=[box1, concept_1, concept_1, edit_concept_1, guidnace_scale_1,neg_guidance_1, add_1])
|
| 511 |
add_2.click(fn = update_display_concept_2, inputs=[add_2, edit_concept_2, neg_guidance_2], outputs=[box2, concept_2, concept_2, edit_concept_2, guidnace_scale_2,neg_guidance_2, add_2])
|
| 512 |
add_3.click(fn = update_display_concept_3, inputs=[add_3, edit_concept_3, neg_guidance_3], outputs=[box3, concept_3, concept_3, edit_concept_3, guidnace_scale_3,neg_guidance_3, add_3])
|
|
|
|
| 171 |
torch.manual_seed(seed)
|
| 172 |
return seed
|
| 173 |
|
| 174 |
+
def update_label(check_negative):
|
| 175 |
+
if(check_negative):
|
| 176 |
+
return gr.update(value="Remove")
|
| 177 |
+
else:
|
| 178 |
+
return gr.update(value="Include")
|
| 179 |
+
|
| 180 |
|
| 181 |
+
|
| 182 |
def get_example():
|
| 183 |
case = [
|
| 184 |
[
|
|
|
|
| 240 |
|
| 241 |
intro = """
|
| 242 |
<h1 style="font-weight: 1400; text-align: center; margin-bottom: 7px;">
|
| 243 |
+
LEDITS - Pipeline for editing images
|
| 244 |
</h1>
|
| 245 |
+
<h3 style="font-weight: 600; text-align: center;">
|
| 246 |
+
Real Image Latent Editing with Edit Friendly DDPM and Semantic Guidance
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 247 |
</h3>
|
| 248 |
+
<h4 style="text-align: center; margin-bottom: 7px;">
|
| 249 |
+
<a href="https://editing-images-project.hf.space/" style="text-decoration: underline;" target="_blank">if(if(egativePage</a> | <a href="#" style="text-decoration: underline;" target="_blank">ArXiv</a>
|
| 250 |
+
</h4>
|
| 251 |
|
| 252 |
<p style="font-size: 0.9rem; margin: 0rem; line-height: 1.2em; margin-top:1em">
|
|
|
|
| 253 |
<a href="https://huggingface.co/spaces/editing-images/edit_friendly_ddpm_x_sega?duplicate=true">
|
| 254 |
+
<img style="margin-top: 0em; margin-bottom: 0em" src="bit.ly/3CWLGkA" alt="Duplicate Space"></a>
|
| 255 |
<p/>"""
|
| 256 |
|
| 257 |
help_text = """
|
|
|
|
| 390 |
)
|
| 391 |
# caption_button = gr.Button("Caption Image")
|
| 392 |
# with gr.TabItem('2. Add SEGA edit concepts', id=1):
|
| 393 |
+
with gr.Box():
|
| 394 |
+
intro_segs = gr.Markdown("Add/Remove New Concepts to your Image")
|
| 395 |
+
# 1st SEGA concept
|
| 396 |
+
with gr.Row().style(mobile_collapse=False, equal_height=True):
|
| 397 |
+
with gr.Column(scale=3, min_width=100):
|
| 398 |
+
edit_concept_1 = gr.Textbox(
|
| 399 |
+
label="Edit Concept",
|
| 400 |
+
show_label=False,
|
| 401 |
+
max_lines=1, value="",
|
| 402 |
+
placeholder="E.g.: Sunglasses",
|
| 403 |
+
)
|
| 404 |
+
with gr.Column(scale=1, min_width=100):
|
| 405 |
+
neg_guidance_1 = gr.Checkbox(
|
| 406 |
+
label='Remove Concept?')
|
| 407 |
+
|
| 408 |
+
# guidnace_scale_1 = gr.Slider(label='Concept Guidance Scale', minimum=1, maximum=30,
|
| 409 |
+
# value=DEFAULT_SEGA_CONCEPT_GUIDANCE_SCALE,
|
| 410 |
+
# step=0.5, interactive=True)
|
| 411 |
+
with gr.Column(scale=1, min_width=100):
|
| 412 |
+
|
| 413 |
+
add_1 = gr.Button('Include')
|
| 414 |
+
|
| 415 |
+
# 2nd SEGA concept
|
| 416 |
+
with gr.Row(visible=False).style(equal_height=True) as row2:
|
| 417 |
+
with gr.Column(scale=3, min_width=100):
|
| 418 |
+
edit_concept_2 = gr.Textbox(
|
| 419 |
+
label="Edit Concept",
|
| 420 |
+
show_label=False,
|
| 421 |
+
max_lines=1,
|
| 422 |
+
placeholder="E.g.: Realistic",
|
| 423 |
+
)
|
| 424 |
+
with gr.Column(scale=1, min_width=100):
|
| 425 |
+
neg_guidance_2 = gr.Checkbox(
|
| 426 |
+
label='Remove Concept?',visible=True)
|
| 427 |
+
# guidnace_scale_2 = gr.Slider(label='Concept Guidance Scale', minimum=1, maximum=30,
|
| 428 |
+
# value=DEFAULT_SEGA_CONCEPT_GUIDANCE_SCALE,
|
| 429 |
+
# step=0.5, interactive=True)
|
| 430 |
+
with gr.Column(scale=1, min_width=100):
|
| 431 |
+
add_2 = gr.Button('Include')
|
| 432 |
+
|
| 433 |
+
# 3rd SEGA concept
|
| 434 |
+
with gr.Row(visible=False).style(equal_height=True) as row3:
|
| 435 |
with gr.Column(scale=3, min_width=100):
|
| 436 |
+
edit_concept_3 = gr.Textbox(
|
| 437 |
+
label="Edit Concept",
|
| 438 |
+
show_label=False,
|
| 439 |
+
max_lines=1,
|
| 440 |
+
placeholder="E.g.: orange",
|
| 441 |
+
)
|
| 442 |
with gr.Column(scale=1, min_width=100):
|
| 443 |
+
neg_guidance_3 = gr.Checkbox(
|
| 444 |
+
label='Remove Concept?',visible=True)
|
| 445 |
+
# guidnace_scale_3 = gr.Slider(label='Concept Guidance Scale', minimum=1, maximum=30,
|
| 446 |
+
# value=DEFAULT_SEGA_CONCEPT_GUIDANCE_SCALE,
|
| 447 |
+
# step=0.5, interactive=True)
|
|
|
|
| 448 |
with gr.Column(scale=1, min_width=100):
|
| 449 |
+
add_3 = gr.Button('Include')
|
| 450 |
+
|
| 451 |
+
|
| 452 |
+
|
| 453 |
+
|
| 454 |
+
with gr.Row().style(mobile_collapse=False, equal_height=True):
|
| 455 |
+
add_concept_button = gr.Button("+1 concept")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 456 |
|
| 457 |
|
| 458 |
with gr.Row():
|
| 459 |
+
run_button = gr.Button("Edit your image!", visible=True)
|
| 460 |
|
| 461 |
|
| 462 |
with gr.Accordion("Advanced Options", open=False):
|
|
|
|
| 509 |
# inputs = [input_image],
|
| 510 |
# outputs = [tar_prompt]
|
| 511 |
# )
|
| 512 |
+
neg_guidance_1.change(fn = update_label, inputs=[neg_guidance_1], outputs=[add_1])
|
| 513 |
add_1.click(fn = update_display_concept_1, inputs=[add_1, edit_concept_1, neg_guidance_1], outputs=[box1, concept_1, concept_1, edit_concept_1, guidnace_scale_1,neg_guidance_1, add_1])
|
| 514 |
add_2.click(fn = update_display_concept_2, inputs=[add_2, edit_concept_2, neg_guidance_2], outputs=[box2, concept_2, concept_2, edit_concept_2, guidnace_scale_2,neg_guidance_2, add_2])
|
| 515 |
add_3.click(fn = update_display_concept_3, inputs=[add_3, edit_concept_3, neg_guidance_3], outputs=[box3, concept_3, concept_3, edit_concept_3, guidnace_scale_3,neg_guidance_3, add_3])
|