mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
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:
parent
93b1298d46
commit
935a9d3c75
@ -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
|
||||
(Windows). You may provide either the name of a file in the current
|
||||
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
|
||||
# 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> !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
|
||||
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
|
||||
|
||||
The dream script keeps track of all the commands you issue during a
|
||||
|
@ -44,7 +44,7 @@ COMMANDS = (
|
||||
'-save_orig','--save_original',
|
||||
'--skip_normalize','-x',
|
||||
'--log_tokenization','-t',
|
||||
'!fix','!fetch','!history',
|
||||
'!fix','!fetch','!history','!replay'
|
||||
)
|
||||
IMG_PATH_COMMANDS = (
|
||||
'--outdir[=\s]',
|
||||
|
@ -513,7 +513,7 @@ def split_variations(variations_string) -> list:
|
||||
else:
|
||||
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,
|
||||
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,
|
||||
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)
|
||||
if len(dir) == 0:
|
||||
dir = opt.outdir
|
||||
|
||||
outdir,outname = os.path.split(outfilepath)
|
||||
if len(outdir) == 0:
|
||||
outfilepath = os.path.join(dir,outname)
|
||||
try:
|
||||
paths = list(Path(dir).glob(basename))
|
||||
except ValueError:
|
||||
@ -543,16 +555,15 @@ def retrieve_dream_command(opt,file_path,completer):
|
||||
except (KeyError, AttributeError):
|
||||
print(f'## {path}: file has no metadata')
|
||||
continue
|
||||
|
||||
commands.append(f'# {path}')
|
||||
commands.append(cmd)
|
||||
|
||||
outfile = os.path.join(dir,'commands.txt')
|
||||
with open(outfile, 'w', encoding='utf-8') as f:
|
||||
with open(outfilepath, 'w', encoding='utf-8') as f:
|
||||
f.write('\n'.join(commands))
|
||||
print(f'>> File {outfile} with commands created')
|
||||
print(f'>> File {outfilepath} with commands created')
|
||||
|
||||
if len(commands) == 1:
|
||||
completer.set_line(commands[0])
|
||||
if len(commands) == 2:
|
||||
completer.set_line(commands[1])
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
Loading…
Reference in New Issue
Block a user