Interactive configuration (#1517)

* Update scripts/configure_invokeai.py

prevent crash if output exists

Co-authored-by: psychedelicious <4822129+psychedelicious@users.noreply.github.com>

* implement changes requested by reviews

* default to correct root and output directory on Windows systems

- Previously the script was relying on the readline buffer editing
  feature to set up the correct default. But this feature doesn't
  exist on windows.

- This commit detects when user typed return with an empty directory
  value and replaces with the default directory.

* improved readability of directory choices

* Update scripts/configure_invokeai.py

Co-authored-by: psychedelicious <4822129+psychedelicious@users.noreply.github.com>

* better error reporting at startup

- If user tries to run the script outside of the repo or runtime directory,
  a more informative message will appear explaining the problem.

Co-authored-by: psychedelicious <4822129+psychedelicious@users.noreply.github.com>
This commit is contained in:
Lincoln Stein 2022-11-27 21:29:56 -05:00 committed by GitHub
parent 9f02595ef2
commit 30c5a0b067
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 31 additions and 24 deletions

View File

@ -138,8 +138,6 @@ set err_msg=----- InvokeAI setup failed -----
.venv\Scripts\python -m pip install %no_cache_dir% --no-warn-script-location -e .
if %errorlevel% neq 0 goto err_exit
echo ***** Installed InvokeAI *****
copy installer\invoke.bat .\invoke.bat
echo ***** Installed invoke launcher script ******
@ -150,6 +148,7 @@ rd /s /q installer installer_files
call .venv\Scripts\python scripts\configure_invokeai.py
set err_msg=----- model download clone failed -----
if %errorlevel% neq 0 goto err_exit
deactivate
echo ***** Finished downloading models *****

1
installer/install.sh Executable file → Normal file
View File

@ -220,6 +220,7 @@ rm -rf installer/ installer_files/
.venv/bin/python3 scripts/configure_invokeai.py
_err_msg="\n----- model download clone failed -----\n"
_err_exit $? _err_msg
deactivate
echo -e "\n***** Finished downloading models *****\n"

View File

@ -39,6 +39,8 @@ Dataset_path = './configs/INITIAL_MODELS.yaml'
Default_config_file = './configs/models.yaml'
SD_Configs = './configs/stable-diffusion'
assert os.path.exists(Dataset_path),"The configs directory cannot be found. Please run this script from within the InvokeAI distribution directory, or from within the invokeai runtime directory."
Datasets = OmegaConf.load(Dataset_path)
completer = generic_completer(['yes','no'])
@ -561,14 +563,14 @@ def get_root(root:str=None)->str:
return root
#-------------------------------------
def select_root(yes_to_all:bool=False):
default = os.path.expanduser('~/invokeai')
def select_root(root:str, yes_to_all:bool=False):
default = root or os.path.expanduser('~/invokeai')
if (yes_to_all):
return default
completer.set_default_dir(default)
completer.complete_extensions(())
completer.set_line(default)
return input(f"Select a directory in which to install InvokeAI's models and configuration files [{default}]: ")
return input(f"Select a directory in which to install InvokeAI's models and configuration files [{default}]: ") or default
#-------------------------------------
def select_outputs(root:str,yes_to_all:bool=False):
@ -578,23 +580,32 @@ def select_outputs(root:str,yes_to_all:bool=False):
completer.set_default_dir(os.path.expanduser('~'))
completer.complete_extensions(())
completer.set_line(default)
return input('Select the default directory for image outputs [{default}]: ')
return input(f'Select the default directory for image outputs [{default}]: ') or default
#-------------------------------------
def initialize_rootdir(root:str,yes_to_all:bool=False):
assert os.path.exists('./configs'),'Run this script from within the top level of the InvokeAI source code directory, "InvokeAI"'
print(f'** INITIALIZING INVOKEAI RUNTIME DIRECTORY **')
root = root or select_root(yes_to_all)
outputs = select_outputs(root,yes_to_all)
Globals.root = root
print(f'InvokeAI models and configuration files will be placed into {root} and image outputs will be placed into {outputs}.')
print(f'\nYou may change these values at any time by editing the --root and --output_dir options in "{Globals.initfile}",')
root_selected = False
while not root_selected:
root = select_root(root,yes_to_all)
outputs = select_outputs(root,yes_to_all)
Globals.root = os.path.abspath(root)
outputs = outputs if os.path.isabs(outputs) else os.path.abspath(os.path.join(Globals.root,outputs))
print(f'\nInvokeAI models and configuration files will be placed into "{root}" and image outputs will be placed into "{outputs}".')
if not yes_to_all:
root_selected = yes_or_no('Accept these locations?')
else:
root_selected = True
print(f'\nYou may change the chosen directories at any time by editing the --root and --outdir options in "{Globals.initfile}",')
print(f'You may also change the runtime directory by setting the environment variable INVOKEAI_ROOT.\n')
for name in ('models','configs'):
for name in ['models','configs']:
os.makedirs(os.path.join(root,name), exist_ok=True)
for src in ['configs']:
for src in (['configs']):
dest = os.path.join(root,src)
if not os.path.samefile(src,dest):
shutil.copytree(src,dest,dirs_exist_ok=True)
@ -610,7 +621,7 @@ def initialize_rootdir(root:str,yes_to_all:bool=False):
# or renaming it and then running configure_invokeai.py again.
# The --root option below points to the folder in which InvokeAI stores its models, configs and outputs.
--root="{root}"
--root="{Globals.root}"
# the --outdir option controls the default location of image files.
--outdir="{outputs}"
@ -673,15 +684,10 @@ def main():
try:
introduction()
# We check for two files to see if the runtime directory is correctly initialized.
# 1. a key stable diffusion config file
# 2. the web front end static files
# We check for to see if the runtime directory is correctly initialized.
if Globals.root == '' \
or not os.path.exists(os.path.join(Globals.root,'configs/stable-diffusion/v1-inference.yaml')) \
or not os.path.exists(os.path.join(Globals.root,'frontend/dist')):
initialize_rootdir(Globals.root,(not opt.interactive) or opt.yes_to_all)
print(f'(Initializing with runtime root {Globals.root})\n')
or not os.path.exists(os.path.join(Globals.root,'configs/stable-diffusion/v1-inference.yaml')):
initialize_rootdir(Globals.root,opt.yes_to_all)
if opt.interactive:
print('** DOWNLOADING DIFFUSION WEIGHTS **')
@ -698,7 +704,8 @@ def main():
except KeyboardInterrupt:
print('\nGoodbye! Come back soon.')
except Exception as e:
print(f'\nA problem occurred during download.\nThe error was: "{str(e)}"')
print(f'\nA problem occurred during initialization.\nThe error was: "{str(e)}"')
print(traceback.format_exc())
#-------------------------------------
if __name__ == '__main__':