refactor html-info and do some linting cleanups

This commit is contained in:
Vladimir Mandic
2023-06-18 11:38:42 -04:00
parent 08db2462a2
commit 457dddf7aa
17 changed files with 69 additions and 76 deletions
+13 -12
View File
@@ -19,11 +19,11 @@ def update_generation_info(generation_info, html_info, img_index):
if img_index < 0 or img_index >= len(generation_info["infotexts"]):
return html_info, generation_info
infotext = generation_info["infotexts"][img_index]
html_text = infotext_to_html(infotext)
return html_text, infotext
html_info_formatted = infotext_to_html(infotext)
return html_info, html_info_formatted
except Exception:
pass
return html_info, generation_info
return html_info, html_info
def plaintext_to_html(text):
@@ -69,7 +69,7 @@ def delete_files(js_data, images, _html_info, _do_make_zip, index):
def save_files(js_data, images, html_info, do_make_zip, index):
os.makedirs(shared.opts.outdir_save, exist_ok=True)
class PObject: #quick dictionary to class object conversion. Its necessary due apply_filename_pattern requiring it
class PObject: # pylint: disable=too-few-public-methods
def __init__(self, d=None):
if d is not None:
for key, value in d.items():
@@ -152,11 +152,11 @@ def create_output_panel(tabname, outdir):
if platform.system() == "Windows":
os.startfile(path) # pylint: disable=no-member
elif platform.system() == "Darwin":
subprocess.Popen(["open", path])
subprocess.Popen(["open", path]) # pylint: disable=consider-using-with
elif "microsoft-standard-WSL2" in platform.uname().release:
subprocess.Popen(["wsl-open", path])
subprocess.Popen(["wsl-open", path]) # pylint: disable=consider-using-with
else:
subprocess.Popen(["xdg-open", path])
subprocess.Popen(["xdg-open", path]) # pylint: disable=consider-using-with
with gr.Column(variant='panel', elem_id=f"{tabname}_results"):
with gr.Group(elem_id=f"{tabname}_gallery_container"):
@@ -173,14 +173,15 @@ def create_output_panel(tabname, outdir):
open_folder_button.click(fn=lambda: open_folder(shared.opts.outdir_samples or outdir), inputs=[], outputs=[])
download_files = gr.File(None, file_count="multiple", interactive=False, show_label=False, visible=False, elem_id=f'download_files_{tabname}')
with gr.Group():
html_info = gr.HTML(elem_id=f'html_info_{tabname}', elem_classes="infotext")
html_info_raw = gr.Text(elem_id=f'html_info_raw_{tabname}', visible=False)
html_info = gr.HTML(elem_id=f'html_info_{tabname}', elem_classes="infotext", visible=False) # contains raw infotext as returned by wrapped call
html_info_formatted = gr.HTML(elem_id=f'html_info_formatted_{tabname}', elem_classes="infotext", visible=True) # contains html formatted infotext
html_info.change(fn=infotext_to_html, inputs=[html_info], outputs=[html_info_formatted], show_progress=False)
html_log = gr.HTML(elem_id=f'html_log_{tabname}')
generation_info = gr.Textbox(visible=False, elem_id=f'generation_info_{tabname}')
generation_info_button = gr.Button(visible=False, elem_id=f"{tabname}_generation_info_button")
generation_info_button.click(fn=update_generation_info, _js="(x, y, z) => [x, y, selected_gallery_index()]", show_progress=False,
generation_info_button.click(fn=update_generation_info, _js="(x, y, z) => [x, y, selected_gallery_index()]", show_progress=False, # triggered on gallery change from js
inputs=[generation_info, html_info, html_info],
outputs=[html_info, html_info_raw],
outputs=[html_info, html_info_formatted],
)
save.click(fn=call_queue.wrap_gradio_call(save_files), _js="(x, y, z, q1, q2) => [x, y, z, false, selected_gallery_index()]", show_progress=False,
inputs=[generation_info, result_gallery, html_info, html_info, html_info],
@@ -205,4 +206,4 @@ def create_output_panel(tabname, outdir):
parameters_copypaste.register_paste_params_button(parameters_copypaste.ParamBinding(
paste_button=paste_button, tabname=paste_tabname, source_tabname=("txt2img" if tabname == "txt2img" else None), source_image_component=result_gallery, paste_field_names=paste_field_names
))
return result_gallery, generation_info, html_info, html_log
return result_gallery, generation_info, html_info, html_info_formatted, html_log