add --version to invoke.py arguments (#2038)

* add --version to invoke.py arguments

This commit allows invoke.py to print out its name and version
number when given the --version argument. I had to move some
status messages around in order to make the output clean.

There is still an early message about initializing patchmatch
that interferes with a clean print of the version, and in fact the
--no-patchmatch argument is not doing anything. This will be the
subject of a subsequent PR.

* export APP_ID and APP_VERSION

Needed to support the web backend.
This commit is contained in:
Lincoln Stein 2022-12-20 10:14:28 -05:00 committed by GitHub
parent ab2972f320
commit 6e98b5535d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 26 additions and 15 deletions

0
installer/create_installer.sh Executable file → Normal file
View File

View File

@ -42,6 +42,7 @@ from ldm.invoke.model_cache import ModelCache
from ldm.invoke.seamless import configure_model_padding
from ldm.invoke.txt2mask import Txt2Mask, SegmentedGrayscale
from ldm.invoke.concepts_lib import Concepts
from ldm.invoke.generator.inpaint import infill_methods
def fix_func(orig):
if hasattr(torch.backends, 'mps') and torch.backends.mps.is_available():
@ -265,8 +266,6 @@ class Generate:
), 'call to img2img() must include the init_img argument'
return self.prompt2png(prompt, outdir, **kwargs)
from ldm.invoke.generator.inpaint import infill_methods
def prompt2image(
self,
# these are common

View File

@ -8,8 +8,8 @@ import time
import traceback
import yaml
from ldm.generate import Generate
from ldm.invoke.globals import Globals
from ldm.generate import Generate
from ldm.invoke.prompt_parser import PromptParser
from ldm.invoke.readline import get_completer, Completer
from ldm.invoke.args import Args, metadata_dumps, metadata_from_png, dream_cmd_from_png
@ -27,7 +27,6 @@ infile = None
def main():
"""Initialize command-line parsers and the diffusion model"""
global infile
print('* Initializing, be patient...')
opt = Args()
args = opt.parse_args()
@ -45,9 +44,6 @@ def main():
print('--max_loaded_models must be >= 1; using 1')
args.max_loaded_models = 1
# alert - setting a global here
Globals.try_patchmatch = args.patchmatch
if not args.conf:
if not os.path.exists(os.path.join(Globals.root,'configs','models.yaml')):
print(f"\n** Error. The file {os.path.join(Globals.root,'configs','models.yaml')} could not be found.")

View File

@ -1 +1,3 @@
__app_id__= 'invoke-ai/InvokeAI'
__app_name__= 'InvokeAI'
__version__='2.2.4'

View File

@ -93,10 +93,15 @@ import copy
import base64
import functools
import warnings
import ldm.invoke
import ldm.invoke.pngwriter
from ldm.invoke.globals import Globals
from ldm.invoke.prompt_parser import split_weighted_subprompts
APP_ID = ldm.invoke.__app_id__
APP_NAME = ldm.invoke.__app_name__
APP_VERSION = ldm.invoke.__version__
SAMPLER_CHOICES = [
'ddim',
'k_dpm_2_a',
@ -117,10 +122,6 @@ PRECISION_CHOICES = [
'float16',
]
# is there a way to pick this up during git commits?
APP_ID = 'invoke-ai/InvokeAI'
APP_VERSION = 'v2.2.4'
class ArgFormatter(argparse.RawTextHelpFormatter):
# use defined argument order to display usage
def _format_usage(self, usage, actions, groups, prefix):
@ -172,15 +173,22 @@ class Args(object):
'''Parse the shell switches and store.'''
try:
sysargs = sys.argv[1:]
# pre-parse to get the root directory; ignore the rest
# pre-parse before we do any initialization to get root directory
# and intercept --version request
switches = self._arg_parser.parse_args(sysargs)
if switches.version:
print(f'{ldm.invoke.__app_name__} {ldm.invoke.__version__}')
sys.exit(0)
print('* Initializing, be patient...')
Globals.root = os.path.abspath(switches.root_dir or Globals.root)
Globals.try_patchmatch = switches.patchmatch
# now use root directory to find the init file
initfile = os.path.expanduser(os.path.join(Globals.root,Globals.initfile))
legacyinit = os.path.expanduser('~/.invokeai')
if os.path.exists(initfile):
print(f'>> Initialization file {initfile} found. Loading...')
print(f'>> Initialization file {initfile} found. Loading...',file=sys.stderr)
sysargs.insert(0,f'@{initfile}')
elif os.path.exists(legacyinit):
print(f'>> WARNING: Old initialization file found at {legacyinit}. This location is deprecated. Please move it to {Globals.root}/invokeai.init.')
@ -405,6 +413,7 @@ class Args(object):
""",
fromfile_prefix_chars='@',
)
general_group = parser.add_argument_group('General')
model_group = parser.add_argument_group('Model selection')
file_group = parser.add_argument_group('Input/output')
web_server_group = parser.add_argument_group('Web server')
@ -414,6 +423,11 @@ class Args(object):
deprecated_group.add_argument('--laion400m')
deprecated_group.add_argument('--weights') # deprecated
general_group.add_argument(
'--version','-V',
action='store_true',
help='Print InvokeAI version number'
)
model_group.add_argument(
'--root_dir',
default=None,
@ -1061,8 +1075,8 @@ def metadata_dumps(opt,
'model' : 'stable diffusion',
'model_id' : opt.model,
'model_hash' : model_hash,
'app_id' : APP_ID,
'app_version' : APP_VERSION,
'app_id' : ldm.invoke.__app_id__,
'app_version' : ldm.invoke.__version__,
}
# # add some RFC266 fields that are generated internally, and not as