amildravid4292 commited on
Commit
93a2723
·
verified ·
1 Parent(s): 7ef7220

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +107 -32
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
- with gr.Tab("Sampling Models + Editing"):
426
- with gr.Column():
 
 
 
 
 
427
  with gr.Row():
428
  with gr.Column():
429
- input_image = gr.Image(label="Identity from Sampled or Uploaded Model", interactive=False)
430
- sample = gr.Button("🎲 Sample New Model")
431
- file_input = gr.File(label="Upload Model", container=True)
432
- #file_input.change(fn=file_upload, inputs=file_input, outputs = gallery1)
433
-
434
- #with gr.Row():
435
- # sample = gr.Button("🎲 Sample New Model")
436
- #invert_button = gr.Button("⏪ Invert")
437
  with gr.Column():
438
  image_slider = ImageSlider(position=0.5, type="pil", height=512, width=512)
439
- prompt = gr.Textbox(label="Prompt",
440
- info="Make sure to include 'sks person'" ,
441
- placeholder="sks person",
442
- value="sks person")
443
- seed = gr.Number(value=5, label="Seed", precision=0, interactive=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
444
  with gr.Row():
445
- a1 = gr.Slider(label="- Young +", value=0, step=0.001, minimum=-1, maximum=1, interactive=True)
446
- a2 = gr.Slider(label="- Pointy Nose +", value=0, step=0.001, minimum=-1, maximum=1, interactive=True)
447
- with gr.Row():
448
- a3 = gr.Slider(label="- Curly Hair +", value=0, step=0.001, minimum=-1, maximum=1, interactive=True)
449
- a4 = gr.Slider(label="- placeholder +", value=0, step=0.001, minimum=-1, maximum=1, interactive=True)
 
 
 
 
 
 
 
450
 
451
-
452
- with gr.Accordion("Advanced Options", open=False):
453
- with gr.Column():
454
- cfg = gr.Slider(label="CFG", value=3.0, step=0.1, minimum=0, maximum=10, interactive=True)
455
- steps = gr.Slider(label="Inference Steps", value=50, step=1, minimum=0, maximum=100, interactive=True)
456
- injection_step = gr.Slider(label="Injection Step", value=800, step=1, minimum=0, maximum=1000, interactive=True)
457
- negative_prompt = gr.Textbox(label="Negative Prompt", placeholder="low quality, blurry, unfinished, nudity", value="low quality, blurry, unfinished, nudity")
458
-
459
- submit = gr.Button("Generate")
460
- # gallery1 = gr.Image(label="Identity from Original Model",height=512, width=512, interactive=False)
 
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()