1
1
import gradio as gr
2
2
import os
3
- from .common_gui import get_folder_path , scriptdir , list_dirs , create_refresh_button
3
+ from .common_gui import get_folder_path , scriptdir , list_dirs , create_refresh_button , load_kohya_ss_gui_config
4
4
5
5
class Folders :
6
6
"""
7
7
A class to handle folder operations in the GUI.
8
8
"""
9
- def __init__ (self , finetune : bool = False , data_dir : str = None , output_dir : str = None , logging_dir : str = None , reg_data_dir : str = None , headless : bool = False ):
9
+ def __init__ (self , finetune : bool = False , headless : bool = False ):
10
10
"""
11
11
Initialize the Folders class.
12
12
13
13
Parameters:
14
14
- finetune (bool): Whether to finetune the model.
15
- - data_dir (str): The directory for data.
16
- - output_dir (str): The directory for output.
17
- - logging_dir (str): The directory for logging.
18
- - reg_data_dir (str): The directory for regularization data.
19
15
- headless (bool): Whether to run in headless mode.
20
16
"""
21
17
self .headless = headless
22
18
self .finetune = finetune
19
+
20
+ # Load kohya_ss GUI configs from config.toml if it exist
21
+ config = load_kohya_ss_gui_config ()
23
22
24
23
# Set default directories if not provided
25
- self .current_data_dir = data_dir if data_dir is not None else os .path .join (scriptdir , "data" )
26
- self .current_output_dir = output_dir if output_dir is not None else os .path .join (scriptdir , "outputs" )
27
- self .current_logging_dir = logging_dir if logging_dir is not None else os .path .join (scriptdir , "logs" )
28
- self .current_reg_data_dir = reg_data_dir if reg_data_dir is not None else os .path .join (scriptdir , "reg" )
24
+ self .current_output_dir = config .get ('output_dir' , os .path .join (scriptdir , "outputs" ))
25
+ self .current_logging_dir = config .get ('logging_dir' , os .path .join (scriptdir , "logs" ))
26
+ self .current_reg_data_dir = config .get ('reg_data_dir' , os .path .join (scriptdir , "reg" ))
29
27
30
28
# Create directories if they don't exist
31
29
self .create_directory_if_not_exists (self .current_output_dir )
@@ -44,18 +42,6 @@ def create_directory_if_not_exists(self, directory: str) -> None:
44
42
if directory is not None and directory .strip () != "" and not os .path .exists (directory ):
45
43
os .makedirs (directory , exist_ok = True )
46
44
47
- def list_data_dirs (self , path : str ) -> list :
48
- """
49
- List directories in the data directory.
50
-
51
- Parameters:
52
- - path (str): The path to list directories from.
53
-
54
- Returns:
55
- - list: A list of directories.
56
- """
57
- self .current_data_dir = path
58
- return list (list_dirs (path ))
59
45
60
46
def list_output_dirs (self , path : str ) -> list :
61
47
"""
@@ -67,7 +53,7 @@ def list_output_dirs(self, path: str) -> list:
67
53
Returns:
68
54
- list: A list of directories.
69
55
"""
70
- self .current_output_dir = path
56
+ self .current_output_dir = path if not path == "" else "."
71
57
return list (list_dirs (path ))
72
58
73
59
def list_logging_dirs (self , path : str ) -> list :
@@ -80,7 +66,7 @@ def list_logging_dirs(self, path: str) -> list:
80
66
Returns:
81
67
- list: A list of directories.
82
68
"""
83
- self .current_logging_dir = path
69
+ self .current_logging_dir = path if not path == "" else "."
84
70
return list (list_dirs (path ))
85
71
86
72
def list_reg_data_dirs (self , path : str ) -> list :
@@ -93,7 +79,7 @@ def list_reg_data_dirs(self, path: str) -> list:
93
79
Returns:
94
80
- list: A list of directories.
95
81
"""
96
- self .current_reg_data_dir = path
82
+ self .current_reg_data_dir = path if not path == "" else "."
97
83
return list (list_dirs (path ))
98
84
99
85
def create_folders_gui (self ) -> None :
@@ -131,7 +117,7 @@ def create_folders_gui(self) -> None:
131
117
allow_custom_value = True ,
132
118
)
133
119
# Refresh button for regularisation directory
134
- create_refresh_button (self .reg_data_dir , lambda : None , lambda : {"choices" : ["" ] + self .list_data_dirs (self .current_data_dir )}, "open_folder_small" )
120
+ create_refresh_button (self .reg_data_dir , lambda : None , lambda : {"choices" : ["" ] + self .list_reg_data_dirs (self .current_reg_data_dir )}, "open_folder_small" )
135
121
# Regularisation directory button
136
122
self .reg_data_dir_folder = gr .Button (
137
123
'📂' , elem_id = 'open_folder_small' , elem_classes = ["tool" ], visible = (not self .headless )
@@ -173,7 +159,7 @@ def create_folders_gui(self) -> None:
173
159
)
174
160
# Change event for regularisation directory dropdown
175
161
self .reg_data_dir .change (
176
- fn = lambda path : gr .Dropdown (choices = ["" ] + self .list_data_dirs (path )),
162
+ fn = lambda path : gr .Dropdown (choices = ["" ] + self .list_reg_data_dirs (path )),
177
163
inputs = self .reg_data_dir ,
178
164
outputs = self .reg_data_dir ,
179
165
show_progress = False ,
0 commit comments