Linoy Tsaban
commited on
Commit
•
7593f04
1
Parent(s):
8fa000b
Update app.py
Browse files
app.py
CHANGED
@@ -123,7 +123,8 @@ def get_example():
|
|
123 |
|
124 |
def invert_and_reconstruct(
|
125 |
input_image,
|
126 |
-
do_inversion,
|
|
|
127 |
wts, zs,
|
128 |
src_prompt ="",
|
129 |
tar_prompt="",
|
@@ -138,12 +139,12 @@ def invert_and_reconstruct(
|
|
138 |
|
139 |
x0 = load_512(input_image, device=device)
|
140 |
|
141 |
-
|
142 |
-
|
143 |
zs_tensor, wts_tensor = invert(x0 =x0 , prompt_src=src_prompt, num_diffusion_steps=steps, cfg_scale_src=src_cfg_scale)
|
144 |
wts = gr.State(value=wts_tensor)
|
145 |
zs = gr.State(value=zs_tensor)
|
146 |
-
|
147 |
|
148 |
output = sample(zs.value, wts.value, prompt_tar=tar_prompt, skip=skip, cfg_scale_tar=tar_cfg_scale)
|
149 |
|
@@ -152,9 +153,7 @@ def invert_and_reconstruct(
|
|
152 |
|
153 |
|
154 |
def edit(input_image,
|
155 |
-
|
156 |
-
wts, zs, seed,
|
157 |
-
src_prompt ="",
|
158 |
tar_prompt="",
|
159 |
steps=100,
|
160 |
skip=36,
|
@@ -251,11 +250,16 @@ with gr.Blocks(css='style.css') as demo:
|
|
251 |
with gr.Row():
|
252 |
tar_prompt = gr.Textbox(lines=1, label="Target Prompt", interactive=True, placeholder="")
|
253 |
with gr.Accordion("SEGA Concepts", open=False, visible=False):
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
|
|
|
|
|
|
|
|
|
|
259 |
|
260 |
|
261 |
with gr.Row():
|
@@ -267,14 +271,13 @@ with gr.Blocks(css='style.css') as demo:
|
|
267 |
with gr.Accordion("Advanced Options", open=False):
|
268 |
with gr.Row():
|
269 |
with gr.Column():
|
270 |
-
#inversion
|
271 |
src_prompt = gr.Textbox(lines=1, label="Source Prompt", interactive=True, placeholder="")
|
272 |
steps = gr.Number(value=100, precision=0, label="Num Diffusion Steps", interactive=True)
|
273 |
src_cfg_scale = gr.Number(value=3.5, label=f"Source Guidance Scale", interactive=True)
|
274 |
seed = gr.Number(value=0, precision=0, label="Seed", interactive=True)
|
275 |
-
randomize_seed = gr.Checkbox(label='Randomize seed', value=
|
276 |
with gr.Column():
|
277 |
-
|
278 |
skip = gr.Slider(minimum=0, maximum=40, value=36, label="Skip Steps", interactive=True)
|
279 |
tar_cfg_scale = gr.Slider(minimum=7, maximum=18,value=15, label=f"Guidance Scale", interactive=True)
|
280 |
sega_edit_guidance = gr.Slider(value=10, label=f"SEGA Edit Guidance Scale", interactive=True)
|
@@ -293,7 +296,8 @@ with gr.Blocks(css='style.css') as demo:
|
|
293 |
queue = False).then(
|
294 |
fn=invert_and_reconstruct,
|
295 |
inputs=[input_image,
|
296 |
-
do_inversion,
|
|
|
297 |
wts, zs,
|
298 |
src_prompt,
|
299 |
tar_prompt,
|
@@ -308,10 +312,7 @@ with gr.Blocks(css='style.css') as demo:
|
|
308 |
edit_button.click(
|
309 |
fn=edit,
|
310 |
inputs=[input_image,
|
311 |
-
do_inversion,
|
312 |
wts, zs,
|
313 |
-
seed,
|
314 |
-
src_prompt,
|
315 |
tar_prompt,
|
316 |
steps,
|
317 |
skip,
|
|
|
123 |
|
124 |
def invert_and_reconstruct(
|
125 |
input_image,
|
126 |
+
do_inversion,
|
127 |
+
seed, randomize_seed,
|
128 |
wts, zs,
|
129 |
src_prompt ="",
|
130 |
tar_prompt="",
|
|
|
139 |
|
140 |
x0 = load_512(input_image, device=device)
|
141 |
|
142 |
+
if do_inversion or randomize_seed:
|
143 |
+
invert and retrieve noise maps and latent
|
144 |
zs_tensor, wts_tensor = invert(x0 =x0 , prompt_src=src_prompt, num_diffusion_steps=steps, cfg_scale_src=src_cfg_scale)
|
145 |
wts = gr.State(value=wts_tensor)
|
146 |
zs = gr.State(value=zs_tensor)
|
147 |
+
do_inversion = False
|
148 |
|
149 |
output = sample(zs.value, wts.value, prompt_tar=tar_prompt, skip=skip, cfg_scale_tar=tar_cfg_scale)
|
150 |
|
|
|
153 |
|
154 |
|
155 |
def edit(input_image,
|
156 |
+
wts, zs,
|
|
|
|
|
157 |
tar_prompt="",
|
158 |
steps=100,
|
159 |
skip=36,
|
|
|
250 |
with gr.Row():
|
251 |
tar_prompt = gr.Textbox(lines=1, label="Target Prompt", interactive=True, placeholder="")
|
252 |
with gr.Accordion("SEGA Concepts", open=False, visible=False):
|
253 |
+
with gr.Column(scale=1):
|
254 |
+
edit_concept = gr.Textbox(lines=1, label="Enter SEGA Edit Concept", visible = True, interactive=True)
|
255 |
+
with gr.Column(scale=1):
|
256 |
+
neg_guidance = gr.Checkbox(label="Negative Guidance", value=False)
|
257 |
+
submit = gr.Button(label="Add Concept")
|
258 |
+
concepts = gr.Dataframe(
|
259 |
+
headers=["Concepts", "Negative Guidance"],
|
260 |
+
datatype=["str", "bool"],
|
261 |
+
label="SEGA Concepts",
|
262 |
+
)
|
263 |
|
264 |
|
265 |
with gr.Row():
|
|
|
271 |
with gr.Accordion("Advanced Options", open=False):
|
272 |
with gr.Row():
|
273 |
with gr.Column():
|
|
|
274 |
src_prompt = gr.Textbox(lines=1, label="Source Prompt", interactive=True, placeholder="")
|
275 |
steps = gr.Number(value=100, precision=0, label="Num Diffusion Steps", interactive=True)
|
276 |
src_cfg_scale = gr.Number(value=3.5, label=f"Source Guidance Scale", interactive=True)
|
277 |
seed = gr.Number(value=0, precision=0, label="Seed", interactive=True)
|
278 |
+
randomize_seed = gr.Checkbox(label='Randomize seed', value=False)
|
279 |
with gr.Column():
|
280 |
+
|
281 |
skip = gr.Slider(minimum=0, maximum=40, value=36, label="Skip Steps", interactive=True)
|
282 |
tar_cfg_scale = gr.Slider(minimum=7, maximum=18,value=15, label=f"Guidance Scale", interactive=True)
|
283 |
sega_edit_guidance = gr.Slider(value=10, label=f"SEGA Edit Guidance Scale", interactive=True)
|
|
|
296 |
queue = False).then(
|
297 |
fn=invert_and_reconstruct,
|
298 |
inputs=[input_image,
|
299 |
+
do_inversion,
|
300 |
+
seed, randomize_seed,
|
301 |
wts, zs,
|
302 |
src_prompt,
|
303 |
tar_prompt,
|
|
|
312 |
edit_button.click(
|
313 |
fn=edit,
|
314 |
inputs=[input_image,
|
|
|
315 |
wts, zs,
|
|
|
|
|
316 |
tar_prompt,
|
317 |
steps,
|
318 |
skip,
|