rebuild button, fix multiline prompt exif, #42
parent
3f6fb330f2
commit
3f61b9f299
|
|
@ -45,6 +45,7 @@ none_select = "Nothing selected"
|
||||||
refresh_symbol = '\U0001f504' # 🔄
|
refresh_symbol = '\U0001f504' # 🔄
|
||||||
up_symbol = '\U000025b2' # ▲
|
up_symbol = '\U000025b2' # ▲
|
||||||
down_symbol = '\U000025bc' # ▼
|
down_symbol = '\U000025bc' # ▼
|
||||||
|
rebuild_symbol = '\U0001f50e\U0001f4c2' # 🔎📂
|
||||||
current_depth = 0
|
current_depth = 0
|
||||||
init = True
|
init = True
|
||||||
copy_move = ["Move", "Copy"]
|
copy_move = ["Move", "Copy"]
|
||||||
|
|
@ -367,6 +368,24 @@ def cache_exif(fileinfos):
|
||||||
cache_exif_end = time.time()
|
cache_exif_end = time.time()
|
||||||
logger.debug(f"cache_exif: {new_exif}/{len(fileinfos)} cache_aes: {new_aes}/{len(fileinfos)} {round(cache_exif_end - cache_exif_start, 1)} seconds")
|
logger.debug(f"cache_exif: {new_exif}/{len(fileinfos)} cache_aes: {new_aes}/{len(fileinfos)} {round(cache_exif_end - cache_exif_start, 1)} seconds")
|
||||||
|
|
||||||
|
def exif_rebuild(exif_rebuild_button):
|
||||||
|
global finfo_exif, exif_cache, finfo_aes, aes_cache
|
||||||
|
if opts.image_browser_scan_exif:
|
||||||
|
print("Rebuild start")
|
||||||
|
exif_dirs = wib_db.get_exif_dirs()
|
||||||
|
finfo_aes = {}
|
||||||
|
exif_cache = {}
|
||||||
|
finfo_exif = {}
|
||||||
|
aes_cache = {}
|
||||||
|
for key, value in exif_dirs.items():
|
||||||
|
if os.path.exists(key):
|
||||||
|
print(f"Rebuilding {key}")
|
||||||
|
fileinfos = traverse_all_files(key, [], "", 0)
|
||||||
|
cache_exif(fileinfos)
|
||||||
|
print("Rebuild end")
|
||||||
|
|
||||||
|
return exif_rebuild_button
|
||||||
|
|
||||||
def atof(text):
|
def atof(text):
|
||||||
try:
|
try:
|
||||||
retval = float(text)
|
retval = float(text)
|
||||||
|
|
@ -623,6 +642,12 @@ def create_tab(tabname, current_gr_tab):
|
||||||
img_path_subdirs = gr.Dropdown(choices=[none_select], value=none_select, label="Sub directories", interactive=True, elem_id=f"{tabname}_img_path_subdirs")
|
img_path_subdirs = gr.Dropdown(choices=[none_select], value=none_select, label="Sub directories", interactive=True, elem_id=f"{tabname}_img_path_subdirs")
|
||||||
with gr.Column(scale=1):
|
with gr.Column(scale=1):
|
||||||
img_path_subdirs_button = gr.Button(value="Get sub directories")
|
img_path_subdirs_button = gr.Button(value="Get sub directories")
|
||||||
|
|
||||||
|
with gr.Row(visible=custom_dir):
|
||||||
|
with gr.Column(scale=10):
|
||||||
|
gr.Dropdown(visible=False)
|
||||||
|
with gr.Column(scale=1):
|
||||||
|
exif_rebuild_button = gr.Button(value=f"{rebuild_symbol} Rebuild exif cache")
|
||||||
|
|
||||||
with gr.Row(visible=not custom_dir, elem_id=f"{tabname}_image_browser") as main_panel:
|
with gr.Row(visible=not custom_dir, elem_id=f"{tabname}_image_browser") as main_panel:
|
||||||
with gr.Column():
|
with gr.Column():
|
||||||
|
|
@ -777,6 +802,11 @@ def create_tab(tabname, current_gr_tab):
|
||||||
inputs=[img_path, path_recorder, img_path_remove, img_path_depth],
|
inputs=[img_path, path_recorder, img_path_remove, img_path_depth],
|
||||||
outputs=[path_recorder, img_path_browser]
|
outputs=[path_recorder, img_path_browser]
|
||||||
)
|
)
|
||||||
|
exif_rebuild_button.click(
|
||||||
|
fn=exif_rebuild,
|
||||||
|
inputs=[exif_rebuild_button],
|
||||||
|
outputs=[exif_rebuild_button]
|
||||||
|
)
|
||||||
|
|
||||||
# other functions
|
# other functions
|
||||||
set_index.click(show_image_info, _js="image_browser_get_current_img", inputs=[tabname_box, image_index, page_index, filenames, turn_page_switch], outputs=[img_file_name, img_file_time, image_index, hidden, turn_page_switch])
|
set_index.click(show_image_info, _js="image_browser_get_current_img", inputs=[tabname_box, image_index, page_index, filenames, turn_page_switch], outputs=[img_file_name, img_file_time, image_index, hidden, turn_page_switch])
|
||||||
|
|
|
||||||
|
|
@ -122,7 +122,11 @@ def update_exif_data(cursor, file, info):
|
||||||
elif info_item.startswith(np):
|
elif info_item.startswith(np):
|
||||||
negative_prompt = info_item.replace(np, "")
|
negative_prompt = info_item.replace(np, "")
|
||||||
else:
|
else:
|
||||||
prompt = info_item
|
if prompt == "":
|
||||||
|
prompt = info_item
|
||||||
|
else:
|
||||||
|
# multiline prompts
|
||||||
|
prompt = f"{prompt}\n{info_item}"
|
||||||
if key_values != "":
|
if key_values != "":
|
||||||
key_value_pairs = []
|
key_value_pairs = []
|
||||||
key_value = ""
|
key_value = ""
|
||||||
|
|
@ -339,3 +343,20 @@ def load_aes_data(aes_cache):
|
||||||
aes_cache[row[0]] = row[1]
|
aes_cache[row[0]] = row[1]
|
||||||
|
|
||||||
return aes_cache
|
return aes_cache
|
||||||
|
|
||||||
|
def get_exif_dirs():
|
||||||
|
with sqlite3.connect(db_file, timeout=timeout) as conn:
|
||||||
|
cursor = conn.cursor()
|
||||||
|
cursor.execute('''
|
||||||
|
SELECT file
|
||||||
|
FROM exif_data
|
||||||
|
''')
|
||||||
|
|
||||||
|
rows = cursor.fetchall()
|
||||||
|
|
||||||
|
dirs = {}
|
||||||
|
for row in rows:
|
||||||
|
dir = os.path.dirname(row[0])
|
||||||
|
dirs[dir] = dir
|
||||||
|
|
||||||
|
return dirs
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue