Spaces:
Running
on
A10G
Running
on
A10G
Linoy Tsaban
commited on
Commit
•
c6ff99b
1
Parent(s):
04efc88
Update app.py
Browse filesadd dynamic sega concepts adding
app.py
CHANGED
@@ -208,16 +208,21 @@ For faster inference without waiting in queue, you may duplicate the space and u
|
|
208 |
<p/>"""
|
209 |
with gr.Blocks(css='style.css') as demo:
|
210 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
211 |
def reset_do_inversion():
|
212 |
do_inversion = True
|
213 |
return do_inversion
|
214 |
-
|
215 |
-
|
216 |
gr.HTML(intro)
|
217 |
wts = gr.State()
|
218 |
zs = gr.State()
|
219 |
do_inversion = gr.State(value=True)
|
220 |
-
|
221 |
with gr.Row():
|
222 |
input_image = gr.Image(label="Input Image", interactive=True)
|
223 |
# ddpm_edited_image = gr.Image(label=f"DDPM Reconstructed Image", interactive=False, visible=False)
|
@@ -226,8 +231,61 @@ with gr.Blocks(css='style.css') as demo:
|
|
226 |
# ddpm_edited_image.style(height=512, width=512)
|
227 |
sega_edited_image.style(height=512, width=512)
|
228 |
|
229 |
-
with gr.
|
230 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
231 |
|
232 |
|
233 |
with gr.Row():
|
@@ -237,43 +295,23 @@ with gr.Blocks(css='style.css') as demo:
|
|
237 |
# edit_button = gr.Button("Edit")
|
238 |
|
239 |
with gr.Accordion("Advanced Options", open=False):
|
240 |
-
|
241 |
-
with gr.
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
with gr.Group():
|
254 |
-
with gr.Row().style(mobile_collapse=False, equal_height=True):
|
255 |
-
neg_guidance_1 = gr.Checkbox(
|
256 |
-
label='Negative Guidance')
|
257 |
-
warmup_1 = gr.Slider(label='Warmup', minimum=0, maximum=50, value=10, step=1, interactive=True)
|
258 |
-
guidnace_scale_1 = gr.Slider(label='Scale', minimum=1, maximum=10, value=5, step=0.25, interactive=True)
|
259 |
-
threshold_1 = gr.Slider(label='Threshold', minimum=0.5, maximum=0.99, value=0.95, steps=0.01, interactive=True)
|
260 |
-
|
261 |
-
with gr.TabItem('DDPM Guidance', id=1):
|
262 |
-
with gr.Row():
|
263 |
-
with gr.Column():
|
264 |
-
src_prompt = gr.Textbox(lines=1, label="Source Prompt", interactive=True, placeholder="")
|
265 |
-
steps = gr.Number(value=100, precision=0, label="Num Diffusion Steps", interactive=True)
|
266 |
-
src_cfg_scale = gr.Number(value=3.5, label=f"Source Guidance Scale", interactive=True)
|
267 |
-
seed = gr.Number(value=0, precision=0, label="Seed", interactive=True)
|
268 |
-
randomize_seed = gr.Checkbox(label='Randomize seed', value=False)
|
269 |
-
with gr.Column():
|
270 |
-
skip = gr.Slider(minimum=0, maximum=40, value=36, label="Skip Steps", interactive=True)
|
271 |
-
tar_cfg_scale = gr.Slider(minimum=7, maximum=18,value=15, label=f"Guidance Scale", interactive=True)
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
|
276 |
# gr.Markdown(help_text)
|
|
|
|
|
277 |
|
278 |
|
279 |
run_button.click(
|
@@ -303,11 +341,11 @@ with gr.Blocks(css='style.css') as demo:
|
|
303 |
steps,
|
304 |
skip,
|
305 |
tar_cfg_scale,
|
306 |
-
edit_concept_1,
|
307 |
-
guidnace_scale_1,
|
308 |
-
warmup_1,
|
309 |
-
neg_guidance_1,
|
310 |
-
threshold_1
|
311 |
|
312 |
],
|
313 |
outputs=[sega_edited_image],
|
|
|
208 |
<p/>"""
|
209 |
with gr.Blocks(css='style.css') as demo:
|
210 |
|
211 |
+
def add_concept(sega_concepts_counter):
|
212 |
+
if sega_concepts_counter == 1:
|
213 |
+
return row2.update(visible=True), row3.update(visible=False), plus.update(visible=True), 2
|
214 |
+
else:
|
215 |
+
return row2.update(visible=True), row3.update(visible=True), plus.update(visible=False), 3
|
216 |
+
|
217 |
+
|
218 |
def reset_do_inversion():
|
219 |
do_inversion = True
|
220 |
return do_inversion
|
|
|
|
|
221 |
gr.HTML(intro)
|
222 |
wts = gr.State()
|
223 |
zs = gr.State()
|
224 |
do_inversion = gr.State(value=True)
|
225 |
+
sega_concepts_counter = gr.Number(1)
|
226 |
with gr.Row():
|
227 |
input_image = gr.Image(label="Input Image", interactive=True)
|
228 |
# ddpm_edited_image = gr.Image(label=f"DDPM Reconstructed Image", interactive=False, visible=False)
|
|
|
231 |
# ddpm_edited_image.style(height=512, width=512)
|
232 |
sega_edited_image.style(height=512, width=512)
|
233 |
|
234 |
+
with gr.Tabs() as tabs:
|
235 |
+
with gr.TabItem('1. Describe the desired output', id=0):
|
236 |
+
with gr.Row().style(mobile_collapse=False, equal_height=True):
|
237 |
+
tar_prompt = gr.Textbox(
|
238 |
+
label="Edit Concept",
|
239 |
+
show_label=False,
|
240 |
+
max_lines=1,
|
241 |
+
placeholder="Enter your 1st edit prompt",
|
242 |
+
)
|
243 |
+
with gr.TabItem('2. Add SEGA edit concepts', id=1):
|
244 |
+
# with gr.Group():
|
245 |
+
with gr.Row().style(mobile_collapse=False, equal_height=True):
|
246 |
+
edit_concept_1 = gr.Textbox(
|
247 |
+
label="Edit Concept",
|
248 |
+
show_label=False,
|
249 |
+
max_lines=1,
|
250 |
+
placeholder="Enter your 1st edit prompt",
|
251 |
+
)
|
252 |
+
# tar_prompt = gr.Textbox(lines=1, label="Target Prompt", interactive=True, placeholder="")
|
253 |
+
neg_guidance_1 = gr.Checkbox(
|
254 |
+
label='Negative Guidance')
|
255 |
+
warmup_1 = gr.Slider(label='Warmup', minimum=0, maximum=50, value=10, step=1, interactive=True)
|
256 |
+
guidnace_scale_1 = gr.Slider(label='Scale', minimum=1, maximum=10, value=5, step=0.25, interactive=True)
|
257 |
+
threshold_1 = gr.Slider(label='Threshold', minimum=0.5, maximum=0.99, value=0.95, steps=0.01, interactive=True)
|
258 |
+
|
259 |
+
with gr.Row(visible=False) as row2:
|
260 |
+
edit_concept_2 = gr.Textbox(
|
261 |
+
label="Edit Concept",
|
262 |
+
show_label=False,visible=True,
|
263 |
+
max_lines=1,
|
264 |
+
placeholder="Enter your 2st edit prompt",
|
265 |
+
)
|
266 |
+
# tar_prompt = gr.Textbox(lines=1, label="Target Prompt", interactive=True, placeholder="")
|
267 |
+
neg_guidance_2 = gr.Checkbox(
|
268 |
+
label='Negative Guidance',visible=True)
|
269 |
+
warmup_2 = gr.Slider(label='Warmup', minimum=0, maximum=50, value=10, step=1, visible=True,interactive=True)
|
270 |
+
guidnace_scale_2 = gr.Slider(label='Scale', minimum=1, maximum=10, value=5, step=0.25,visible=True, interactive=True)
|
271 |
+
threshold_2 = gr.Slider(label='Threshold', minimum=0.5, maximum=0.99, value=0.95, steps=0.01,visible=True, interactive=True)
|
272 |
+
|
273 |
+
with gr.Row(visible=False) as row3:
|
274 |
+
edit_concept_3 = gr.Textbox(
|
275 |
+
label="Edit Concept",
|
276 |
+
show_label=False,visible=True,
|
277 |
+
max_lines=1,
|
278 |
+
placeholder="Enter your 3rd edit prompt",
|
279 |
+
)
|
280 |
+
# tar_prompt = gr.Textbox(lines=1, label="Target Prompt", interactive=True, placeholder="")
|
281 |
+
neg_guidance_3 = gr.Checkbox(
|
282 |
+
label='Negative Guidance',visible=True)
|
283 |
+
warmup_3 = gr.Slider(label='Warmup', minimum=0, maximum=50, value=10, step=1, visible=True,interactive=True)
|
284 |
+
guidnace_scale_3 = gr.Slider(label='Scale', minimum=1, maximum=10, value=5, step=0.25,visible=True, interactive=True)
|
285 |
+
threshold_3 = gr.Slider(label='Threshold', minimum=0.5, maximum=0.99, value=0.95, steps=0.01,visible=True, interactive=True)
|
286 |
+
|
287 |
+
with gr.Row().style(mobile_collapse=False, equal_height=True):
|
288 |
+
plus = gr.Button("+")
|
289 |
|
290 |
|
291 |
with gr.Row():
|
|
|
295 |
# edit_button = gr.Button("Edit")
|
296 |
|
297 |
with gr.Accordion("Advanced Options", open=False):
|
298 |
+
with gr.Row():
|
299 |
+
with gr.Column():
|
300 |
+
src_prompt = gr.Textbox(lines=1, label="Source Prompt", interactive=True, placeholder="")
|
301 |
+
steps = gr.Number(value=100, precision=0, label="Num Diffusion Steps", interactive=True)
|
302 |
+
src_cfg_scale = gr.Number(value=3.5, label=f"Source Guidance Scale", interactive=True)
|
303 |
+
seed = gr.Number(value=0, precision=0, label="Seed", interactive=True)
|
304 |
+
randomize_seed = gr.Checkbox(label='Randomize seed', value=False)
|
305 |
+
with gr.Column():
|
306 |
+
skip = gr.Slider(minimum=0, maximum=40, value=36, label="Skip Steps", interactive=True)
|
307 |
+
tar_cfg_scale = gr.Slider(minimum=7, maximum=18,value=15, label=f"Guidance Scale", interactive=True)
|
308 |
+
|
309 |
+
|
310 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
311 |
|
312 |
# gr.Markdown(help_text)
|
313 |
+
plus.click(fn = add_concept, inputs=sega_concepts_counter,
|
314 |
+
outputs= [row2, row3, plus, sega_concepts_counter])
|
315 |
|
316 |
|
317 |
run_button.click(
|
|
|
341 |
steps,
|
342 |
skip,
|
343 |
tar_cfg_scale,
|
344 |
+
[edit_concept_1,edit_concept_2,edit_concept_3],
|
345 |
+
[guidnace_scale_1,guidnace_scale_2,guidnace_scale_3],
|
346 |
+
[warmup_1, warmup_2, warmup_3],
|
347 |
+
[neg_guidance_1, neg_guidance_2, neg_guidance_3],
|
348 |
+
[threshold_1, threshold_2, threshold_3]
|
349 |
|
350 |
],
|
351 |
outputs=[sega_edited_image],
|