mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
catch and handle malformed user inputs; documentation fixes
This commit is contained in:
parent
a7532b386a
commit
c477525036
20
README.md
20
README.md
@ -12,10 +12,11 @@ lets you create images from a prompt in just three lines of code:
|
||||
|
||||
~~~~
|
||||
from ldm.simplet2i import T2I
|
||||
model = T2I()
|
||||
model.text2image("a unicorn in manhattan")
|
||||
model = T2I()
|
||||
outputs = model.text2image("a unicorn in manhattan")
|
||||
~~~~
|
||||
|
||||
Outputs is a list of lists in the format [[filename1,seed1],[filename2,seed2]...]
|
||||
Please see ldm/simplet2i.py for more information.
|
||||
|
||||
## Interactive command-line interface similar to the Discord bot
|
||||
@ -27,6 +28,9 @@ server. The advantage of this is that the lengthy model
|
||||
initialization only happens once. After that image generation is
|
||||
fast.
|
||||
|
||||
The script uses the readline library to allow for in-line editing,
|
||||
command history (up and down arrows) and more.
|
||||
|
||||
Note that this has only been tested in the Linux environment!
|
||||
|
||||
~~~~
|
||||
@ -48,14 +52,18 @@ Outputs:
|
||||
outputs/txt2img-samples/00010.png: "ashley judd riding a camel" -n2 -S 1362479620
|
||||
|
||||
dream> "your prompt here" -n6 -g
|
||||
...
|
||||
outputs/txt2img-samples/00041.png: "your prompt here" -n6 -g -S 2685670268
|
||||
seeds for individual rows: [2685670268, 1216708065, 2335773498, 822223658, 714542046, 3395302430]
|
||||
~~~~
|
||||
|
||||
Command-line arguments (`./scripts/dream.py -h`) allow you to change
|
||||
Command-line arguments passed to the script allow you to change
|
||||
various defaults, and select between the mature stable-diffusion
|
||||
weights (512x512) and the older (256x256) latent diffusion weights
|
||||
(laion400m). Within the script, the switches are (mostly) identical to
|
||||
those used in the Discord bot, except you don't need to type "!dream".
|
||||
(laion400m). From the dream> prompt, the arguments are (mostly)
|
||||
identical to those used in the Discord bot, except you don't need to
|
||||
type "!dream". Pass "-h" (or "--help") to list the arguments.
|
||||
|
||||
For command-line help, type -h (or --help) at the dream> prompt.
|
||||
|
||||
## Workaround for machines with limited internet connectivity
|
||||
|
||||
|
@ -7,7 +7,8 @@ from ldm.simplet2i import T2I
|
||||
t2i = T2I(outdir = <path> // outputs/txt2img-samples
|
||||
model = <path> // models/ldm/stable-diffusion-v1/model.ckpt
|
||||
config = <path> // default="configs/stable-diffusion/v1-inference.yaml
|
||||
batch = <integer> // 1
|
||||
iterations = <integer> // how many times to run the sampling (1)
|
||||
batch = <integer> // how many images to generate per sampling (1)
|
||||
steps = <integer> // 50
|
||||
seed = <integer> // current system time
|
||||
sampler = ['ddim','plms'] // ddim
|
||||
@ -17,27 +18,33 @@ t2i = T2I(outdir = <path> // outputs/txt2img-samples
|
||||
cfg_scale = <float> // unconditional guidance scale (7.5)
|
||||
fixed_code = <boolean> // False
|
||||
)
|
||||
|
||||
# do the slow model initialization
|
||||
t2i.load_model()
|
||||
|
||||
# Do the fast inference & image generation. Any options passed here
|
||||
# override the default values assigned during class initialization
|
||||
# Will call load_model() if the model was not previously loaded.
|
||||
t2i.txt2img(prompt = <string> // required
|
||||
// the remaining option arguments override constructur value when present
|
||||
outdir = <path>
|
||||
iterations = <integer>
|
||||
batch = <integer>
|
||||
steps = <integer>
|
||||
seed = <integer>
|
||||
sampler = ['ddim','plms']
|
||||
grid = <boolean>
|
||||
width = <integer>
|
||||
height = <integer>
|
||||
cfg_scale = <float>
|
||||
# The method returns a list of images. Each row of the list is a sub-list of [filename,seed]
|
||||
results = t2i.txt2img(prompt = <string> // required
|
||||
outdir = <path> // the remaining option arguments override constructur value when present
|
||||
iterations = <integer>
|
||||
batch = <integer>
|
||||
steps = <integer>
|
||||
seed = <integer>
|
||||
sampler = ['ddim','plms']
|
||||
grid = <boolean>
|
||||
width = <integer>
|
||||
height = <integer>
|
||||
cfg_scale = <float>
|
||||
) -> boolean
|
||||
|
||||
for row in results:
|
||||
print(f'filename={row[0]}')
|
||||
print(f'seed ={row[1]}')
|
||||
|
||||
"""
|
||||
|
||||
import torch
|
||||
import numpy as np
|
||||
import random
|
||||
@ -126,7 +133,10 @@ class T2I:
|
||||
def txt2img(self,prompt,outdir=None,batch=None,iterations=None,
|
||||
steps=None,seed=None,grid=None,individual=None,width=None,height=None,
|
||||
cfg_scale=None,ddim_eta=None):
|
||||
""" generate an image from the prompt, writing iteration images into the outdir """
|
||||
"""
|
||||
Generate an image from the prompt, writing iteration images into the outdir
|
||||
The output is a list of lists in the format: [[filename1,seed1], [filename2,seed2],...]
|
||||
"""
|
||||
outdir = outdir or self.outdir
|
||||
steps = steps or self.steps
|
||||
seed = seed or self.seed
|
||||
|
@ -51,7 +51,7 @@ def main():
|
||||
|
||||
# preload the model
|
||||
t2i.load_model()
|
||||
print("\n* Initialization done! Awaiting your command...")
|
||||
print("\n* Initialization done! Awaiting your command (-h for help)...")
|
||||
|
||||
log_path = os.path.join(opt.outdir,"dream_log.txt")
|
||||
with open(log_path,'a') as log:
|
||||
@ -68,6 +68,7 @@ def main_loop(t2i,parser,log):
|
||||
print("goodbye!")
|
||||
break
|
||||
|
||||
# rearrange the arguments to mimic how it works in the Dream bot.
|
||||
elements = shlex.split(command)
|
||||
switches = ['']
|
||||
switches_started = False
|
||||
@ -81,11 +82,16 @@ def main_loop(t2i,parser,log):
|
||||
switches[0] += el
|
||||
switches[0] += ' '
|
||||
switches[0] = switches[0][:len(switches[0])-1]
|
||||
|
||||
try:
|
||||
opt = parser.parse_args(switches)
|
||||
except SystemExit:
|
||||
parser.print_help()
|
||||
pass
|
||||
continue
|
||||
if len(opt.prompt)==0:
|
||||
print("Try again with a prompt!")
|
||||
continue
|
||||
|
||||
results = t2i.txt2img(**vars(opt))
|
||||
print("Outputs:")
|
||||
write_log_message(opt,switches,results,log)
|
||||
@ -147,7 +153,7 @@ def create_argv_parser():
|
||||
|
||||
|
||||
def create_cmd_parser():
|
||||
parser = argparse.ArgumentParser(description="Parse terminal input in a discord 'dreambot' fashion")
|
||||
parser = argparse.ArgumentParser(description='Example: dream> a fantastic alien landscape -W1024 -H960 -s100 -n12')
|
||||
parser.add_argument('prompt')
|
||||
parser.add_argument('-s','--steps',type=int,help="number of steps")
|
||||
parser.add_argument('-S','--seed',type=int,help="image seed")
|
||||
|
Loading…
x
Reference in New Issue
Block a user