better html log
This commit is contained in:
parent
4fe08161a5
commit
c35321013a
|
|
@ -1 +1 @@
|
|||
version = '2.1.782'
|
||||
version = '2.1.783'
|
||||
|
|
|
|||
|
|
@ -5,6 +5,9 @@ from PIL import Image
|
|||
from modules.util import generate_temp_filename
|
||||
|
||||
|
||||
log_cache = {}
|
||||
|
||||
|
||||
def get_current_html_path():
|
||||
date_string, local_temp_filename, only_name = generate_temp_filename(folder=modules.config.path_outputs,
|
||||
extension='png')
|
||||
|
|
@ -18,27 +21,33 @@ def log(img, dic, single_line_number=3):
|
|||
Image.fromarray(img).save(local_temp_filename)
|
||||
html_name = os.path.join(os.path.dirname(local_temp_filename), 'log.html')
|
||||
|
||||
if not os.path.exists(html_name):
|
||||
with open(html_name, 'a+', encoding='utf-8') as f:
|
||||
f.write(f"<p>Fooocus Log {date_string} (private)</p>\n")
|
||||
f.write(f"<p>All images do not contain any hidden data.</p>")
|
||||
existing_log = log_cache.get(html_name, None)
|
||||
|
||||
with open(html_name, 'a+', encoding='utf-8') as f:
|
||||
div_name = only_name.replace('.', '_')
|
||||
f.write(f'<div id="{div_name}"><hr>\n')
|
||||
f.write(f"<p>{only_name}</p>\n")
|
||||
i = 0
|
||||
for k, v in dic:
|
||||
if i < single_line_number:
|
||||
f.write(f"<p>{k}: <b>{v}</b> </p>\n")
|
||||
if existing_log is None:
|
||||
if os.path.exists(html_name):
|
||||
existing_log = open(html_name, encoding='utf-8').read()
|
||||
else:
|
||||
existing_log = f'<p>Fooocus Log {date_string} (private)</p>\n<p>All images do not contain any hidden data.</p>'
|
||||
|
||||
div_name = only_name.replace('.', '_')
|
||||
item = f'<div id="{div_name}">\n'
|
||||
item += f"<p>{only_name}</p>\n"
|
||||
for i, (k, v) in enumerate(dic):
|
||||
if i < single_line_number:
|
||||
item += f"<p>{k}: <b>{v}</b> </p>\n"
|
||||
else:
|
||||
if (i - single_line_number) % 2 == 0:
|
||||
item += f"<p>{k}: <b>{v}</b>, "
|
||||
else:
|
||||
if (i - single_line_number) % 2 == 0:
|
||||
f.write(f"<p>{k}: <b>{v}</b>, ")
|
||||
else:
|
||||
f.write(f"{k}: <b>{v}</b></p>\n")
|
||||
i += 1
|
||||
f.write(f"<p><img src=\"{only_name}\" width=512 onerror=\"document.getElementById('{div_name}').style.display = 'none';\"></img></p></div>\n")
|
||||
item += f"{k}: <b>{v}</b></p>\n"
|
||||
item += f"<p><img src=\"{only_name}\" width=512 onerror=\"document.getElementById('{div_name}').style.display = 'none';\"></img></p><hr></div>\n"
|
||||
existing_log = item + existing_log
|
||||
|
||||
with open(html_name, 'w', encoding='utf-8') as f:
|
||||
f.write(existing_log)
|
||||
|
||||
print(f'Image generated with private log at: {html_name}')
|
||||
|
||||
log_cache[html_name] = existing_log
|
||||
|
||||
return
|
||||
|
|
|
|||
Loading…
Reference in New Issue