@@ -57,6 +57,21 @@ def paginate_go(page, max_page):
57
57
return gr .update ()
58
58
59
59
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
+
60
75
def paginate (page , max_page , page_change ):
61
76
# REFACTOR: Ensure page is treated as an integer
62
77
return int (max (min (int (page ) + page_change , max_page ), 1 ))
@@ -294,7 +309,12 @@ def render_pagination_with_logic(page, max_page):
294
309
load_images_button = gr .Button ("Load Images" , variant = "primary" )
295
310
296
311
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
+ )
298
318
299
319
with gr .Group ():
300
320
quick_tags_text = gr .Textbox (label = "Quick Tags" , placeholder = "Comma separated list of tags" , interactive = True )
0 commit comments