Skip to content

Commit b903031

Browse files
feat: Suggest target folder in kontext manual caption GUI
1 parent d534cb9 commit b903031

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

kohya_gui/kontext_manual_caption_gui.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,21 @@ def paginate_go(page, max_page):
5757
return gr.update()
5858

5959

60+
def derive_target_folder(control_folder):
61+
if not control_folder or not os.path.exists(control_folder):
62+
return ""
63+
64+
parent_dir = os.path.dirname(control_folder)
65+
control_folder_name = os.path.basename(control_folder)
66+
67+
for item in os.listdir(parent_dir):
68+
if os.path.isdir(os.path.join(parent_dir, item)):
69+
if "control" in item.lower() and item.lower() != control_folder_name.lower():
70+
return os.path.join(parent_dir, item)
71+
72+
return control_folder_name
73+
74+
6075
def paginate(page, max_page, page_change):
6176
# REFACTOR: Ensure page is treated as an integer
6277
return int(max(min(int(page) + page_change, max_page), 1))
@@ -294,7 +309,12 @@ def render_pagination_with_logic(page, max_page):
294309
load_images_button = gr.Button("Load Images", variant="primary")
295310

296311
target_images_dir.change(update_dir_list, inputs=target_images_dir, outputs=target_images_dir, show_progress=False)
297-
control_images_dir.change(update_dir_list, inputs=control_images_dir, outputs=control_images_dir, show_progress=False)
312+
control_images_dir.change(
313+
lambda path: (update_dir_list(path), derive_target_folder(path)),
314+
inputs=control_images_dir,
315+
outputs=[control_images_dir, target_images_dir],
316+
show_progress=False
317+
)
298318

299319
with gr.Group():
300320
quick_tags_text = gr.Textbox(label="Quick Tags", placeholder="Comma separated list of tags", interactive=True)

0 commit comments

Comments
 (0)