Merge branch 'add-invokeai-initfile' into development

This commit is contained in:
Lincoln Stein 2022-11-08 13:41:11 +00:00
commit ededeaed86
7 changed files with 108 additions and 27 deletions

3
.gitignore vendored
View File

@ -209,3 +209,6 @@ configs/models.yaml
# weights (will be created by installer) # weights (will be created by installer)
models/ldm/stable-diffusion-v1/*.ckpt models/ldm/stable-diffusion-v1/*.ckpt
# ignore initfile
invokeai.init

View File

@ -91,6 +91,10 @@ overridden on a per-prompt basis (see
| `--port <port>` | | `9090` | Which port web server should listen for requests on. | | `--port <port>` | | `9090` | Which port web server should listen for requests on. |
| `--config <path>` | | `configs/models.yaml` | Configuration file for models and their weights. | | `--config <path>` | | `configs/models.yaml` | Configuration file for models and their weights. |
| `--iterations <int>` | `-n<int>` | `1` | How many images to generate per prompt. | | `--iterations <int>` | `-n<int>` | `1` | How many images to generate per prompt. |
| `--width <int>` | `-W<int>` | `512` | Width of generated image |
| `--height <int>` | `-H<int>` | `512` | Height of generated image | `--steps <int>` | `-s<int>` | `50` | How many steps of refinement to apply |
| `--strength <float>` | `-s<float>` | `0.75` | For img2img: how hard to try to match the prompt to the initial image. Ranges from 0.0-0.99, with higher values replacing the initial image completely. |
| `--fit` | `-F` | `False` | For img2img: scale the init image to fit into the specified -H and -W dimensions |
| `--grid` | `-g` | `False` | Save all image series as a grid rather than individually. | | `--grid` | `-g` | `False` | Save all image series as a grid rather than individually. |
| `--sampler <sampler>` | `-A<sampler>` | `k_lms` | Sampler to use. Use `-h` to get list of available samplers. | | `--sampler <sampler>` | `-A<sampler>` | `k_lms` | Sampler to use. Use `-h` to get list of available samplers. |
| `--seamless` | | `False` | Create interesting effects by tiling elements of the image. | | `--seamless` | | `False` | Create interesting effects by tiling elements of the image. |
@ -106,7 +110,7 @@ overridden on a per-prompt basis (see
| Argument | Shortcut | Default | Description | | Argument | Shortcut | Default | Description |
|--------------------|------------|---------------------|--------------| |--------------------|------------|---------------------|--------------|
| `--weights <path>` | | `None` | Pth to weights file; use `--model stable-diffusion-1.4` instead | | `--weights <path>` | | `None` | Path to weights file; use `--model stable-diffusion-1.4` instead |
| `--laion400m` | `-l` | `False` | Use older LAION400m weights; use `--model=laion400m` instead | | `--laion400m` | `-l` | `False` | Use older LAION400m weights; use `--model=laion400m` instead |
</div> </div>
@ -119,6 +123,29 @@ overridden on a per-prompt basis (see
You can either double your slashes (ick): `C:\\path\\to\\my\\file`, or You can either double your slashes (ick): `C:\\path\\to\\my\\file`, or
use Linux/Mac style forward slashes (better): `C:/path/to/my/file`. use Linux/Mac style forward slashes (better): `C:/path/to/my/file`.
## The .invokeai initialization file
To start up invoke.py with your preferred settings, place your desired
startup options in a file in your home directory named `.invokeai` The
file should contain the startup options as you would type them on the
command line (`--steps=10 --grid`), one argument per line, or a
mixture of both using any of the accepted command switch formats:
!!! example ""
```bash
--web
--steps=28
--grid
-f 0.6 -C 11.0 -A k_euler_a
```
Note that the initialization file only accepts the command line arguments.
There are additional arguments that you can provide on the `invoke>` command
line (such as `-n` or `--iterations`) that cannot be entered into this file.
Also be alert for empty blank lines at the end of the file, which will cause
an arguments error at startup time.
## List of prompt arguments ## List of prompt arguments
After the invoke.py script initializes, it will present you with a `invoke>` After the invoke.py script initializes, it will present you with a `invoke>`

View File

@ -36,7 +36,7 @@ dependencies:
- eventlet - eventlet
- getpass_asterisk - getpass_asterisk
- kornia==0.6.0 - kornia==0.6.0
- -e git+https://github.com/openai/CLIP.git@main#egg=clip - git+https://github.com/openai/CLIP.git@main#egg=clip
- -e git+https://github.com/CompVis/taming-transformers.git@master#egg=taming-transformers - -e git+https://github.com/CompVis/taming-transformers.git@master#egg=taming-transformers
- -e git+https://github.com/Birch-san/k-diffusion.git@mps#egg=k_diffusion - -e git+https://github.com/Birch-san/k-diffusion.git@mps#egg=k_diffusion
- -e git+https://github.com/invoke-ai/Real-ESRGAN.git#egg=realesrgan - -e git+https://github.com/invoke-ai/Real-ESRGAN.git#egg=realesrgan

View File

@ -87,6 +87,7 @@ import json
import hashlib import hashlib
import os import os
import re import re
import sys
import shlex import shlex
import copy import copy
import base64 import base64
@ -114,7 +115,8 @@ PRECISION_CHOICES = [
# is there a way to pick this up during git commits? # is there a way to pick this up during git commits?
APP_ID = 'invoke-ai/InvokeAI' APP_ID = 'invoke-ai/InvokeAI'
APP_VERSION = 'v2.02' APP_VERSION = 'v2.1.2'
INITFILE = os.path.expanduser('~/.invokeai')
class ArgFormatter(argparse.RawTextHelpFormatter): class ArgFormatter(argparse.RawTextHelpFormatter):
# use defined argument order to display usage # use defined argument order to display usage
@ -141,11 +143,15 @@ class ArgFormatter(argparse.RawTextHelpFormatter):
class PagingArgumentParser(argparse.ArgumentParser): class PagingArgumentParser(argparse.ArgumentParser):
''' '''
A custom ArgumentParser that uses pydoc to page its output. A custom ArgumentParser that uses pydoc to page its output.
It also supports reading defaults from an init file.
''' '''
def print_help(self, file=None): def print_help(self, file=None):
text = self.format_help() text = self.format_help()
pydoc.pager(text) pydoc.pager(text)
def convert_arg_line_to_args(self, arg_line):
return shlex.split(arg_line,comments=True)
class Args(object): class Args(object):
def __init__(self,arg_parser=None,cmd_parser=None): def __init__(self,arg_parser=None,cmd_parser=None):
''' '''
@ -162,9 +168,16 @@ class Args(object):
def parse_args(self): def parse_args(self):
'''Parse the shell switches and store.''' '''Parse the shell switches and store.'''
try: try:
self._arg_switches = self._arg_parser.parse_args() sysargs = sys.argv[1:]
if os.path.exists(INITFILE):
print(f'>> Initialization file {INITFILE} found. Loading...')
sysargs.insert(0,f'@{INITFILE}')
else:
print(f'>> Initialization file {INITFILE} not found. Applying default settings...')
self._arg_switches = self._arg_parser.parse_args(sysargs)
return self._arg_switches return self._arg_switches
except: except Exception as e:
print(f'An exception has occurred: {e}')
return None return None
def parse_cmd(self,cmd_string): def parse_cmd(self,cmd_string):
@ -357,7 +370,7 @@ class Args(object):
This defines all the arguments used on the command line when you launch This defines all the arguments used on the command line when you launch
the CLI or web backend. the CLI or web backend.
''' '''
parser = argparse.ArgumentParser( parser = PagingArgumentParser(
description= description=
""" """
Generate images using Stable Diffusion. Generate images using Stable Diffusion.
@ -367,6 +380,7 @@ class Args(object):
Other command-line arguments are defaults that can usually be overridden Other command-line arguments are defaults that can usually be overridden
prompt the command prompt. prompt the command prompt.
""", """,
fromfile_prefix_chars='@',
) )
model_group = parser.add_argument_group('Model selection') model_group = parser.add_argument_group('Model selection')
file_group = parser.add_argument_group('Input/output') file_group = parser.add_argument_group('Input/output')
@ -397,17 +411,6 @@ class Args(object):
dest='png_compression', dest='png_compression',
help='level of PNG compression, from 0 (none) to 9 (maximum). Default is 6.' help='level of PNG compression, from 0 (none) to 9 (maximum). Default is 6.'
) )
model_group.add_argument(
'--sampler',
'-A',
'-m',
dest='sampler_name',
type=str,
choices=SAMPLER_CHOICES,
metavar='SAMPLER_NAME',
help=f'Switch to a different sampler. Supported samplers: {", ".join(SAMPLER_CHOICES)}',
default='k_lms',
)
model_group.add_argument( model_group.add_argument(
'-F', '-F',
'--full_precision', '--full_precision',
@ -467,10 +470,61 @@ class Args(object):
type=str, type=str,
help='Overwrite the filename format. You can use any argument as wildcard enclosed in curly braces. Default is {prefix}.{seed}.png', help='Overwrite the filename format. You can use any argument as wildcard enclosed in curly braces. Default is {prefix}.{seed}.png',
) )
render_group.add_argument(
'-s',
'--steps',
type=int,
default=50,
help='Number of steps'
)
render_group.add_argument(
'-W',
'--width',
type=int,
help='Image width, multiple of 64',
)
render_group.add_argument(
'-H',
'--height',
type=int,
help='Image height, multiple of 64',
)
render_group.add_argument(
'-C',
'--cfg_scale',
default=7.5,
type=float,
help='Classifier free guidance (CFG) scale - higher numbers cause generator to "try" harder.',
)
render_group.add_argument(
'--sampler',
'-A',
'-m',
dest='sampler_name',
type=str,
choices=SAMPLER_CHOICES,
metavar='SAMPLER_NAME',
help=f'Set the default sampler. Supported samplers: {", ".join(SAMPLER_CHOICES)}',
default='k_lms',
)
render_group.add_argument(
'-f',
'--strength',
type=float,
help='img2img strength for noising/unnoising. 0.0 preserves image exactly, 1.0 replaces it completely',
)
render_group.add_argument(
'-T',
'-fit',
'--fit',
action=argparse.BooleanOptionalAction,
help='If specified, will resize the input image to fit within the dimensions of width x height (512x512 default)',
)
render_group.add_argument( render_group.add_argument(
'--grid', '--grid',
'-g', '-g',
action='store_true', action=argparse.BooleanOptionalAction,
help='generate a grid' help='generate a grid'
) )
render_group.add_argument( render_group.add_argument(
@ -599,7 +653,6 @@ class Args(object):
'-s', '-s',
'--steps', '--steps',
type=int, type=int,
default=50,
help='Number of steps' help='Number of steps'
) )
render_group.add_argument( render_group.add_argument(
@ -631,7 +684,6 @@ class Args(object):
render_group.add_argument( render_group.add_argument(
'-C', '-C',
'--cfg_scale', '--cfg_scale',
default=7.5,
type=float, type=float,
help='Classifier free guidance (CFG) scale - higher numbers cause generator to "try" harder.', help='Classifier free guidance (CFG) scale - higher numbers cause generator to "try" harder.',
) )
@ -656,7 +708,7 @@ class Args(object):
render_group.add_argument( render_group.add_argument(
'--grid', '--grid',
'-g', '-g',
action='store_true', action=argparse.BooleanOptionalAction,
help='generate a grid' help='generate a grid'
) )
render_group.add_argument( render_group.add_argument(
@ -750,8 +802,7 @@ class Args(object):
'-f', '-f',
'--strength', '--strength',
type=float, type=float,
help='Strength for noising/unnoising. 0.0 preserves image exactly, 1.0 replaces it completely', help='img2img strength for noising/unnoising. 0.0 preserves image exactly, 1.0 replaces it completely',
default=0.75,
) )
inpainting_group.add_argument( inpainting_group.add_argument(
'-M', '-M',

View File

@ -29,7 +29,7 @@ work fine.
import torch import torch
import numpy as np import numpy as np
from clipseg_models.clipseg import CLIPDensePredT from clipseg.clipseg import CLIPDensePredT
from einops import rearrange, repeat from einops import rearrange, repeat
from PIL import Image, ImageOps from PIL import Image, ImageOps
from torchvision import transforms from torchvision import transforms

0
scripts/invoke.py Normal file → Executable file
View File

View File

@ -2,7 +2,7 @@ from setuptools import setup, find_packages
setup( setup(
name='invoke-ai', name='invoke-ai',
version='2.0.2', version='2.1.3',
description='', description='',
packages=find_packages(), packages=find_packages(),
install_requires=[ install_requires=[