Generation Info: Formatted display, #252

ib4
AlUlkesh 2024-06-01 18:51:10 +02:00
parent 3d2d0f4c7b
commit 6b71b462f1
2 changed files with 72 additions and 29 deletions

View File

@ -1190,6 +1190,27 @@ def show_video(video_checkbox, img_file_name):
video_filename = None video_filename = None
return gr.update(value=video_filename, visible=video_checkbox_visible) return gr.update(value=video_filename, visible=video_checkbox_visible)
def img_file_info_format_visibility(img_file_info_format):
if img_file_info_format:
img_file_info_visible = False
img_file_info_formatted_visible = True
else:
img_file_info_visible = True
img_file_info_formatted_visible = False
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):
img_file_info_formatted = ""
lines = 6
prompt, negative_prompt, key_value_pairs = wib_db.split_exif_data(img_file_info)
if key_value_pairs:
img_file_info_formatted = f"Prompt: {prompt}\n\nNegative_prompt: {negative_prompt}\n\n"
lines = 5
for (key, value) in key_value_pairs:
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
dir_name = None dir_name = None
@ -1335,8 +1356,12 @@ def create_tab(tab: ImageBrowserTab, current_gr_tab: gr.Tab):
with gr.Row(): with gr.Row():
aes_filter_min = gr.Textbox(value="", label="Minimum score") aes_filter_min = gr.Textbox(value="", label="Minimum score")
aes_filter_max = gr.Textbox(value="", label="Maximum score") aes_filter_max = gr.Textbox(value="", label="Maximum score")
with gr.Row() as generation_info_panel: with gr.Box() as generation_info_panel:
img_file_info = gr.Textbox(label="Generation Info", interactive=False, lines=6, elem_id=f"{tab.base_tag}_image_browser_file_info") with gr.Row():
img_file_info_format = gr.Checkbox(value=opts.image_browser_info_format, label="Formatted display")
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_formatted = gr.Textbox(label="Generation Info", interactive=False, lines=6, visible=opts.image_browser_info_format)
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:
@ -1562,6 +1587,18 @@ def create_tab(tab: ImageBrowserTab, current_gr_tab: gr.Tab):
outputs=[warning_box], outputs=[warning_box],
show_progress=show_progress_setting show_progress=show_progress_setting
) )
img_file_info_format.change(
fn=img_file_info_format_visibility,
inputs=[img_file_info_format],
outputs=[img_file_info, img_file_info_formatted],
show_progress=show_progress_setting
)
img_file_info.change(
fn=img_file_info_do_format,
inputs=[img_file_info],
outputs=[img_file_info_formatted],
show_progress=show_progress_setting
)
# Others # Others
img_path_subdirs_button.click( img_path_subdirs_button.click(
@ -1843,6 +1880,7 @@ def on_ui_settings():
("image_browser_swipe", None, False, "Swipe left/right navigates to the next image"), ("image_browser_swipe", None, False, "Swipe left/right navigates to the next image"),
("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_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

@ -180,10 +180,11 @@ def migrate_path_recorder(cursor):
return return
def update_exif_data(cursor, file, info): def split_exif_data(info):
prompt = "0" prompt = "0"
negative_prompt = "0" negative_prompt = "0"
key_values = "0: 0" key_values = "0: 0"
key_value_pairs = []
if info != "0": if info != "0":
info_list = info.split("\n") info_list = info.split("\n")
prompt = "" prompt = ""
@ -201,7 +202,6 @@ def update_exif_data(cursor, file, info):
# multiline prompts # multiline prompts
prompt = f"{prompt}\n{info_item}" prompt = f"{prompt}\n{info_item}"
if key_values != "": if key_values != "":
key_value_pairs = []
key_value = "" key_value = ""
quote_open = False quote_open = False
for char in key_values + ",": for char in key_values + ",":
@ -216,37 +216,42 @@ def update_exif_data(cursor, file, info):
v = "" v = ""
key_value_pairs.append((k, v)) key_value_pairs.append((k, v))
key_value = "" key_value = ""
return prompt, negative_prompt, key_value_pairs
try: def update_exif_data(cursor, file, info):
cursor.execute(''' prompt, negative_prompt, key_value_pairs = split_exif_data(info)
INSERT INTO exif_data (file, key, value) if key_value_pairs:
VALUES (?, ?, ?) try:
''', (file, "prompt", prompt)) cursor.execute('''
except sqlite3.IntegrityError: INSERT INTO exif_data (file, key, value)
# Duplicate, delete all "file" entries and try again VALUES (?, ?, ?)
cursor.execute(''' ''', (file, "prompt", prompt))
DELETE FROM exif_data except sqlite3.IntegrityError:
WHERE file = ? # Duplicate, delete all "file" entries and try again
''', (file,)) cursor.execute('''
DELETE FROM exif_data
WHERE file = ?
''', (file,))
cursor.execute(''' cursor.execute('''
INSERT INTO exif_data (file, key, value) INSERT INTO exif_data (file, key, value)
VALUES (?, ?, ?) VALUES (?, ?, ?)
''', (file, "prompt", prompt)) ''', (file, "prompt", prompt))
cursor.execute('''
INSERT INTO exif_data (file, key, value)
VALUES (?, ?, ?)
''', (file, "negative_prompt", negative_prompt))
for (key, value) in key_value_pairs:
try:
cursor.execute(''' cursor.execute('''
INSERT INTO exif_data (file, key, value) INSERT INTO exif_data (file, key, value)
VALUES (?, ?, ?) VALUES (?, ?, ?)
''', (file, "negative_prompt", negative_prompt)) ''', (file, key, value))
except sqlite3.IntegrityError:
for (key, value) in key_value_pairs: pass
try:
cursor.execute('''
INSERT INTO exif_data (file, key, value)
VALUES (?, ?, ?)
''', (file, key, value))
except sqlite3.IntegrityError:
pass
return return