enhance outcropping with ability to direct contents of new regions

This commit does several things that improve the customizability of the CLI `outcrop` command:

1. When outcropping an image you can now add a `--new_prompt` option, to specify a new prompt to be applied to the outpainted region instead of the prompt used to generate the image.
2. Similarly you can provide a new seed using `--seed` (or `-S`). A seed less than zero will pick one randomly.
3. The metadata written into the outcropped file is now more informative about what was previously stored.
4. This PR also fixes the crash that happened when trying to outcrop an image  that does not contain InvokeAI metadata.

Other changes:

- add error checking suggested by @Kyle0654
- add special case in invoke.py to allow -1 to be passed as seed.
  This now only occurs for postprocessing commands. Previously, -1
  caused previous seed to be used, and this still applies to generate
  operations.
This commit is contained in:
Lincoln Stein
2022-11-08 17:27:42 +00:00
parent 5606af5083
commit 9141132a5c
7 changed files with 60 additions and 19 deletions

View File

@ -561,18 +561,22 @@ class Generate:
):
# retrieve the seed from the image;
seed = None
image_metadata = None
prompt = None
args = metadata_from_png(image_path)
seed = args.seed
prompt = args.prompt or ''
if seed == 0:
seed = random.randrange(0, np.iinfo(np.uint32).max)
opt.seed = seed
print(f'>> generated new seed {seed} and prompt "{prompt}" for {image_path}')
if opt.seed is not None:
seed = opt.seed
elif args.seed >= 0:
seed = args.seed
else:
print(f'>> retrieved seed {seed} and prompt "{prompt}" from {image_path}')
seed = random.randrange(0, np.iinfo(np.uint32).max)
if opt.prompt is not None:
prompt = opt.prompt
else:
prompt = args.prompt
print(f'>> using seed {seed} and prompt "{prompt}" for {image_path}')
# try to reuse the same filename prefix as the original file.
# we take everything up to the first period
@ -619,6 +623,10 @@ class Generate:
extend_instructions[direction]=int(pixels)
except ValueError:
print(f'** invalid extension instruction. Use <directions> <pixels>..., as in "top 64 left 128 right 64 bottom 64"')
opt.seed = seed
opt.prompt = prompt
if len(extend_instructions)>0:
restorer = Outcrop(image,self,)
return restorer.process (