diff options
author | 不会画画的中医不是好程序员 <yfszzx@gmail.com> | 2022-10-13 23:35:07 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-13 23:35:07 +0000 |
commit | 7c8903367c350e7e3ba8f90679890566446f36b2 (patch) | |
tree | a949c12c2a93c4e20aff30adf4412a450f6b2b8e /modules/deepbooru.py | |
parent | a1489f94283c07824a7a58353c03dc89541bbe49 (diff) | |
parent | 08b3f7aef15f74f4d2254b1274dd66fcc7940348 (diff) | |
download | stable-diffusion-webui-gfx803-7c8903367c350e7e3ba8f90679890566446f36b2.tar.gz stable-diffusion-webui-gfx803-7c8903367c350e7e3ba8f90679890566446f36b2.tar.bz2 stable-diffusion-webui-gfx803-7c8903367c350e7e3ba8f90679890566446f36b2.zip |
Merge branch 'AUTOMATIC1111:master' into master
Diffstat (limited to 'modules/deepbooru.py')
-rw-r--r-- | modules/deepbooru.py | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/modules/deepbooru.py b/modules/deepbooru.py index 419e6a9c..f34f3788 100644 --- a/modules/deepbooru.py +++ b/modules/deepbooru.py @@ -19,6 +19,7 @@ def get_deepbooru_tags(pil_image): release_process() +OPT_INCLUDE_RANKS = "include_ranks" def create_deepbooru_opts(): from modules import shared @@ -26,6 +27,7 @@ def create_deepbooru_opts(): "use_spaces": shared.opts.deepbooru_use_spaces, "use_escape": shared.opts.deepbooru_escape, "alpha_sort": shared.opts.deepbooru_sort_alpha, + OPT_INCLUDE_RANKS: shared.opts.interrogate_return_ranks, } @@ -113,6 +115,7 @@ def get_deepbooru_tags_from_model(model, tags, pil_image, threshold, deepbooru_o alpha_sort = deepbooru_opts['alpha_sort'] use_spaces = deepbooru_opts['use_spaces'] use_escape = deepbooru_opts['use_escape'] + include_ranks = deepbooru_opts['include_ranks'] width = model.input_shape[2] height = model.input_shape[1] @@ -151,19 +154,20 @@ def get_deepbooru_tags_from_model(model, tags, pil_image, threshold, deepbooru_o if alpha_sort: sort_ndx = 1 - # sort by reverse by likelihood and normal for alpha + # sort by reverse by likelihood and normal for alpha, and format tag text as requested unsorted_tags_in_theshold.sort(key=lambda y: y[sort_ndx], reverse=(not alpha_sort)) for weight, tag in unsorted_tags_in_theshold: - result_tags_out.append(tag) + # note: tag_outformat will still have a colon if include_ranks is True + tag_outformat = tag.replace(':', ' ') + if use_spaces: + tag_outformat = tag_outformat.replace('_', ' ') + if use_escape: + tag_outformat = re.sub(re_special, r'\\\1', tag_outformat) + if include_ranks: + tag_outformat = f"({tag_outformat}:{weight:.3f})" - print('\n'.join(sorted(result_tags_print, reverse=True))) - - tags_text = ', '.join(result_tags_out) + result_tags_out.append(tag_outformat) - if use_spaces: - tags_text = tags_text.replace('_', ' ') - - if use_escape: - tags_text = re.sub(re_special, r'\\\1', tags_text) + print('\n'.join(sorted(result_tags_print, reverse=True))) - return tags_text.replace(':', ' ') + return ', '.join(result_tags_out) |