import gradio as gr import csv import logging import os import platform import random import re import shutil import stat import subprocess as sp import sys import tempfile import time import modules.extras import modules.images import modules.ui from modules import paths, shared, script_callbacks, scripts, images from modules.shared import opts, cmd_opts from modules.ui_common import plaintext_to_html from modules.ui_components import ToolButton, DropdownMulti from scripts.wib import wib_db from PIL import Image, UnidentifiedImageError from pathlib import Path from typing import List, Tuple from itertools import chain from io import StringIO try: from send2trash import send2trash send2trash_installed = True except ImportError: print("Image Browser: send2trash is not installed. recycle bin cannot be used.") send2trash_installed = False yappi_do = False favorite_tab_name = "Favorites" default_tab_options = ["txt2img", "img2img", "txt2img-grids", "img2img-grids", "Extras", favorite_tab_name, "Others"] tabs_list = [tab.strip() for tab in chain.from_iterable(csv.reader(StringIO(opts.image_browser_active_tabs))) if tab] if hasattr(opts, "image_browser_active_tabs") else default_tab_options try: if opts.image_browser_enable_maint: tabs_list.append("Maintenance") # mandatory tab except AttributeError: tabs_list.append("Maintenance") # mandatory tab components_list = ["Sort by", "Filename keyword search", "EXIF keyword search", "Ranking Filter", "Aesthestic Score", "Generation Info", "File Name", "File Time", "Open Folder", "Send to buttons", "Copy to directory", "Gallery Controls Bar", "Ranking Bar", "Delete Bar", "Additional Generation Info"] num_of_imgs_per_page = 0 loads_files_num = 0 image_ext_list = [".png", ".jpg", ".jpeg", ".bmp", ".gif", ".webp"] finfo_aes = {} exif_cache = {} finfo_exif = {} aes_cache = {} none_select = "Nothing selected" refresh_symbol = '\U0001f504' # 🔄 up_symbol = '\U000025b2' # ▲ down_symbol = '\U000025bc' # ▼ caution_symbol = '\U000026a0' # ⚠folder_symbol = '\U0001f4c2' # 📂 current_depth = 0 init = True copy_move = ["Move", "Copy"] copied_moved = ["Moved", "Copied"] np = "negative_prompt: " openoutpaint = False controlnet = False path_maps = { "txt2img": opts.outdir_samples or opts.outdir_txt2img_samples, "img2img": opts.outdir_samples or opts.outdir_img2img_samples, "txt2img-grids": opts.outdir_grids or opts.outdir_txt2img_grids, "img2img-grids": opts.outdir_grids or opts.outdir_img2img_grids, "Extras": opts.outdir_samples or opts.outdir_extras_samples, favorite_tab_name: opts.outdir_save } class ImageBrowserTab(): seen_base_tags = set() def __init__(self, name: str): self.name: str = os.path.basename(name) if os.path.isdir(name) else name self.path: str = os.path.realpath(path_maps.get(name, name)) self.base_tag: str = f"image_browser_tab_{self.get_unique_base_tag(self.remove_invalid_html_tag_chars(self.name).lower())}" def remove_invalid_html_tag_chars(self, tag: str) -> str: # Removes any character that is not a letter, a digit, a hyphen, or an underscore removed = re.sub(r'[^a-zA-Z0-9\-_]', '', tag) return removed def get_unique_base_tag(self, base_tag: str) -> str: counter = 1 while base_tag in self.seen_base_tags: match = re.search(r'_(\d+)$', base_tag) if match: counter = int(match.group(1)) + 1 base_tag = re.sub(r'_(\d+)$', f"_{counter}", base_tag) else: base_tag = f"{base_tag}_{counter}" counter += 1 self.seen_base_tags.add(base_tag) return base_tag def __str__(self): return f"Name: {self.name} / Path: {self.path} / Base tag: {self.base_tag} / Seen base tags: {self.seen_base_tags}" tabs_list = [ImageBrowserTab(tab) for tab in tabs_list] # Logging logger = logging.getLogger(__name__) logger_mode = logging.ERROR if hasattr(opts, "image_browser_logger_warning"): if opts.image_browser_logger_warning: logger_mode = logging.WARNING if hasattr(opts, "image_browser_logger_debug"): if opts.image_browser_logger_debug: logger_mode = logging.DEBUG logger.setLevel(logger_mode) if (logger.hasHandlers()): logger.handlers.clear() console_handler = logging.StreamHandler() console_handler.setLevel(logger_mode) logger.addHandler(console_handler) # Debug logging if logger.isEnabledFor(logging.DEBUG): logger.debug(f"{sys.executable} {sys.version}") logger.debug(f"{platform.system()} {platform.version()}") try: git = os.environ.get('GIT', "git") commit_hash = os.popen(f"{git} rev-parse HEAD").read() except Exception as e: commit_hash = e logger.debug(f"{commit_hash}") logger.debug(f"Gradio {gr.__version__}") logger.debug(f"{paths.script_path}") with open(cmd_opts.ui_config_file, "r") as f: logger.debug(f.read()) with open(cmd_opts.ui_settings_file, "r") as f: logger.debug(f.read()) logger.debug(os.path.realpath(__file__)) logger.debug([str(tab) for tab in tabs_list]) def delete_recycle(filename): if opts.image_browser_delete_recycle and send2trash_installed: send2trash(filename) else: file = Path(filename) file.unlink() return def img_path_subdirs_get(img_path): subdirs = [] subdirs.append(none_select) for item in os.listdir(img_path): item_path = os.path.join(img_path, item) if os.path.isdir(item_path): subdirs.append(item_path) return gr.update(choices=subdirs) def img_path_add_remove(img_dir, path_recorder, add_remove, img_path_depth): img_dir = os.path.realpath(img_dir) if add_remove == "add" or (add_remove == "remove" and img_dir in path_recorder): if add_remove == "add": path_recorder[img_dir] = { "depth": int(img_path_depth), "path_display": f"{img_dir} [{int(img_path_depth)}]" } wib_db.update_path_recorder(img_dir, path_recorder[img_dir]["depth"], path_recorder[img_dir]["path_display"]) else: del path_recorder[img_dir] wib_db.delete_path_recorder(img_dir) path_recorder_formatted = [value.get("path_display") for key, value in path_recorder.items()] path_recorder_formatted = sorted(path_recorder_formatted, key=lambda x: natural_keys(x.lower())) if add_remove == "remove": selected = None else: selected = path_recorder[img_dir]["path_display"] return path_recorder, gr.update(choices=path_recorder_formatted, value=selected) def sort_order_flip(turn_page_switch, sort_order): if sort_order == up_symbol: sort_order = down_symbol else: sort_order = up_symbol return 1, -turn_page_switch, sort_order def read_path_recorder(): path_recorder = wib_db.load_path_recorder() path_recorder_formatted = [value.get("path_display") for key, value in path_recorder.items()] path_recorder_formatted = sorted(path_recorder_formatted, key=lambda x: natural_keys(x.lower())) path_recorder_unformatted = list(path_recorder.keys()) path_recorder_unformatted = sorted(path_recorder_unformatted, key=lambda x: natural_keys(x.lower())) return path_recorder, path_recorder_formatted, path_recorder_unformatted def pure_path(path): if path == []: return path, 0 match = re.search(r" \[(\d+)\]$", path) if match: path = path[:match.start()] depth = int(match.group(1)) else: depth = 0 path = os.path.realpath(path) return path, depth def browser2path(img_path_browser): img_path, _ = pure_path(img_path_browser) return img_path def totxt(file): base, _ = os.path.splitext(file) file_txt = base + '.txt' return file_txt def tab_select(): path_recorder, path_recorder_formatted, path_recorder_unformatted = read_path_recorder() return path_recorder, gr.update(choices=path_recorder_unformatted) def reduplicative_file_move(src, dst): def same_name_file(basename, path): name, ext = os.path.splitext(basename) f_list = os.listdir(path) max_num = 0 for f in f_list: if len(f) <= len(basename): continue f_ext = f[-len(ext):] if len(ext) > 0 else "" if f[:len(name)] == name and f_ext == ext: if f[len(name)] == "(" and f[-len(ext)-1] == ")": number = f[len(name)+1:-len(ext)-1] if number.isdigit(): if int(number) > max_num: max_num = int(number) return f"{name}({max_num + 1}){ext}" name = os.path.basename(src) save_name = os.path.join(dst, name) src_txt_exists = False if opts.image_browser_txt_files: src_txt = totxt(src) if os.path.exists(src_txt): src_txt_exists = True if not os.path.exists(save_name): if opts.image_browser_copy_image: shutil.copy2(src, dst) if opts.image_browser_txt_files and src_txt_exists: shutil.copy2(src_txt, dst) else: shutil.move(src, dst) if opts.image_browser_txt_files and src_txt_exists: shutil.move(src_txt, dst) else: name = same_name_file(name, dst) if opts.image_browser_copy_image: shutil.copy2(src, os.path.join(dst, name)) if opts.image_browser_txt_files and src_txt_exists: shutil.copy2(src_txt, totxt(os.path.join(dst, name))) else: shutil.move(src, os.path.join(dst, name)) if opts.image_browser_txt_files and src_txt_exists: shutil.move(src_txt, totxt(os.path.join(dst, name))) def save_image(file_name, filenames, page_index, turn_page_switch, dest_path): if file_name is not None and os.path.exists(file_name): reduplicative_file_move(file_name, dest_path) message = f"
 ") with gr.Column(scale=5, visible=(tab.name==favorite_tab_name)): gr.HTML(f"
Favorites path from settings: {opts.outdir_save}") with gr.Row(visible=others_dir): with gr.Column(scale=10): img_path = gr.Textbox(dir_name, label="Images directory", placeholder="Input images directory", interactive=others_dir) with gr.Column(scale=1): img_path_depth = gr.Number(value="0", label="Sub directory depth") with gr.Column(scale=1): img_path_save_button = gr.Button(value="Add to / replace in saved directories") with gr.Row(visible=others_dir): with gr.Column(scale=10): img_path_browser = gr.Dropdown(choices=path_recorder_formatted, label="Saved directories") with gr.Column(scale=1): img_path_remove_button = gr.Button(value="Remove from saved directories") with gr.Row(visible=others_dir): with gr.Column(scale=10): img_path_subdirs = gr.Dropdown(choices=[none_select], value=none_select, label="Sub directories", interactive=True, elem_id=f"{tab.base_tag}_img_path_subdirs") with gr.Column(scale=1): img_path_subdirs_button = gr.Button(value="Get sub directories") with gr.Row(visible=standard_ui, elem_id=f"{tab.base_tag}_image_browser") as main_panel: with gr.Column(): with gr.Row(): with gr.Column(scale=2): with gr.Row() as gallery_controls_panel: first_page = gr.Button('First Page') prev_page = gr.Button('Prev Page', elem_id=f"{tab.base_tag}_image_browser_prev_page") page_index = gr.Number(value=1, label="Page Index") refresh_index_button = ToolButton(value=refresh_symbol) next_page = gr.Button('Next Page', elem_id=f"{tab.base_tag}_image_browser_next_page") end_page = gr.Button('End Page') with gr.Row() as ranking_panel: ranking = gr.Radio(value="None", choices=["1", "2", "3", "4", "5", "None"], label="ranking", elem_id=f"{tab.base_tag}_image_browser_ranking", interactive=True, visible=False) with gr.Row(): image_gallery = gr.Gallery(show_label=False, elem_id=f"{tab.base_tag}_image_browser_gallery").style(grid=opts.image_browser_page_columns) with gr.Row() as delete_panel: with gr.Column(scale=1): delete_num = gr.Number(value=1, interactive=True, label="delete next") delete_confirm = gr.Checkbox(value=False, label="also delete off-screen images") with gr.Column(scale=3): delete = gr.Button('Delete', elem_id=f"{tab.base_tag}_image_browser_del_img_btn") with gr.Row() as info_add_panel: with gr.Accordion("Additional Generation Info", open=False): img_file_info_add = gr.HTML() with gr.Column(scale=1): with gr.Row(scale=0.5) as sort_panel: sort_by = gr.Dropdown(value="date", choices=["path name", "date", "aesthetic_score", "random", "cfg scale", "steps", "seed", "sampler", "size", "model", "model hash", "ranking"], label="Sort by") sort_order = ToolButton(value=down_symbol) with gr.Row() as filename_search_panel: filename_keyword_search = gr.Textbox(value="", label="Filename keyword search") with gr.Box() as exif_search_panel: with gr.Row(): exif_keyword_search = gr.Textbox(value="", label="EXIF keyword search") negative_prompt_search = gr.Radio(value="No", choices=["No", "Yes", "Only"], label="Search negative prompt", interactive=True) with gr.Row(): case_sensitive = gr.Checkbox(value=False, label="case sensitive") use_regex = gr.Checkbox(value=False, label=r"regex - e.g. ^(?!.*Hires).*$") with gr.Column() as ranking_filter_panel: ranking_filter = gr.Radio(value="All", choices=["All", "1", "2", "3", "4", "5", "None"], label="Ranking filter", interactive=True) with gr.Row() as aesthetic_score_filter_panel: aes_filter_min = gr.Textbox(value="", label="Minimum aesthetic_score") aes_filter_max = gr.Textbox(value="", label="Maximum aesthetic_score") with gr.Row() as generation_info_panel: img_file_info = gr.Textbox(label="Generation Info", interactive=False, lines=6) with gr.Row() as filename_panel: img_file_name = gr.Textbox(value="", label="File Name", interactive=False) with gr.Row() as filetime_panel: img_file_time= gr.HTML() with gr.Row() as open_folder_panel: open_folder_button = gr.Button(folder_symbol, visible=standard_ui or others_dir) gr.HTML(" ") gr.HTML(" ") gr.HTML(" ") with gr.Row(elem_id=f"{tab.base_tag}_image_browser_button_panel", visible=False) as button_panel: with gr.Column(): with gr.Row(): if tab.name != favorite_tab_name: favorites_btn = gr.Button(f'{copy_move[opts.image_browser_copy_image]} to favorites', elem_id=f"{tab.base_tag}_image_browser_favorites_btn") try: send_to_buttons = modules.generation_parameters_copypaste.create_buttons(["txt2img", "img2img", "inpaint", "extras"]) except: pass sendto_openoutpaint = gr.Button("Send to openOutpaint", elem_id=f"{tab.base_tag}_image_browser_openoutpaint_btn", visible=openoutpaint) with gr.Row(visible=controlnet): sendto_controlnet_txt2img = gr.Button("Send to txt2img ControlNet", visible=controlnet) sendto_controlnet_img2img = gr.Button("Send to img2img ControlNet", visible=controlnet) controlnet_max = opts.data.get("control_net_max_models_num", 1) sendto_controlnet_num = gr.Dropdown(list(range(controlnet_max)), label="ControlNet number", value="0", interactive=True, visible=(controlnet and controlnet_max > 1)) with gr.Row(elem_id=f"{tab.base_tag}_image_browser_to_dir_panel", visible=False) as to_dir_panel: with gr.Box(): with gr.Row(): to_dir_path = gr.Textbox(label="Directory path") with gr.Row(): to_dir_saved = gr.Dropdown(choices=path_recorder_unformatted, label="Saved directories") with gr.Row(): to_dir_btn = gr.Button(f'{copy_move[opts.image_browser_copy_image]} to directory', elem_id=f"{tab.base_tag}_image_browser_to_dir_btn") with gr.Row(): collected_warning = gr.HTML() # hidden items with gr.Row(visible=False): renew_page = gr.Button("Renew Page", elem_id=f"{tab.base_tag}_image_browser_renew_page") visible_img_num = gr.Number() tab_base_tag_box = gr.Textbox(tab.base_tag) image_index = gr.Textbox(value=-1) set_index = gr.Button('set_index', elem_id=f"{tab.base_tag}_image_browser_set_index") filenames = gr.State([]) all_images_list = gr.State() hidden = gr.Image(type="pil") info1 = gr.Textbox() info2 = gr.Textbox() load_switch = gr.Textbox(value="load_switch", label="load_switch") to_dir_load_switch = gr.Textbox(value="to dir load_switch", label="to_dir_load_switch") turn_page_switch = gr.Number(value=1, label="turn_page_switch") img_path_add = gr.Textbox(value="add") img_path_remove = gr.Textbox(value="remove") delete_state = gr.Checkbox(value=False, elem_id=f"{tab.base_tag}_image_browser_delete_state") favorites_path = gr.Textbox(value=opts.outdir_save) mod_keys = "" if opts.image_browser_mod_ctrl_shift: mod_keys = f"{mod_keys}CS" elif opts.image_browser_mod_shift: mod_keys = f"{mod_keys}S" image_browser_mod_keys = gr.Textbox(value=mod_keys, elem_id=f"{tab.base_tag}_image_browser_mod_keys") image_browser_prompt = gr.Textbox(elem_id=f"{tab.base_tag}_image_browser_prompt") image_browser_neg_prompt = gr.Textbox(elem_id=f"{tab.base_tag}_image_browser_neg_prompt") # Maintenance tab with gr.Row(visible=maint): with gr.Column(scale=4): gr.HTML(f"{caution_symbol} Caution: You should only use these options if you know what you are doing. {caution_symbol}") with gr.Column(scale=3): maint_wait = gr.HTML("Status:") with gr.Column(scale=7): gr.HTML(" ") with gr.Row(visible=maint): maint_last_msg = gr.Textbox(label="Last message", interactive=False) with gr.Row(visible=maint): with gr.Column(scale=1): maint_exif_rebuild = gr.Button(value="Rebuild exif cache") with gr.Column(scale=1): maint_exif_delete_0 = gr.Button(value="Delete 0-entries from exif cache") with gr.Column(scale=10): gr.HTML(visible=False) with gr.Row(visible=maint): with gr.Column(scale=1): maint_update_dirs = gr.Button(value="Update directory names in database") with gr.Column(scale=10): maint_update_dirs_from = gr.Textbox(label="From (full path)") with gr.Column(scale=10): maint_update_dirs_to = gr.Textbox(label="to (full path)") with gr.Row(visible=maint): with gr.Column(scale=1): maint_reapply_ranking = gr.Button(value="Reapply ranking after moving files") with gr.Column(scale=10): gr.HTML(visible=False) with gr.Row(visible=False): with gr.Column(scale=1): maint_rebuild_ranking = gr.Button(value="Rebuild ranking from exif info") with gr.Column(scale=10): gr.HTML(visible=False) # Hide components based on opts.image_browser_hidden_components hidden_component_map = { "Sort by": sort_panel, "Filename keyword search": filename_search_panel, "EXIF keyword search": exif_search_panel, "Ranking Filter": ranking_filter_panel, "Aesthestic Score": aesthetic_score_filter_panel, "Generation Info": generation_info_panel, "File Name": filename_panel, "File Time": filetime_panel, "Open Folder": open_folder_panel, "Send to buttons": button_panel, "Copy to directory": to_dir_panel, "Gallery Controls Bar": gallery_controls_panel, "Ranking Bar": ranking_panel, "Delete Bar": delete_panel, "Additional Generation Info": info_add_panel } if set(hidden_component_map.keys()) != set(components_list): logger.warning(f"Invalid items present in either hidden_component_map or components_list. Make sure when adding new components they are added to both.") override_hidden = set() if hasattr(opts, "image_browser_hidden_components"): for item in opts.image_browser_hidden_components: hidden_component_map[item].visible = False override_hidden.add(hidden_component_map[item]) change_dir_outputs = [warning_box, main_panel, img_path_browser, path_recorder, load_switch, img_path, img_path_depth] img_path.submit(change_dir, inputs=[img_path, path_recorder, load_switch, img_path_browser, img_path_depth, img_path], outputs=change_dir_outputs) img_path_browser.change(change_dir, inputs=[img_path_browser, path_recorder, load_switch, img_path_browser, img_path_depth, img_path], outputs=change_dir_outputs) # img_path_browser.change(browser2path, inputs=[img_path_browser], outputs=[img_path]) to_dir_saved.change(change_dir, inputs=[to_dir_saved, path_recorder, to_dir_load_switch, to_dir_saved, img_path_depth, to_dir_path], outputs=[warning_box, main_panel, to_dir_saved, path_recorder, to_dir_load_switch, to_dir_path, img_path_depth]) #delete delete.click(delete_image, inputs=[delete_num, img_file_name, filenames, image_index, visible_img_num, delete_confirm, turn_page_switch], outputs=[filenames, delete_num, delete_state, turn_page_switch, visible_img_num]) delete.click(fn=None, _js="image_browser_delete", inputs=[delete_num, tab_base_tag_box, image_index], outputs=None) if tab.name == favorite_tab_name: img_file_name.change(fn=update_move_text_one, inputs=[to_dir_btn], outputs=[to_dir_btn]) else: favorites_btn.click(save_image, inputs=[img_file_name, filenames, page_index, turn_page_switch, favorites_path], outputs=[collected_warning, filenames, page_index, turn_page_switch]) img_file_name.change(fn=update_move_text, inputs=[favorites_btn, to_dir_btn], outputs=[favorites_btn, to_dir_btn]) to_dir_btn.click(save_image, inputs=[img_file_name, filenames, page_index, turn_page_switch, to_dir_path], outputs=[collected_warning, filenames, page_index, turn_page_switch]) #turn page first_page.click(lambda s:(1, -s) , inputs=[turn_page_switch], outputs=[page_index, turn_page_switch]) next_page.click(lambda p, s: (p + 1, -s), inputs=[page_index, turn_page_switch], outputs=[page_index, turn_page_switch]) prev_page.click(lambda p, s: (p - 1, -s), inputs=[page_index, turn_page_switch], outputs=[page_index, turn_page_switch]) end_page.click(lambda s: (-1, -s), inputs=[turn_page_switch], outputs=[page_index, turn_page_switch]) load_switch.change(lambda s:(1, -s), inputs=[turn_page_switch], outputs=[page_index, turn_page_switch]) filename_keyword_search.submit(lambda s:(1, -s), inputs=[turn_page_switch], outputs=[page_index, turn_page_switch]) exif_keyword_search.submit(lambda s:(1, -s), inputs=[turn_page_switch], outputs=[page_index, turn_page_switch]) aes_filter_min.submit(lambda s:(1, -s), inputs=[turn_page_switch], outputs=[page_index, turn_page_switch]) aes_filter_max.submit(lambda s:(1, -s), inputs=[turn_page_switch], outputs=[page_index, turn_page_switch]) sort_by.change(lambda s:(1, -s), inputs=[turn_page_switch], outputs=[page_index, turn_page_switch]) ranking_filter.change(lambda s:(1, -s), inputs=[turn_page_switch], outputs=[page_index, turn_page_switch]) page_index.submit(lambda s: -s, inputs=[turn_page_switch], outputs=[turn_page_switch]) renew_page.click(lambda s: -s, inputs=[turn_page_switch], outputs=[turn_page_switch]) refresh_index_button.click(lambda p, s:(p, -s), inputs=[page_index, turn_page_switch], outputs=[page_index, turn_page_switch]) img_path_depth.change(lambda s: -s, inputs=[turn_page_switch], outputs=[turn_page_switch]) turn_page_switch.change( fn=get_image_page, inputs=[img_path, page_index, filenames, filename_keyword_search, sort_by, sort_order, tab_base_tag_box, img_path_depth, ranking_filter, aes_filter_min, aes_filter_max, exif_keyword_search, negative_prompt_search, use_regex, case_sensitive, delete_state], outputs=[filenames, page_index, image_gallery, img_file_name, img_file_time, img_file_info, visible_img_num, warning_box, delete_state, hidden] ) turn_page_switch.change(fn=None, inputs=[tab_base_tag_box], outputs=None, _js="image_browser_turnpage") hide_on_thumbnail_view = [delete_panel, button_panel, ranking, to_dir_panel, info_add_panel] turn_page_switch.change(fn=lambda:(gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False)), inputs=None, outputs=hide_on_thumbnail_view) sort_order.click( fn=sort_order_flip, inputs=[turn_page_switch, sort_order], outputs=[page_index, turn_page_switch, sort_order] ) # Others img_path_subdirs_button.click( fn=img_path_subdirs_get, inputs=[img_path], outputs=[img_path_subdirs] ) img_path_subdirs.change( fn=change_dir, inputs=[img_path_subdirs, path_recorder, load_switch, img_path_browser, img_path_depth, img_path], outputs=change_dir_outputs ) img_path_save_button.click( fn=img_path_add_remove, inputs=[img_path, path_recorder, img_path_add, img_path_depth], outputs=[path_recorder, img_path_browser] ) img_path_remove_button.click( fn=img_path_add_remove, inputs=[img_path, path_recorder, img_path_remove, img_path_depth], outputs=[path_recorder, img_path_browser] ) maint_exif_rebuild.click( fn=exif_rebuild, show_progress=True, inputs=[maint_wait], outputs=[maint_wait, maint_last_msg] ) maint_exif_delete_0.click( fn=exif_delete_0, show_progress=True, inputs=[maint_wait], outputs=[maint_wait, maint_last_msg] ) maint_update_dirs.click( fn=exif_update_dirs, show_progress=True, inputs=[maint_update_dirs_from, maint_update_dirs_to, maint_wait], outputs=[maint_wait, maint_last_msg] ) maint_reapply_ranking.click( fn=reapply_ranking, show_progress=True, inputs=[path_recorder, maint_wait], outputs=[maint_wait, maint_last_msg] ) # other functions set_index.click(show_image_info, _js="image_browser_get_current_img", inputs=[tab_base_tag_box, image_index, page_index, filenames, turn_page_switch], outputs=[img_file_name, img_file_time, image_index, hidden, turn_page_switch, img_file_info_add]) set_index.click(fn=lambda:(gr.update(visible=delete_panel not in override_hidden), gr.update(visible=button_panel not in override_hidden), gr.update(visible=ranking_panel not in override_hidden), gr.update(visible=to_dir_panel not in override_hidden), gr.update(visible=info_add_panel not in override_hidden)), inputs=None, outputs=hide_on_thumbnail_view) img_file_name.change(fn=lambda : "", inputs=None, outputs=[collected_warning]) img_file_name.change(get_ranking, inputs=img_file_name, outputs=ranking) hidden.change(fn=run_pnginfo, inputs=[hidden, img_path, img_file_name], outputs=[info1, img_file_info, info2, image_browser_prompt, image_browser_neg_prompt]) #ranking ranking.change(update_ranking, inputs=[img_file_name, ranking, img_file_info], outputs=[img_file_info]) try: modules.generation_parameters_copypaste.bind_buttons(send_to_buttons, hidden, img_file_info) except: pass if standard_ui: current_gr_tab.select( fn=tab_select, inputs=[], outputs=[path_recorder, to_dir_saved] ) open_folder_button.click( fn=lambda: open_folder(dir_name), inputs=[], outputs=[] ) elif others_dir: open_folder_button.click( fn=open_folder, inputs=[img_path], outputs=[] ) if standard_ui or others_dir: sendto_openoutpaint.click( fn=None, inputs=[tab_base_tag_box, image_index, image_browser_prompt, image_browser_neg_prompt], outputs=[], _js="image_browser_openoutpaint_send" ) sendto_controlnet_txt2img.click( fn=None, inputs=[tab_base_tag_box, image_index, sendto_controlnet_num], outputs=[], _js="image_browser_controlnet_send_txt2img" ) sendto_controlnet_img2img.click( fn=None, inputs=[tab_base_tag_box, image_index, sendto_controlnet_num], outputs=[], _js="image_browser_controlnet_send_img2img" ) def run_pnginfo(image, image_path, image_file_name): if image is None: return '', '', '', '', '' geninfo, items = images.read_info_from_image(image) items = {**{'parameters': geninfo}, **items} info = '' for key, text in items.items(): info += f"""
{plaintext_to_html(str(key))}
{plaintext_to_html(str(text))}