Generation Info: Customization, Dataframe display, #252

ib4
AlUlkesh 2024-06-02 10:00:35 +02:00
parent 8cda5e1ff9
commit 18816fc220
2 changed files with 20 additions and 11 deletions

View File

@ -91,7 +91,6 @@ js_dummy_return = None
log_file = os.path.join(scripts.basedir(), "image_browser.log") log_file = os.path.join(scripts.basedir(), "image_browser.log")
optimized_cache = None optimized_cache = None
show_progress_setting = True show_progress_setting = True
img_file_info_order = ["Model", "VAE", "Sampler", "Schedule", "Steps", "CFG scale", "Seed", "Size"]
db_version = wib_db.check() db_version = wib_db.check()
@ -1201,19 +1200,16 @@ def img_file_info_format_visibility(img_file_info_format):
return gr.update(visible=img_file_info_visible), gr.update(visible=img_file_info_formatted_visible) return gr.update(visible=img_file_info_visible), gr.update(visible=img_file_info_formatted_visible)
def img_file_info_do_format(img_file_info): def img_file_info_do_format(img_file_info):
img_file_info_formatted = "" img_file_info_formatted = []
lines = 6
prompt, negative_prompt, key_value_pairs = wib_db.split_exif_data(img_file_info) prompt, negative_prompt, key_value_pairs = wib_db.split_exif_data(img_file_info)
if key_value_pairs: if key_value_pairs:
img_file_info_formatted = f"Prompt: {prompt}\n\nNegative_prompt: {negative_prompt}\n\n" key_value_pairs.append(("Prompt", prompt))
lines = 5 key_value_pairs.append(("Negative prompt", negative_prompt))
# Sort the key_value_pairs by the order in img_file_info_order # Sort the key_value_pairs by the order in img_file_info_order
img_file_info_order = opts.image_browser_info_order.split(',')
key_value_pairs = sorted(key_value_pairs, key=lambda pair: (img_file_info_order.index(pair[0]) if pair[0] in img_file_info_order else len(img_file_info_order), pair[0])) key_value_pairs = sorted(key_value_pairs, key=lambda pair: (img_file_info_order.index(pair[0]) if pair[0] in img_file_info_order else len(img_file_info_order), pair[0]))
img_file_info_formatted = key_value_pairs
for (key, value) in key_value_pairs: return img_file_info_formatted
img_file_info_formatted = img_file_info_formatted + f"{key}: {value}\n"
lines = lines + 1
return gr.update(value=img_file_info_formatted, lines=lines)
def create_tab(tab: ImageBrowserTab, current_gr_tab: gr.Tab): def create_tab(tab: ImageBrowserTab, current_gr_tab: gr.Tab):
global init, exif_cache, aes_cache, openoutpaint, controlnet, js_dummy_return, show_progress_setting global init, exif_cache, aes_cache, openoutpaint, controlnet, js_dummy_return, show_progress_setting
@ -1365,7 +1361,7 @@ def create_tab(tab: ImageBrowserTab, current_gr_tab: gr.Tab):
img_file_info_format = gr.Checkbox(value=opts.image_browser_info_format, label="Formatted display") img_file_info_format = gr.Checkbox(value=opts.image_browser_info_format, label="Formatted display")
with gr.Row(): with gr.Row():
img_file_info = gr.Textbox(label="Generation Info", interactive=False, lines=6, visible=not opts.image_browser_info_format) img_file_info = gr.Textbox(label="Generation Info", interactive=False, lines=6, visible=not opts.image_browser_info_format)
img_file_info_formatted = gr.Textbox(label="Generation Info", interactive=False, lines=6, visible=opts.image_browser_info_format) img_file_info_formatted = gr.DataFrame(label="Generation Info", headers=["Key", "Value"], wrap=True, interactive=False, visible=opts.image_browser_info_format, elem_classes="image_browser_file_info_formatted")
with gr.Row() as filename_panel: with gr.Row() as filename_panel:
img_file_name = gr.Textbox(value="", label="File Name", interactive=False) img_file_name = gr.Textbox(value="", label="File Name", interactive=False)
with gr.Row() as filetime_panel: with gr.Row() as filetime_panel:
@ -1885,6 +1881,7 @@ def on_ui_settings():
("image_browser_img_tooltips", None, True, "Enable thumbnail tooltips"), ("image_browser_img_tooltips", None, True, "Enable thumbnail tooltips"),
("image_browser_show_progress", None, True, "Show progress indicator"), ("image_browser_show_progress", None, True, "Show progress indicator"),
("image_browser_info_format", None, True, "Initially display Generation Info as formatted"), ("image_browser_info_format", None, True, "Initially display Generation Info as formatted"),
("image_browser_info_order", None, "Prompt,Negative prompt,Model,VAE,Sampler,Schedule,Steps,CFG scale,Seed,Size", "Display order for Generation Info as formatted"),
("image_browser_info_add", None, False, "Show Additional Generation Info"), ("image_browser_info_add", None, False, "Show Additional Generation Info"),
("image_browser_video_pos", None, "Above", "Video above or below gallery", gr.Dropdown, lambda: {"choices": ["Above", "Below"]}), ("image_browser_video_pos", None, "Above", "Video above or below gallery", gr.Dropdown, lambda: {"choices": ["Above", "Below"]}),
("image_browser_video_x", None, 640, "Video player width (px)"), ("image_browser_video_x", None, 640, "Video player width (px)"),

View File

@ -92,3 +92,15 @@ button[id$='_image_browser_del_img_btn'] {
margin-top: var(--text-xxl) !important; margin-top: var(--text-xxl) !important;
padding: 1px !important; padding: 1px !important;
} }
.image_browser_file_info_formatted {
width: 100%;
}
.image_browser_file_info_formatted th {
display: none;
}
.image_browser_file_info_formatted td:first-child {
width: 30%;
}
.image_browser_file_info_formatted td:not(:first-child) {
width: 70%;
}