Spaces:
Runtime error
Runtime error
Linoy Tsaban
commited on
Commit
·
88f076f
1
Parent(s):
774cc5f
Update app.py
Browse fileschanged sega edit concepts processing to accepts multiple concepts
app.py
CHANGED
|
@@ -90,11 +90,23 @@ def edit(input_image,
|
|
| 90 |
pure_ddpm_out = sample(wt, zs, wts, prompt_tar=tar_prompt,
|
| 91 |
cfg_scale_tar=tar_cfg_scale, skip=skip)
|
| 92 |
yield pure_ddpm_out, pure_ddpm_out
|
| 93 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
editing_args = dict(
|
| 95 |
-
editing_prompt =
|
| 96 |
-
reverse_editing_direction =
|
| 97 |
-
edit_warmup_steps=
|
| 98 |
edit_guidance_scale=[sega_edit_guidance],
|
| 99 |
edit_threshold=[.93],
|
| 100 |
edit_momentum_scale=0.5,
|
|
@@ -106,8 +118,10 @@ def edit(input_image,
|
|
| 106 |
use_ddpm=True, wts=wts, zs=zs[skip:], **editing_args)
|
| 107 |
yield pure_ddpm_out,sega_out.images[0]
|
| 108 |
|
| 109 |
-
|
| 110 |
-
# demo
|
|
|
|
|
|
|
| 111 |
intro = """
|
| 112 |
<h1 style="font-weight: 1400; text-align: center; margin-bottom: 7px;">
|
| 113 |
Edit Friendly DDPM X Semantic Guidance: Editing Real Images
|
|
@@ -122,9 +136,8 @@ with gr.Blocks() as demo:
|
|
| 122 |
|
| 123 |
with gr.Row():
|
| 124 |
src_prompt = gr.Textbox(lines=1, label="Source Prompt", interactive=True)
|
| 125 |
-
#edit
|
| 126 |
tar_prompt = gr.Textbox(lines=1, label="Target Prompt", interactive=True)
|
| 127 |
-
edit_concept = gr.Textbox(lines=1, label="SEGA Edit
|
| 128 |
|
| 129 |
with gr.Row():
|
| 130 |
input_image = gr.Image(label="Input Image", interactive=True)
|
|
@@ -137,14 +150,7 @@ with gr.Blocks() as demo:
|
|
| 137 |
with gr.Row():
|
| 138 |
with gr.Column(scale=1, min_width=100):
|
| 139 |
generate_button = gr.Button("Run")
|
| 140 |
-
# with gr.Column(scale=1, min_width=100):
|
| 141 |
-
# reset_button = gr.Button("Reset")
|
| 142 |
-
# with gr.Column(scale=3):
|
| 143 |
-
# instruction = gr.Textbox(lines=1, label="Edit Instruction", interactive=True)
|
| 144 |
-
|
| 145 |
-
|
| 146 |
|
| 147 |
-
# with gr.Row():
|
| 148 |
with gr.Accordion("Advanced Options", open=False):
|
| 149 |
with gr.Row():
|
| 150 |
#inversion
|
|
@@ -157,8 +163,8 @@ with gr.Blocks() as demo:
|
|
| 157 |
|
| 158 |
# edit
|
| 159 |
sega_edit_guidance = gr.Slider(value=10, label=f"SEGA Edit Guidance Scale", interactive=True)
|
| 160 |
-
warm_up = gr.Number(value=1, label=f"SEGA Warm-up Steps", interactive=True)
|
| 161 |
-
neg_guidance = gr.Checkbox(label="SEGA Negative Guidance")
|
| 162 |
|
| 163 |
|
| 164 |
# gr.Markdown(help_text)
|
|
@@ -173,9 +179,9 @@ with gr.Blocks() as demo:
|
|
| 173 |
skip,
|
| 174 |
tar_cfg_scale,
|
| 175 |
edit_concept,
|
| 176 |
-
sega_edit_guidance
|
| 177 |
-
warm_up,
|
| 178 |
-
neg_guidance
|
| 179 |
],
|
| 180 |
outputs=[ddpm_edited_image, sega_edited_image],
|
| 181 |
)
|
|
|
|
| 90 |
pure_ddpm_out = sample(wt, zs, wts, prompt_tar=tar_prompt,
|
| 91 |
cfg_scale_tar=tar_cfg_scale, skip=skip)
|
| 92 |
yield pure_ddpm_out, pure_ddpm_out
|
| 93 |
+
|
| 94 |
+
# SEGA
|
| 95 |
+
edit_concepts = edit_concept.split(",")
|
| 96 |
+
neg_guidance =[]
|
| 97 |
+
for edit_concept in edit_concepts:
|
| 98 |
+
if edit_concept.startswith("-"):
|
| 99 |
+
neg_guidance.append(True)
|
| 100 |
+
else:
|
| 101 |
+
neg_guidance.append(False)
|
| 102 |
+
edit_concepts = [concept.strip("+|-") for concept in edit_concepts]
|
| 103 |
+
|
| 104 |
+
default_warm_up = [1]*len(edit_concepts)
|
| 105 |
+
|
| 106 |
editing_args = dict(
|
| 107 |
+
editing_prompt = edit_concepts,
|
| 108 |
+
reverse_editing_direction = neg_guidance,
|
| 109 |
+
edit_warmup_steps=default_warm_up,
|
| 110 |
edit_guidance_scale=[sega_edit_guidance],
|
| 111 |
edit_threshold=[.93],
|
| 112 |
edit_momentum_scale=0.5,
|
|
|
|
| 118 |
use_ddpm=True, wts=wts, zs=zs[skip:], **editing_args)
|
| 119 |
yield pure_ddpm_out,sega_out.images[0]
|
| 120 |
|
| 121 |
+
########
|
| 122 |
+
# demo #
|
| 123 |
+
########
|
| 124 |
+
|
| 125 |
intro = """
|
| 126 |
<h1 style="font-weight: 1400; text-align: center; margin-bottom: 7px;">
|
| 127 |
Edit Friendly DDPM X Semantic Guidance: Editing Real Images
|
|
|
|
| 136 |
|
| 137 |
with gr.Row():
|
| 138 |
src_prompt = gr.Textbox(lines=1, label="Source Prompt", interactive=True)
|
|
|
|
| 139 |
tar_prompt = gr.Textbox(lines=1, label="Target Prompt", interactive=True)
|
| 140 |
+
edit_concept = gr.Textbox(lines=1, label="SEGA Edit Concepts", interactive=True)
|
| 141 |
|
| 142 |
with gr.Row():
|
| 143 |
input_image = gr.Image(label="Input Image", interactive=True)
|
|
|
|
| 150 |
with gr.Row():
|
| 151 |
with gr.Column(scale=1, min_width=100):
|
| 152 |
generate_button = gr.Button("Run")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 153 |
|
|
|
|
| 154 |
with gr.Accordion("Advanced Options", open=False):
|
| 155 |
with gr.Row():
|
| 156 |
#inversion
|
|
|
|
| 163 |
|
| 164 |
# edit
|
| 165 |
sega_edit_guidance = gr.Slider(value=10, label=f"SEGA Edit Guidance Scale", interactive=True)
|
| 166 |
+
# warm_up = gr.Number(value=1, label=f"SEGA Warm-up Steps", interactive=True)
|
| 167 |
+
# neg_guidance = gr.Checkbox(label="SEGA Negative Guidance")
|
| 168 |
|
| 169 |
|
| 170 |
# gr.Markdown(help_text)
|
|
|
|
| 179 |
skip,
|
| 180 |
tar_cfg_scale,
|
| 181 |
edit_concept,
|
| 182 |
+
sega_edit_guidance
|
| 183 |
+
# warm_up,
|
| 184 |
+
# neg_guidance
|
| 185 |
],
|
| 186 |
outputs=[ddpm_edited_image, sega_edited_image],
|
| 187 |
)
|