mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
Gracefully handle invalid files passed to !fix and !fetch
This commit is contained in:
parent
36ac66fff2
commit
72834ad16c
@ -201,9 +201,7 @@ def main_loop(gen, opt, infile):
|
|||||||
oldargs = metadata_from_png(opt.init_img)
|
oldargs = metadata_from_png(opt.init_img)
|
||||||
opt.prompt = oldargs.prompt
|
opt.prompt = oldargs.prompt
|
||||||
print(f'>> Retrieved old prompt "{opt.prompt}" from {opt.init_img}')
|
print(f'>> Retrieved old prompt "{opt.prompt}" from {opt.init_img}')
|
||||||
except AttributeError:
|
except (OSError, AttributeError, KeyError):
|
||||||
pass
|
|
||||||
except KeyError:
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if len(opt.prompt) == 0:
|
if len(opt.prompt) == 0:
|
||||||
@ -376,9 +374,6 @@ def do_postprocess (gen, opt, callback):
|
|||||||
file_path = opt.prompt # treat the prompt as the file pathname
|
file_path = opt.prompt # treat the prompt as the file pathname
|
||||||
if os.path.dirname(file_path) == '': #basename given
|
if os.path.dirname(file_path) == '': #basename given
|
||||||
file_path = os.path.join(opt.outdir,file_path)
|
file_path = os.path.join(opt.outdir,file_path)
|
||||||
if not os.path.exists(file_path):
|
|
||||||
print(f'* file {file_path} does not exist')
|
|
||||||
return
|
|
||||||
|
|
||||||
tool=None
|
tool=None
|
||||||
if opt.gfpgan_strength > 0:
|
if opt.gfpgan_strength > 0:
|
||||||
@ -391,17 +386,24 @@ def do_postprocess (gen, opt, callback):
|
|||||||
tool = 'outpaint'
|
tool = 'outpaint'
|
||||||
opt.save_original = True # do not overwrite old image!
|
opt.save_original = True # do not overwrite old image!
|
||||||
opt.last_operation = f'postprocess:{tool}'
|
opt.last_operation = f'postprocess:{tool}'
|
||||||
gen.apply_postprocessor(
|
try:
|
||||||
image_path = file_path,
|
gen.apply_postprocessor(
|
||||||
tool = tool,
|
image_path = file_path,
|
||||||
gfpgan_strength = opt.gfpgan_strength,
|
tool = tool,
|
||||||
codeformer_fidelity = opt.codeformer_fidelity,
|
gfpgan_strength = opt.gfpgan_strength,
|
||||||
save_original = opt.save_original,
|
codeformer_fidelity = opt.codeformer_fidelity,
|
||||||
upscale = opt.upscale,
|
save_original = opt.save_original,
|
||||||
out_direction = opt.out_direction,
|
upscale = opt.upscale,
|
||||||
callback = callback,
|
out_direction = opt.out_direction,
|
||||||
opt = opt,
|
callback = callback,
|
||||||
|
opt = opt,
|
||||||
)
|
)
|
||||||
|
except OSError:
|
||||||
|
print(f'** {file_path}: file could not be read')
|
||||||
|
return
|
||||||
|
except (KeyError, AttributeError):
|
||||||
|
print(f'** {file_path}: file has no metadata')
|
||||||
|
return
|
||||||
return opt.last_operation
|
return opt.last_operation
|
||||||
|
|
||||||
def prepare_image_metadata(
|
def prepare_image_metadata(
|
||||||
@ -518,8 +520,11 @@ def retrieve_dream_command(opt,file_path,completer):
|
|||||||
path = file_path
|
path = file_path
|
||||||
try:
|
try:
|
||||||
cmd = dream_cmd_from_png(path)
|
cmd = dream_cmd_from_png(path)
|
||||||
except FileNotFoundError:
|
except OSError:
|
||||||
print(f'** {path}: file not found')
|
print(f'** {path}: file could not be read')
|
||||||
|
return
|
||||||
|
except (KeyError, AttributeError):
|
||||||
|
print(f'** {path}: file has no metadata')
|
||||||
return
|
return
|
||||||
completer.set_line(cmd)
|
completer.set_line(cmd)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user