Update !fetch command, add documentation and autocomplete list

-- !fetch takes second optional argument name of the file to save commands to
This commit is contained in:
ArDiouscuros
2022-10-03 10:38:22 +02:00
parent 93b1298d46
commit 935a9d3c75
3 changed files with 35 additions and 9 deletions

View File

@ -249,16 +249,31 @@ generated image and either loads them into the command line
(Linux|Mac), or prints them out in a comment for copy-and-paste (Linux|Mac), or prints them out in a comment for copy-and-paste
(Windows). You may provide either the name of a file in the current (Windows). You may provide either the name of a file in the current
output directory, or a full file path. output directory, or a full file path.
Given a wildcard path to a folder with image png files,
command will retrieve the dream command used to generate the images,
and save them to a file commands.txt for further processing
Name of the saved file could be set as the second argument to !fetch
~~~ ~~~
dream> !fetch 0000015.8929913.png dream> !fetch 0000015.8929913.png
# the script returns the next line, ready for editing and running: # the script returns the next line, ready for editing and running:
dream> a fantastic alien landscape -W 576 -H 512 -s 60 -A plms -C 7.5 dream> a fantastic alien landscape -W 576 -H 512 -s 60 -A plms -C 7.5
dream> !fetch outputs\selected-imgs\*.png selected.txt
>> File outputs\selected-imgs\selected.txt with commands created
~~~ ~~~
Note that this command may behave unexpectedly if given a PNG file that Note that this command may behave unexpectedly if given a PNG file that
was not generated by InvokeAI. was not generated by InvokeAI.
## !replay
This command replays a text file generated by !fetch or created manually
~~~
dream> !replay outputs\selected-imgs\selected.txt
~~~
## !history ## !history
The dream script keeps track of all the commands you issue during a The dream script keeps track of all the commands you issue during a

View File

@ -44,7 +44,7 @@ COMMANDS = (
'-save_orig','--save_original', '-save_orig','--save_original',
'--skip_normalize','-x', '--skip_normalize','-x',
'--log_tokenization','-t', '--log_tokenization','-t',
'!fix','!fetch','!history', '!fix','!fetch','!history','!replay'
) )
IMG_PATH_COMMANDS = ( IMG_PATH_COMMANDS = (
'--outdir[=\s]', '--outdir[=\s]',

View File

@ -513,7 +513,7 @@ def split_variations(variations_string) -> list:
else: else:
return parts return parts
def retrieve_dream_command(opt,file_path,completer): def retrieve_dream_command(opt,command,completer):
''' '''
Given a full or partial path to a previously-generated image file, Given a full or partial path to a previously-generated image file,
will retrieve and format the dream command used to generate the image, will retrieve and format the dream command used to generate the image,
@ -523,10 +523,22 @@ def retrieve_dream_command(opt,file_path,completer):
will retrieve and format the dream command used to generate the images, will retrieve and format the dream command used to generate the images,
and save them to a file commands.txt for further processing and save them to a file commands.txt for further processing
''' '''
if len(command) == 0:
return
tokens = command.split()
if len(tokens) > 1:
outfilepath = tokens[1]
else:
outfilepath = "commands.txt"
file_path = tokens[0]
dir,basename = os.path.split(file_path) dir,basename = os.path.split(file_path)
if len(dir) == 0: if len(dir) == 0:
dir = opt.outdir dir = opt.outdir
outdir,outname = os.path.split(outfilepath)
if len(outdir) == 0:
outfilepath = os.path.join(dir,outname)
try: try:
paths = list(Path(dir).glob(basename)) paths = list(Path(dir).glob(basename))
except ValueError: except ValueError:
@ -543,16 +555,15 @@ def retrieve_dream_command(opt,file_path,completer):
except (KeyError, AttributeError): except (KeyError, AttributeError):
print(f'## {path}: file has no metadata') print(f'## {path}: file has no metadata')
continue continue
commands.append(f'# {path}')
commands.append(cmd) commands.append(cmd)
outfile = os.path.join(dir,'commands.txt') with open(outfilepath, 'w', encoding='utf-8') as f:
with open(outfile, 'w', encoding='utf-8') as f:
f.write('\n'.join(commands)) f.write('\n'.join(commands))
print(f'>> File {outfile} with commands created') print(f'>> File {outfilepath} with commands created')
if len(commands) == 1: if len(commands) == 2:
completer.set_line(commands[0]) completer.set_line(commands[1])
if __name__ == '__main__': if __name__ == '__main__':
main() main()