Spaces:
Running
on
Zero
Running
on
Zero
amildravid4292
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -406,6 +406,10 @@ def file_upload(file):
|
|
406 |
|
407 |
|
408 |
|
|
|
|
|
|
|
|
|
409 |
intro = """
|
410 |
<div style="display: flex;align-items: center;justify-content: center">
|
411 |
<h1 style="margin-left: 12px;text-align: center;margin-bottom: 7px;display: inline-block">weights2weights</h1>
|
@@ -418,51 +422,122 @@ intro = """
|
|
418 |
display: inline-block;
|
419 |
">
|
420 |
<img style="margin-top: -1em;margin-bottom: 0em;position: absolute;" src="https://bit.ly/3CWLGkA" alt="Duplicate Space"></a>
|
421 |
-
</p>
|
|
|
|
|
|
|
422 |
|
423 |
with gr.Blocks(css="style.css") as demo:
|
424 |
gr.HTML(intro)
|
425 |
-
|
426 |
-
|
|
|
|
|
|
|
|
|
|
|
427 |
with gr.Row():
|
428 |
with gr.Column():
|
429 |
-
input_image = gr.Image(label="
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
|
435 |
-
|
436 |
-
#invert_button = gr.Button("⏪ Invert")
|
437 |
with gr.Column():
|
438 |
image_slider = ImageSlider(position=0.5, type="pil", height=512, width=512)
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
444 |
with gr.Row():
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
|
449 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
450 |
|
451 |
-
|
452 |
-
|
453 |
-
|
454 |
-
|
455 |
-
|
456 |
-
|
457 |
-
|
458 |
-
|
459 |
-
|
460 |
-
|
|
|
461 |
|
462 |
|
463 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
464 |
|
465 |
|
466 |
-
|
467 |
|
468 |
demo.queue().launch()
|
|
|
406 |
|
407 |
|
408 |
|
409 |
+
|
410 |
+
|
411 |
+
|
412 |
+
|
413 |
intro = """
|
414 |
<div style="display: flex;align-items: center;justify-content: center">
|
415 |
<h1 style="margin-left: 12px;text-align: center;margin-bottom: 7px;display: inline-block">weights2weights</h1>
|
|
|
422 |
display: inline-block;
|
423 |
">
|
424 |
<img style="margin-top: -1em;margin-bottom: 0em;position: absolute;" src="https://bit.ly/3CWLGkA" alt="Duplicate Space"></a>
|
425 |
+
</p>
|
426 |
+
"""
|
427 |
+
|
428 |
+
|
429 |
|
430 |
with gr.Blocks(css="style.css") as demo:
|
431 |
gr.HTML(intro)
|
432 |
+
|
433 |
+
gr.Markdown("""
|
434 |
+
Click sample (to sample an identity) *or* upload an image & click `invert` to get started ✨
|
435 |
+
> 💡 When inverting, draw a mask over the face for improved results.
|
436 |
+
> To use a model previously downloaded from this demo see `Uplaoding a model` in the `Advanced options`
|
437 |
+
""")
|
438 |
+
with gr.Column():
|
439 |
with gr.Row():
|
440 |
with gr.Column():
|
441 |
+
# input_image = gr.Image(source='upload', elem_id="image_upload", tool='sketch', type='pil', label="Upload image and draw to define mask",
|
442 |
+
# height=512, width=512, brush_color='#00FFFF', mask_opacity=0.6)
|
443 |
+
input_image = gr.ImageEditor(elem_id="image_upload", type='pil', label="Upload image and draw to define mask",
|
444 |
+
height=512, width=512, brush=gr.Brush(), layers=False)
|
445 |
+
with gr.Row():
|
446 |
+
sample = gr.Button("🎲 Sample New Model")
|
447 |
+
invert_button = gr.Button("⏪ Invert")
|
|
|
448 |
with gr.Column():
|
449 |
image_slider = ImageSlider(position=0.5, type="pil", height=512, width=512)
|
450 |
+
# gallery1 = gr.Image(label="Identity from Original Model",height=512, width=512, interactive=False)
|
451 |
+
|
452 |
+
prompt1 = gr.Textbox(label="Prompt",
|
453 |
+
info="Make sure to include 'sks person'" ,
|
454 |
+
placeholder="sks person",
|
455 |
+
value="sks person")
|
456 |
+
|
457 |
+
# Editing
|
458 |
+
with gr.Column():
|
459 |
+
#gallery2 = gr.Image(label="Identity from Edited Model", interactive=False, visible=False )
|
460 |
+
with gr.Row():
|
461 |
+
a1 = gr.Slider(label="- Young +", value=0, step=0.001, minimum=-1, maximum=1, interactive=True)
|
462 |
+
a2 = gr.Slider(label="- Pointy Nose +", value=0, step=0.001, minimum=-1, maximum=1, interactive=True)
|
463 |
+
with gr.Row():
|
464 |
+
a3 = gr.Slider(label="- Curly Hair +", value=0, step=0.001, minimum=-1, maximum=1, interactive=True)
|
465 |
+
a4 = gr.Slider(label="- Thick Eyebrows +", value=0, step=0.001, minimum=-1, maximum=1, interactive=True)
|
466 |
+
# prompt2 = gr.Textbox(label="Prompt",
|
467 |
+
# info="Make sure to include 'sks person'" ,
|
468 |
+
# placeholder="sks person",
|
469 |
+
# value="sks person", visible=False)
|
470 |
+
# seed2 = gr.Number(value=5, label="Seed", precision=0, interactive=True, visible=False)
|
471 |
+
|
472 |
+
|
473 |
+
|
474 |
+
# submit2 = gr.Button("Generate", visible=False)
|
475 |
+
|
476 |
+
|
477 |
+
|
478 |
+
with gr.Accordion("Advanced Options", open=False):
|
479 |
+
with gr.Tab("Inversion"):
|
480 |
+
with gr.Row():
|
481 |
+
lr = gr.Number(value=1e-1, label="Learning Rate", interactive=True)
|
482 |
+
pcs = gr.Slider(label="# Principal Components", value=10000, step=1, minimum=1, maximum=10000, interactive=True)
|
483 |
+
with gr.Row():
|
484 |
+
epochs = gr.Slider(label="Epochs", value=400, step=1, minimum=1, maximum=2000, interactive=True)
|
485 |
+
weight_decay = gr.Number(value=1e-10, label="Weight Decay", interactive=True)
|
486 |
+
with gr.Tab("Sampling"):
|
487 |
+
with gr.Row():
|
488 |
+
cfg1= gr.Slider(label="CFG", value=3.0, step=0.1, minimum=0, maximum=10, interactive=True)
|
489 |
+
steps1 = gr.Slider(label="Inference Steps", value=50, step=1, minimum=0, maximum=100, interactive=True)
|
490 |
+
seed1 = gr.Number(value=5, label="Seed", precision=0, interactive=True)
|
491 |
with gr.Row():
|
492 |
+
negative_prompt1 = gr.Textbox(label="Negative Prompt", placeholder="low quality, blurry, unfinished, nudity, weapon", value="low quality, blurry, unfinished, nudity, weapon")
|
493 |
+
injection_step = gr.Slider(label="Injection Step", value=800, step=1, minimum=0, maximum=1000, interactive=True)
|
494 |
+
|
495 |
+
|
496 |
+
# with gr.Tab("Editing"):
|
497 |
+
# with gr.Column():
|
498 |
+
# cfg2 = gr.Slider(label="CFG", value=3.0, step=0.1, minimum=0, maximum=10, interactive=True)
|
499 |
+
# steps2 = gr.Slider(label="Inference Steps", value=50, step=1, minimum=0, maximum=100, interactive=True)
|
500 |
+
# injection_step = gr.Slider(label="Injection Step", value=800, step=1, minimum=0, maximum=1000, interactive=True)
|
501 |
+
# negative_prompt2 = gr.Textbox(label="Negative Prompt", placeholder="low quality, blurry, unfinished, nudity, weapon", value="low quality, blurry, unfinished, nudity, weapon")
|
502 |
+
with gr.Tab("Uploading a model"):
|
503 |
+
gr.Markdown("""<div style="text-align: justify;">Upload a model below downloaded from this demo.""")
|
504 |
|
505 |
+
file_input = gr.File(label="Upload Model", container=True)
|
506 |
+
|
507 |
+
submit1 = gr.Button("Generate")
|
508 |
+
|
509 |
+
|
510 |
+
|
511 |
+
gr.Markdown("""<div style="text-align: justify;"> After sampling a new model or inverting, you can download the model below.""")
|
512 |
+
|
513 |
+
with gr.Row():
|
514 |
+
file_output = gr.File(label="Download Sampled Model", container=True, interactive=False)
|
515 |
+
|
516 |
|
517 |
|
518 |
|
519 |
+
|
520 |
+
invert_button.click(fn=run_inversion,
|
521 |
+
inputs=[input_image, pcs, epochs, weight_decay,lr],
|
522 |
+
outputs = [image_slider, file_output])
|
523 |
+
|
524 |
+
|
525 |
+
sample.click(fn=sample_then_run, outputs=[input_image, file_output])
|
526 |
+
|
527 |
+
# submit1.click(fn=inference,
|
528 |
+
# inputs=[prompt1, negative_prompt1, cfg1, steps1, seed1],
|
529 |
+
# outputs=gallery1)
|
530 |
+
# submit1.click(fn=edit_inference,
|
531 |
+
# inputs=[input_image, prompt1, negative_prompt1, cfg1, steps1, seed1, injection_step, a1, a2, a3, a4],
|
532 |
+
# outputs=image_slider)
|
533 |
+
submit1.click(
|
534 |
+
fn=edit_inference, inputs=[input_image, prompt1, negative_prompt1, cfg1, steps1, seed1, injection_step, a1, a2, a3, a4], outputs=[image_slider]
|
535 |
+
)
|
536 |
+
file_input.change(fn=file_upload, inputs=file_input, outputs = input_image)
|
537 |
+
|
538 |
+
|
539 |
|
540 |
|
541 |
+
|
542 |
|
543 |
demo.queue().launch()
|