Fabrice-TIERCELIN commited on
Commit
8cdca89
1 Parent(s): ae9aaa7

Image Guidance Scale, Strength and Black mask

Browse files
Files changed (1) hide show
  1. app.py +32 -2
app.py CHANGED
@@ -30,6 +30,8 @@ def check(
30
  denoising_steps,
31
  num_inference_steps,
32
  guidance_scale,
 
 
33
  randomize_seed,
34
  seed,
35
  debug_mode,
@@ -72,6 +74,8 @@ def uncrop(
72
  denoising_steps,
73
  num_inference_steps,
74
  guidance_scale,
 
 
75
  randomize_seed,
76
  seed,
77
  debug_mode,
@@ -88,6 +92,8 @@ def uncrop(
88
  denoising_steps,
89
  num_inference_steps,
90
  guidance_scale,
 
 
91
  randomize_seed,
92
  seed,
93
  debug_mode
@@ -122,6 +128,12 @@ def uncrop(
122
  if guidance_scale is None:
123
  guidance_scale = 7
124
 
 
 
 
 
 
 
125
  if randomize_seed:
126
  seed = random.randint(0, max_64_bit_int)
127
 
@@ -182,7 +194,7 @@ def uncrop(
182
 
183
  # Mask
184
  mask_image = Image.new(mode = input_image.mode, size = (output_width, output_height), color = (255, 255, 255, 0))
185
- black_mask = Image.new(mode = input_image.mode, size = (original_width - smooth_border, original_height - smooth_border), color = (127, 127, 127, 0))
186
  mask_image.paste(black_mask, (enlarge_left + (smooth_border // 2), enlarge_top + (smooth_border // 2)))
187
  mask_image = mask_image.filter(ImageFilter.BoxBlur((smooth_border // 2)))
188
 
@@ -226,6 +238,8 @@ def uncrop(
226
  mask_image = mask_image,
227
  num_inference_steps = num_inference_steps,
228
  guidance_scale = guidance_scale,
 
 
229
  denoising_steps = denoising_steps,
230
  show_progress_bar = True
231
  ).images[0]
@@ -308,17 +322,21 @@ with gr.Blocks() as interface:
308
  with gr.Row():
309
  prompt = gr.Textbox(label = 'Prompt', info = "Describe the subject, the background and the style of image; 77 token limit", placeholder = 'Describe what you want to see in the entire image')
310
  with gr.Row():
311
- with gr.Accordion("Advanced options", open = False):
312
  negative_prompt = gr.Textbox(label = 'Negative prompt', placeholder = 'Describe what you do NOT want to see in the entire image', value = 'Border, frame, painting, scribbling, smear, noise, blur, watermark')
313
  smooth_border = gr.Slider(minimum = 0, maximum = 1024, value = 0, step = 2, label = "Smooth border", info = "lower=preserve original, higher=seamless")
314
  denoising_steps = gr.Slider(minimum = 0, maximum = 1000, value = 1000, step = 1, label = "Denoising", info = "lower=irrelevant result, higher=relevant result")
315
  num_inference_steps = gr.Slider(minimum = 10, maximum = 100, value = 50, step = 1, label = "Number of inference steps", info = "lower=faster, higher=image quality")
316
  guidance_scale = gr.Slider(minimum = 1, maximum = 13, value = 7, step = 0.1, label = "Classifier-Free Guidance Scale", info = "lower=image quality, higher=follow the prompt")
 
 
317
  randomize_seed = gr.Checkbox(label = "\U0001F3B2 Randomize seed (not working, always checked)", value = True, info = "If checked, result is always different")
318
  seed = gr.Slider(minimum = 0, maximum = max_64_bit_int, step = 1, randomize = True, label = "Seed (if not randomized)")
319
  debug_mode = gr.Checkbox(label = "Debug mode", value = False, info = "Show intermediate results")
 
320
  with gr.Row():
321
  submit = gr.Button("Uncrop", variant = "primary")
 
322
  with gr.Row():
323
  uncropped_image = gr.Image(label = "Uncropped image")
324
  with gr.Row():
@@ -346,6 +364,8 @@ with gr.Blocks() as interface:
346
  denoising_steps,
347
  num_inference_steps,
348
  guidance_scale,
 
 
349
  randomize_seed,
350
  seed,
351
  debug_mode
@@ -362,6 +382,8 @@ with gr.Blocks() as interface:
362
  denoising_steps,
363
  num_inference_steps,
364
  guidance_scale,
 
 
365
  randomize_seed,
366
  seed,
367
  debug_mode
@@ -386,6 +408,8 @@ with gr.Blocks() as interface:
386
  denoising_steps,
387
  num_inference_steps,
388
  guidance_scale,
 
 
389
  randomize_seed,
390
  seed,
391
  debug_mode
@@ -410,6 +434,8 @@ with gr.Blocks() as interface:
410
  1000,
411
  50,
412
  7,
 
 
413
  True,
414
  42,
415
  False
@@ -426,6 +452,8 @@ with gr.Blocks() as interface:
426
  1000,
427
  50,
428
  7,
 
 
429
  True,
430
  42,
431
  False
@@ -442,6 +470,8 @@ with gr.Blocks() as interface:
442
  1000,
443
  50,
444
  7,
 
 
445
  True,
446
  42,
447
  False
 
30
  denoising_steps,
31
  num_inference_steps,
32
  guidance_scale,
33
+ image_guidance_scale,
34
+ strength,
35
  randomize_seed,
36
  seed,
37
  debug_mode,
 
74
  denoising_steps,
75
  num_inference_steps,
76
  guidance_scale,
77
+ image_guidance_scale,
78
+ strength,
79
  randomize_seed,
80
  seed,
81
  debug_mode,
 
92
  denoising_steps,
93
  num_inference_steps,
94
  guidance_scale,
95
+ image_guidance_scale,
96
+ strength,
97
  randomize_seed,
98
  seed,
99
  debug_mode
 
128
  if guidance_scale is None:
129
  guidance_scale = 7
130
 
131
+ if image_guidance_scale is None:
132
+ image_guidance_scale = 1.5
133
+
134
+ if strength is None:
135
+ strength = 0.99
136
+
137
  if randomize_seed:
138
  seed = random.randint(0, max_64_bit_int)
139
 
 
194
 
195
  # Mask
196
  mask_image = Image.new(mode = input_image.mode, size = (output_width, output_height), color = (255, 255, 255, 0))
197
+ black_mask = Image.new(mode = input_image.mode, size = (original_width - smooth_border, original_height - smooth_border), color = (0, 0, 0, 0))
198
  mask_image.paste(black_mask, (enlarge_left + (smooth_border // 2), enlarge_top + (smooth_border // 2)))
199
  mask_image = mask_image.filter(ImageFilter.BoxBlur((smooth_border // 2)))
200
 
 
238
  mask_image = mask_image,
239
  num_inference_steps = num_inference_steps,
240
  guidance_scale = guidance_scale,
241
+ image_guidance_scale = image_guidance_scale,
242
+ strength = strength,
243
  denoising_steps = denoising_steps,
244
  show_progress_bar = True
245
  ).images[0]
 
322
  with gr.Row():
323
  prompt = gr.Textbox(label = 'Prompt', info = "Describe the subject, the background and the style of image; 77 token limit", placeholder = 'Describe what you want to see in the entire image')
324
  with gr.Row():
325
+ with gr.Accordion("Advanced options", open = False):
326
  negative_prompt = gr.Textbox(label = 'Negative prompt', placeholder = 'Describe what you do NOT want to see in the entire image', value = 'Border, frame, painting, scribbling, smear, noise, blur, watermark')
327
  smooth_border = gr.Slider(minimum = 0, maximum = 1024, value = 0, step = 2, label = "Smooth border", info = "lower=preserve original, higher=seamless")
328
  denoising_steps = gr.Slider(minimum = 0, maximum = 1000, value = 1000, step = 1, label = "Denoising", info = "lower=irrelevant result, higher=relevant result")
329
  num_inference_steps = gr.Slider(minimum = 10, maximum = 100, value = 50, step = 1, label = "Number of inference steps", info = "lower=faster, higher=image quality")
330
  guidance_scale = gr.Slider(minimum = 1, maximum = 13, value = 7, step = 0.1, label = "Classifier-Free Guidance Scale", info = "lower=image quality, higher=follow the prompt")
331
+ image_guidance_scale = gr.Slider(minimum = 1, value = 1.5, step = 0.1, label = "Image Guidance Scale", info = "lower=image quality, higher=follow the image")
332
+ strength = gr.Number(value = 0.99, minimum = 0.01, maximum = 1.0, step = 0.01, label = "Strength", info = "lower=follow the original area (discouraged), higher=redraw from scratch")
333
  randomize_seed = gr.Checkbox(label = "\U0001F3B2 Randomize seed (not working, always checked)", value = True, info = "If checked, result is always different")
334
  seed = gr.Slider(minimum = 0, maximum = max_64_bit_int, step = 1, randomize = True, label = "Seed (if not randomized)")
335
  debug_mode = gr.Checkbox(label = "Debug mode", value = False, info = "Show intermediate results")
336
+
337
  with gr.Row():
338
  submit = gr.Button("Uncrop", variant = "primary")
339
+
340
  with gr.Row():
341
  uncropped_image = gr.Image(label = "Uncropped image")
342
  with gr.Row():
 
364
  denoising_steps,
365
  num_inference_steps,
366
  guidance_scale,
367
+ image_guidance_scale,
368
+ strength,
369
  randomize_seed,
370
  seed,
371
  debug_mode
 
382
  denoising_steps,
383
  num_inference_steps,
384
  guidance_scale,
385
+ image_guidance_scale,
386
+ strength,
387
  randomize_seed,
388
  seed,
389
  debug_mode
 
408
  denoising_steps,
409
  num_inference_steps,
410
  guidance_scale,
411
+ image_guidance_scale,
412
+ strength,
413
  randomize_seed,
414
  seed,
415
  debug_mode
 
434
  1000,
435
  50,
436
  7,
437
+ 1.5,
438
+ 0.99,
439
  True,
440
  42,
441
  False
 
452
  1000,
453
  50,
454
  7,
455
+ 1.5,
456
+ 0.99,
457
  True,
458
  42,
459
  False
 
470
  1000,
471
  50,
472
  7,
473
+ 1.5,
474
+ 0.99,
475
  True,
476
  42,
477
  False