diff --git a/modules/extras.py b/modules/extras.py
index adc88ca558b..ba89bc37b60 100644
--- a/modules/extras.py
+++ b/modules/extras.py
@@ -2,38 +2,113 @@
import re
import shutil
import json
-
+import html
import torch
import tqdm
-from modules import shared, images, sd_models, sd_vae, sd_models_config, errors
+from modules import shared, images, sd_models, sd_vae, sd_models_config, errors, infotext_utils
from modules.ui_common import plaintext_to_html
import gradio as gr
import safetensors.torch
-def run_pnginfo(image):
- if image is None:
- return '', '', ''
+def pnginfo_format_string(plain_text):
+ content = "
\n".join(html.escape(x) for x in str(plain_text).split('\n'))
+ return content
- geninfo, items = images.read_info_from_image(image)
+
+def pnginfo_format_setting(name, value):
+ cls_name = 'geninfo-setting-string' if value.startswith('"') else 'geninfo-setting-value'
+ return f"{html.escape(name)}: {html.escape(value)}"
+
+
+def pnginfo_format_quicklink(name):
+ return f"[{html.escape(name)}]"
+
+
+def pnginfo_html_v1(geninfo, items):
items = {**{'parameters': geninfo}, **items}
+ info_html = ''
+ for key, text in items.items():
+ info_html += f"""
{plaintext_to_html(str(key))}
+{plaintext_to_html(str(text))}
+{message}
parameters
+{pnginfo_format_quicklink("Copy")} {pnginfo_format_quicklink("Prompt")}"""
+ if negative_prompt:
+ info_html += f' {pnginfo_format_quicklink("Negative")}'
+ info_html += f""" {pnginfo_format_quicklink("Settings")}
+
{pnginfo_format_string(prompt)}
""" + if negative_prompt: + info_html += f""" +
+Negative prompt:
{pnginfo_format_string(negative_prompt)}
+
" + first = True + for key, value in res.items(): + if first: + first = False + else: + info_html += ", " + info_html += pnginfo_format_setting(key, value) + info_html += "
" + info_html += "{plaintext_to_html(str(key))}
{plaintext_to_html(str(text))}
{message}
{message}