Skip to content

Commit

Permalink
dev(narugo): add empty metadata support for a41 webui images
Browse files Browse the repository at this point in the history
  • Loading branch information
narugo1992 committed Sep 7, 2024
1 parent a1720fd commit c02b2b2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
8 changes: 7 additions & 1 deletion imgutils/sd/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,13 @@ def parse_sdmeta_from_text(x: str) -> SDMetaData:
<class 'imgutils.sd.metadata.SDMetaData'>
"""
x = textwrap.dedent(x).strip()
*prompt_lines, argument_line = x.splitlines(keepends=False)
all_lines = x.splitlines(keepends=False)
if len(all_lines) >= 1:
prompt_lines = all_lines[:-1]
argument_line = all_lines[-1]
else:
prompt_lines = []
argument_line = ''
if len(_PARAM_PATTERN.findall(argument_line)) < 3:
prompt_lines.append(argument_line)
argument_line = ''
Expand Down
3 changes: 3 additions & 0 deletions test/sd/test_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,3 +397,6 @@ def _test_pnginfo(pinfo):
assert get_sdmeta_from_image(f) == sdimg_3_std
with _test_pnginfo(sdimg_4_std.pnginfo) as f:
assert get_sdmeta_from_image(f) == sdimg_4_std

def test_empty_info_parse(self):
assert parse_sdmeta_from_text('') == SDMetaData('', '', {})

0 comments on commit c02b2b2

Please sign in to comment.