mirror of
https://github.com/AUTOMATIC1111/stable-diffusion-webui.git
synced 2025-04-11 23:39:01 +08:00
make PNG Info HTML style selectable
allowing user choose between new and old styles of HTML for PNG info page
This commit is contained in:
parent
0309360cb1
commit
d679154b22
@ -44,11 +44,11 @@ def pnginfo_html_v1(geninfo, items):
|
||||
|
||||
|
||||
def pnginfo_html_v2(geninfo, items):
|
||||
# raise ValueError
|
||||
|
||||
prompt, negative_prompt, last_line = infotext_utils.split_infotext(geninfo)
|
||||
res = infotext_utils.parameters_to_dict(last_line)
|
||||
if not any([prompt, res, items]):
|
||||
raise ValueError
|
||||
return pnginfo_html_v1(geninfo, items)
|
||||
|
||||
info_html = ''
|
||||
if prompt:
|
||||
@ -90,21 +90,25 @@ def pnginfo_html_v2(geninfo, items):
|
||||
return info_html
|
||||
|
||||
|
||||
pnginfo_html_map = {
|
||||
'Default': pnginfo_html_v2,
|
||||
'Parsed': pnginfo_html_v2,
|
||||
'Raw': pnginfo_html_v1,
|
||||
}
|
||||
|
||||
|
||||
def run_pnginfo(image):
|
||||
if image is None:
|
||||
return '', '', ''
|
||||
|
||||
geninfo, items = images.read_info_from_image(image)
|
||||
try:
|
||||
info = pnginfo_html_v2(geninfo, items)
|
||||
except ValueError:
|
||||
info = pnginfo_html_v1(geninfo, items)
|
||||
info_html = pnginfo_html_map.get(shared.opts.png_info_html_style, pnginfo_html_v2)(geninfo, items)
|
||||
|
||||
if len(info) == 0:
|
||||
if len(info_html) == 0:
|
||||
message = "Nothing found in the image."
|
||||
info = f"<div><p>{message}<p></div>"
|
||||
info_html = f"<div><p>{message}<p></div>"
|
||||
|
||||
return '', geninfo, info
|
||||
return '', geninfo, info_html
|
||||
|
||||
|
||||
def create_config(ckpt_result, config_source, a, b, c):
|
||||
|
@ -74,6 +74,11 @@ def reload_hypernetworks():
|
||||
shared.hypernetworks = hypernetwork.list_hypernetworks(cmd_opts.hypernetwork_dir)
|
||||
|
||||
|
||||
def list_pnginfo_html_methods():
|
||||
from modules.extras import pnginfo_html_map
|
||||
return list(pnginfo_html_map)
|
||||
|
||||
|
||||
def get_infotext_names():
|
||||
from modules import infotext_utils, shared
|
||||
res = {}
|
||||
|
@ -366,7 +366,7 @@ It is displayed in UI below the image. To use infotext, paste it into the prompt
|
||||
<li>Discard: remove style text from prompt, keep styles dropdown as it is.</li>
|
||||
<li>Apply if any: remove style text from prompt; if any styles are found in prompt, put them into styles dropdown, otherwise keep it as it is.</li>
|
||||
</ul>"""),
|
||||
|
||||
"png_info_html_style": OptionInfo("Default", "PNG Info style", gr.Radio, lambda: {"choices": shared_items.list_pnginfo_html_methods()}).info('"Default -> Parsed"'),
|
||||
}))
|
||||
|
||||
options_templates.update(options_section(('ui', "Live previews", "ui"), {
|
||||
|
Loading…
x
Reference in New Issue
Block a user