Skip to content

Commit

Permalink
add --version to invoke.py arguments (#2038)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
lstein committed Dec 20, 2022
1 parent ab2972f commit 6e98b55
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 15 deletions.
Empty file modified installer/create_installer.sh
100755 → 100644
Empty file.
3 changes: 1 addition & 2 deletions ldm/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
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():
Expand Down Expand Up @@ -265,8 +266,6 @@ def img2img(self, prompt, **kwargs):
), '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
Expand Down
6 changes: 1 addition & 5 deletions ldm/invoke/CLI.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
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
Expand All @@ -27,7 +27,6 @@
def main():
"""Initialize command-line parsers and the diffusion model"""
global infile
print('* Initializing, be patient...')

opt = Args()
args = opt.parse_args()
Expand All @@ -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.")
Expand Down
2 changes: 2 additions & 0 deletions ldm/invoke/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
__app_id__= 'invoke-ai/InvokeAI'
__app_name__= 'InvokeAI'
__version__='2.2.4'
30 changes: 22 additions & 8 deletions ldm/invoke/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,15 @@
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',
Expand All @@ -117,10 +122,6 @@
'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):
Expand Down Expand Up @@ -172,15 +173,22 @@ def parse_args(self):
'''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.')
Expand Down Expand Up @@ -405,6 +413,7 @@ def _create_arg_parser(self):
""",
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')
Expand All @@ -414,6 +423,11 @@ def _create_arg_parser(self):

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,
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 6e98b55

Please sign in to comment.