Spaces:
Running
on
Zero
Running
on
Zero
change layout + adjust logic a bit
Browse files
app.py
CHANGED
@@ -430,77 +430,78 @@ intro = """
|
|
430 |
|
431 |
with gr.Blocks(css="style.css") as demo:
|
432 |
gr.HTML(intro)
|
433 |
-
|
434 |
-
|
435 |
-
|
436 |
-
|
437 |
-
gr.Markdown("""<div style="text-align: justify;"> Or upload an image below and click \"invert\". You can also optionally draw over the face to define a mask.""")
|
438 |
-
input_image = gr.Image(source='upload', elem_id="image_upload", tool='sketch', type='pil', label="Upload image and draw to define mask",
|
439 |
-
height=512, width=512, brush_color='#00FFFF', mask_opacity=0.6)
|
440 |
-
|
441 |
-
lr = gr.Number(value=1e-1, label="Learning Rate", interactive=True)
|
442 |
-
pcs = gr.Slider(label="# Principal Components", value=10000, step=1, minimum=1, maximum=10000, interactive=True)
|
443 |
-
with gr.Accordion("Advanced Options", open=False):
|
444 |
with gr.Column():
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
451 |
|
452 |
-
file_input = gr.File(label="Upload Model", container=True)
|
453 |
|
454 |
|
455 |
-
|
456 |
-
|
457 |
|
458 |
-
|
459 |
-
|
460 |
-
prompt1 = gr.Textbox(label="Prompt",
|
461 |
-
info="Make sure to include 'sks person'" ,
|
462 |
-
placeholder="sks person",
|
463 |
-
value="sks person")
|
464 |
-
seed1 = gr.Number(value=5, label="Seed", precision=0, interactive=True)
|
465 |
-
|
466 |
with gr.Accordion("Advanced Options", open=False):
|
467 |
-
with gr.
|
468 |
-
|
469 |
-
|
470 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
471 |
|
472 |
submit1 = gr.Button("Generate")
|
473 |
-
|
474 |
-
|
475 |
-
|
476 |
-
with gr.Column():
|
477 |
-
gallery2 = gr.Image(label="Identity from Edited Model", interactive=False )
|
478 |
-
with gr.Row():
|
479 |
-
a1 = gr.Slider(label="- Young +", value=0, step=0.001, minimum=-1, maximum=1, interactive=True)
|
480 |
-
a2 = gr.Slider(label="- Pointy Nose +", value=0, step=0.001, minimum=-1, maximum=1, interactive=True)
|
481 |
-
with gr.Row():
|
482 |
-
a3 = gr.Slider(label="- Curly Hair +", value=0, step=0.001, minimum=-1, maximum=1, interactive=True)
|
483 |
-
a4 = gr.Slider(label="- Thick Eyebrows +", value=0, step=0.001, minimum=-1, maximum=1, interactive=True)
|
484 |
-
prompt2 = gr.Textbox(label="Prompt",
|
485 |
-
info="Make sure to include 'sks person'" ,
|
486 |
-
placeholder="sks person",
|
487 |
-
value="sks person")
|
488 |
-
seed2 = gr.Number(value=5, label="Seed", precision=0, interactive=True)
|
489 |
-
with gr.Accordion("Advanced Options", open=False):
|
490 |
-
with gr.Column():
|
491 |
-
cfg2 = gr.Slider(label="CFG", value=3.0, step=0.1, minimum=0, maximum=10, interactive=True)
|
492 |
-
steps2 = gr.Slider(label="Inference Steps", value=50, step=1, minimum=0, maximum=100, interactive=True)
|
493 |
-
injection_step = gr.Slider(label="Injection Step", value=800, step=1, minimum=0, maximum=1000, interactive=True)
|
494 |
-
negative_prompt2 = gr.Textbox(label="Negative Prompt", placeholder="low quality, blurry, unfinished, nudity, weapon", value="low quality, blurry, unfinished, nudity, weapon")
|
495 |
-
|
496 |
-
submit2 = gr.Button("Generate")
|
497 |
-
|
498 |
|
499 |
|
500 |
-
gr.Markdown("""<div style="text-align: justify;"> After sampling a new model or inverting, you can download the model below.""")
|
501 |
|
502 |
with gr.Row():
|
503 |
-
file_output = gr.File(label="Download Sampled Model", container=True, interactive=False)
|
504 |
|
505 |
|
506 |
|
@@ -513,12 +514,12 @@ with gr.Blocks(css="style.css") as demo:
|
|
513 |
|
514 |
sample.click(fn=sample_then_run, outputs=[gallery1, file_output])
|
515 |
|
516 |
-
submit1.click(fn=inference,
|
517 |
-
|
|
|
|
|
|
|
518 |
outputs=gallery1)
|
519 |
-
submit2.click(fn=edit_inference,
|
520 |
-
inputs=[prompt2, negative_prompt2, cfg2, steps2, seed2, injection_step, a1, a2, a3, a4],
|
521 |
-
outputs=gallery2)
|
522 |
file_input.change(fn=file_upload, inputs=file_input, outputs = gallery1)
|
523 |
|
524 |
|
|
|
430 |
|
431 |
with gr.Blocks(css="style.css") as demo:
|
432 |
gr.HTML(intro)
|
433 |
+
|
434 |
+
gr.Markdown("""<div style="text-align: justify;"> Click below to sample an identity-encoding model, or upload an image below and click \"invert\". You can also optionally draw over the face to define a mask. To use model previously downloaded from this demo see \"Uplaoding a model\" in the Advanced options""")
|
435 |
+
with gr.Column():
|
436 |
+
with gr.Row():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
437 |
with gr.Column():
|
438 |
+
input_image = gr.Image(source='upload', elem_id="image_upload", tool='sketch', type='pil', label="Upload image and draw to define mask",
|
439 |
+
height=512, width=512, brush_color='#00FFFF', mask_opacity=0.6)
|
440 |
+
with gr.Row():
|
441 |
+
sample = gr.Button("Sample New Model")
|
442 |
+
invert_button = gr.Button("Invert")
|
443 |
+
with gr.Column():
|
444 |
+
gallery1 = gr.Image(label="Identity from Original Model",height=512, width=512, interactive=False)
|
445 |
+
|
446 |
+
prompt1 = gr.Textbox(label="Prompt",
|
447 |
+
info="Make sure to include 'sks person'" ,
|
448 |
+
placeholder="sks person",
|
449 |
+
value="sks person")
|
450 |
+
|
451 |
+
# Editing
|
452 |
+
with gr.Column():
|
453 |
+
#gallery2 = gr.Image(label="Identity from Edited Model", interactive=False, visible=False )
|
454 |
+
with gr.Row():
|
455 |
+
a1 = gr.Slider(label="- Young +", value=0, step=0.001, minimum=-1, maximum=1, interactive=True)
|
456 |
+
a2 = gr.Slider(label="- Pointy Nose +", value=0, step=0.001, minimum=-1, maximum=1, interactive=True)
|
457 |
+
with gr.Row():
|
458 |
+
a3 = gr.Slider(label="- Curly Hair +", value=0, step=0.001, minimum=-1, maximum=1, interactive=True)
|
459 |
+
a4 = gr.Slider(label="- Thick Eyebrows +", value=0, step=0.001, minimum=-1, maximum=1, interactive=True)
|
460 |
+
# prompt2 = gr.Textbox(label="Prompt",
|
461 |
+
# info="Make sure to include 'sks person'" ,
|
462 |
+
# placeholder="sks person",
|
463 |
+
# value="sks person", visible=False)
|
464 |
+
# seed2 = gr.Number(value=5, label="Seed", precision=0, interactive=True, visible=False)
|
465 |
|
|
|
466 |
|
467 |
|
468 |
+
# submit2 = gr.Button("Generate", visible=False)
|
|
|
469 |
|
470 |
+
|
471 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
472 |
with gr.Accordion("Advanced Options", open=False):
|
473 |
+
with gr.Tab("Inversion"):
|
474 |
+
with gr.Column():
|
475 |
+
lr = gr.Number(value=1e-1, label="Learning Rate", interactive=True)
|
476 |
+
pcs = gr.Slider(label="# Principal Components", value=10000, step=1, minimum=1, maximum=10000, interactive=True)
|
477 |
+
epochs = gr.Slider(label="Epochs", value=400, step=1, minimum=1, maximum=2000, interactive=True)
|
478 |
+
weight_decay = gr.Number(value=1e-10, label="Weight Decay", interactive=True)
|
479 |
+
with gr.Tab("Sampling"):
|
480 |
+
with gr.Column():
|
481 |
+
cfg1= gr.Slider(label="CFG", value=3.0, step=0.1, minimum=0, maximum=10, interactive=True)
|
482 |
+
steps1 = gr.Slider(label="Inference Steps", value=50, step=1, minimum=0, maximum=100, interactive=True)
|
483 |
+
negative_prompt1 = gr.Textbox(label="Negative Prompt", placeholder="low quality, blurry, unfinished, nudity, weapon", value="low quality, blurry, unfinished, nudity, weapon")
|
484 |
+
seed1 = gr.Number(value=5, label="Seed", precision=0, interactive=True)
|
485 |
+
injection_step = gr.Slider(label="Injection Step", value=800, step=1, minimum=0, maximum=1000, interactive=True)
|
486 |
+
# with gr.Tab("Editing"):
|
487 |
+
# with gr.Column():
|
488 |
+
# cfg2 = gr.Slider(label="CFG", value=3.0, step=0.1, minimum=0, maximum=10, interactive=True)
|
489 |
+
# steps2 = gr.Slider(label="Inference Steps", value=50, step=1, minimum=0, maximum=100, interactive=True)
|
490 |
+
# injection_step = gr.Slider(label="Injection Step", value=800, step=1, minimum=0, maximum=1000, interactive=True)
|
491 |
+
# negative_prompt2 = gr.Textbox(label="Negative Prompt", placeholder="low quality, blurry, unfinished, nudity, weapon", value="low quality, blurry, unfinished, nudity, weapon")
|
492 |
+
with gr.Tab("Uploading a model"):
|
493 |
+
gr.Markdown("""<div style="text-align: justify;">Upload a model below downloaded from this demo.""")
|
494 |
+
|
495 |
+
file_input = gr.File(label="Upload Model", container=True)
|
496 |
|
497 |
submit1 = gr.Button("Generate")
|
498 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
499 |
|
500 |
|
501 |
+
# gr.Markdown("""<div style="text-align: justify;"> After sampling a new model or inverting, you can download the model below.""")
|
502 |
|
503 |
with gr.Row():
|
504 |
+
file_output = gr.File(label="Download Sampled Model", container=True, interactive=False, info="After sampling a new model or inverting, you can download the model below")
|
505 |
|
506 |
|
507 |
|
|
|
514 |
|
515 |
sample.click(fn=sample_then_run, outputs=[gallery1, file_output])
|
516 |
|
517 |
+
# submit1.click(fn=inference,
|
518 |
+
# inputs=[prompt1, negative_prompt1, cfg1, steps1, seed1],
|
519 |
+
# outputs=gallery1)
|
520 |
+
submit1.click(fn=edit_inference,
|
521 |
+
inputs=[prompt1, negative_prompt1, cfg1, steps1, seed1, injection_step, a1, a2, a3, a4],
|
522 |
outputs=gallery1)
|
|
|
|
|
|
|
523 |
file_input.change(fn=file_upload, inputs=file_input, outputs = gallery1)
|
524 |
|
525 |
|