amildravid4292 commited on
Commit
7b8af8c
·
verified ·
1 Parent(s): d2f443c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +63 -56
app.py CHANGED
@@ -438,62 +438,59 @@ with gr.Blocks(css="style.css") as demo:
438
  with gr.Column():
439
  with gr.Row():
440
  with gr.Column():
441
- input_image = gr.Image(label="Identity from Sampled or Uploaded Model", height=512, width=512, interactive=False)
442
- # input_image = gr.ImageEditor(elem_id="image_upload", type='pil', label="Upload image and draw to define mask",
443
- # height=512, width=512, brush=gr.Brush(), layers=False)
 
444
  with gr.Row():
445
  sample = gr.Button("🎲 Sample New Model")
446
- #invert_button = gr.Button("⏪ Invert")
447
- file_input = gr.File(label="Upload Model", container=True)
448
- file_output = gr.File(label="Download Model", container=True)
449
  with gr.Column():
450
-
451
  image_slider = ImageSlider(position=0.5, type="pil", height=512, width=512)
 
452
 
453
- prompt = gr.Textbox(label="Prompt",
454
  info="Make sure to include 'sks person'" ,
455
  placeholder="sks person",
456
  value="sks person")
457
- seed = gr.Number(value=5, label="Seed", precision=0, interactive=True)
458
-
459
- with gr.Row():
460
- a1 = gr.Slider(label="- Young +", value=0, step=0.001, minimum=-1, maximum=1, interactive=True)
461
- a2 = gr.Slider(label="- Pointy Nose +", value=0, step=0.001, minimum=-1, maximum=1, interactive=True)
462
- with gr.Row():
463
- a3 = gr.Slider(label="- Curly Hair +", value=0, step=0.001, minimum=-1, maximum=1, interactive=True)
464
- a4 = gr.Slider(label="- Thick Eyebrows +", value=0, step=0.001, minimum=-1, maximum=1, interactive=True)
465
-
466
- with gr.Accordion("Advanced Options", open=False):
467
- with gr.Column():
468
- cfg = gr.Slider(label="CFG", value=3.0, step=0.1, minimum=0, maximum=10, interactive=True)
469
- steps = gr.Slider(label="Inference Steps", value=50, step=1, minimum=0, maximum=100, interactive=True)
470
- injection_step = gr.Slider(label="Injection Step", value=800, step=1, minimum=0, maximum=1000, interactive=True)
471
- negative_prompt = gr.Textbox(label="Negative Prompt", placeholder="low quality, blurry, unfinished, nudity, weapon", value="low quality, blurry, unfinished, weapon, nudity, weapon")
472
-
473
- submit = gr.Button("Generate")
474
-
475
-
476
 
477
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
478
 
479
 
480
 
481
- # with gr.Accordion("Advanced Options", open=False):
482
- # with gr.Tab("Inversion"):
483
- # with gr.Row():
484
- # lr = gr.Number(value=1e-1, label="Learning Rate", interactive=True)
485
- # pcs = gr.Slider(label="# Principal Components", value=10000, step=1, minimum=1, maximum=10000, interactive=True)
486
- # with gr.Row():
487
- # epochs = gr.Slider(label="Epochs", value=400, step=1, minimum=1, maximum=2000, interactive=True)
488
- # weight_decay = gr.Number(value=1e-10, label="Weight Decay", interactive=True)
489
- # with gr.Tab("Sampling"):
490
- # with gr.Row():
491
- # cfg1= gr.Slider(label="CFG", value=3.0, step=0.1, minimum=0, maximum=10, interactive=True)
492
- # steps1 = gr.Slider(label="Inference Steps", value=50, step=1, minimum=0, maximum=100, interactive=True)
493
- # seed1 = gr.Number(value=5, label="Seed", precision=0, interactive=True)
494
- # with gr.Row():
495
- # negative_prompt1 = gr.Textbox(label="Negative Prompt", placeholder="low quality, blurry, unfinished, nudity, weapon", value="low quality, blurry, unfinished, nudity, weapon")
496
- # injection_step = gr.Slider(label="Injection Step", value=800, step=1, minimum=0, maximum=1000, interactive=True)
497
 
498
 
499
  # with gr.Tab("Editing"):
@@ -502,20 +499,30 @@ with gr.Blocks(css="style.css") as demo:
502
  # steps2 = gr.Slider(label="Inference Steps", value=50, step=1, minimum=0, maximum=100, interactive=True)
503
  # injection_step = gr.Slider(label="Injection Step", value=800, step=1, minimum=0, maximum=1000, interactive=True)
504
  # negative_prompt2 = gr.Textbox(label="Negative Prompt", placeholder="low quality, blurry, unfinished, nudity, weapon", value="low quality, blurry, unfinished, nudity, weapon")
505
- # with gr.Tab("Uploading a model"):
506
- # gr.Markdown("""<div style="text-align: justify;">Upload a model below downloaded from this demo.""")
507
 
508
- # file_input = gr.File(label="Upload Model", container=True)
509
 
510
- # submit1 = gr.Button("Generate")
511
 
512
 
513
- # invert_button.click(fn=run_inversion,
514
- # inputs=[input_image, pcs, epochs, weight_decay,lr],
515
- # outputs = [image_slider, file_output])
 
 
 
 
 
 
 
 
 
 
516
 
517
 
518
- sample.click(fn=sample_then_run, outputs=[input_image, file_output])
519
 
520
  # submit1.click(fn=inference,
521
  # inputs=[prompt1, negative_prompt1, cfg1, steps1, seed1],
@@ -523,10 +530,10 @@ with gr.Blocks(css="style.css") as demo:
523
  # submit1.click(fn=edit_inference,
524
  # inputs=[input_image, prompt1, negative_prompt1, cfg1, steps1, seed1, injection_step, a1, a2, a3, a4],
525
  # outputs=image_slider)
526
- # submit1.click(
527
- # fn=edit_inference, inputs=[input_image, prompt, negative_prompt, cfg, steps, seed, injection_step, a1, a2, a3, a4], outputs=[image_slider]
528
- # )
529
- # file_input.change(fn=file_upload, inputs=file_input, outputs = input_image)
530
 
531
 
532
 
 
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"):
 
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],
 
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