mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
Added --from_file argument to load input from a file. Closes #23
This commit is contained in:
parent
6d1219deec
commit
bc7b1fdd37
@ -67,29 +67,45 @@ def main():
|
|||||||
# gets rid of annoying messages about random seed
|
# gets rid of annoying messages about random seed
|
||||||
logging.getLogger("pytorch_lightning").setLevel(logging.ERROR)
|
logging.getLogger("pytorch_lightning").setLevel(logging.ERROR)
|
||||||
|
|
||||||
|
infile = None
|
||||||
|
try:
|
||||||
|
if opt.infile is not None:
|
||||||
|
infile = open(opt.infile,'r')
|
||||||
|
except FileNotFoundError as e:
|
||||||
|
print(e)
|
||||||
|
exit(-1)
|
||||||
|
|
||||||
# preload the model
|
# preload the model
|
||||||
if not debugging:
|
if not debugging:
|
||||||
t2i.load_model()
|
t2i.load_model()
|
||||||
print("\n* Initialization done! Awaiting your command (-h for help, 'q' to quit, 'cd' to change output dir, 'pwd' to print output dir)...")
|
print("\n* Initialization done! Awaiting your command (-h for help, 'q' to quit, 'cd' to change output dir, 'pwd' to print output dir)...")
|
||||||
|
|
||||||
log_path = os.path.join(opt.outdir,'..','dream_log.txt')
|
log_path = os.path.join(opt.outdir,'dream_log.txt')
|
||||||
with open(log_path,'a') as log:
|
with open(log_path,'a') as log:
|
||||||
cmd_parser = create_cmd_parser()
|
cmd_parser = create_cmd_parser()
|
||||||
main_loop(t2i,cmd_parser,log)
|
main_loop(t2i,cmd_parser,log,infile)
|
||||||
log.close()
|
log.close()
|
||||||
|
infile.close()
|
||||||
|
|
||||||
|
|
||||||
def main_loop(t2i,parser,log):
|
def main_loop(t2i,parser,log,infile):
|
||||||
''' prompt/read/execute loop '''
|
''' prompt/read/execute loop '''
|
||||||
done = False
|
done = False
|
||||||
|
|
||||||
while not done:
|
while not done:
|
||||||
try:
|
try:
|
||||||
command = input("dream> ")
|
command = infile.readline() if infile else input("dream> ")
|
||||||
except EOFError:
|
except EOFError:
|
||||||
done = True
|
done = True
|
||||||
break
|
break
|
||||||
|
|
||||||
|
if infile and len(command)==0:
|
||||||
|
done = True
|
||||||
|
break
|
||||||
|
|
||||||
|
if command.startswith(('#','//')):
|
||||||
|
continue
|
||||||
|
|
||||||
try:
|
try:
|
||||||
elements = shlex.split(command)
|
elements = shlex.split(command)
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
@ -98,7 +114,7 @@ def main_loop(t2i,parser,log):
|
|||||||
|
|
||||||
if len(elements)==0:
|
if len(elements)==0:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if elements[0]=='q':
|
if elements[0]=='q':
|
||||||
done = True
|
done = True
|
||||||
break
|
break
|
||||||
@ -232,6 +248,10 @@ def create_argv_parser():
|
|||||||
dest='laion400m',
|
dest='laion400m',
|
||||||
action='store_true',
|
action='store_true',
|
||||||
help="fallback to the latent diffusion (laion400m) weights and config")
|
help="fallback to the latent diffusion (laion400m) weights and config")
|
||||||
|
parser.add_argument("--from_file",
|
||||||
|
dest='infile',
|
||||||
|
type=str,
|
||||||
|
help="if specified, load prompts from this file")
|
||||||
parser.add_argument('-n','--iterations',
|
parser.add_argument('-n','--iterations',
|
||||||
type=int,
|
type=int,
|
||||||
default=1,
|
default=1,
|
||||||
|
Loading…
Reference in New Issue
Block a user