Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix creation of output folders #2473

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions kohya_gui/common_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -1368,17 +1368,21 @@ def validate_file_path(file_path: str) -> bool:
return True


def validate_folder_path(folder_path: str, can_be_written_to: bool = False) -> bool:
def validate_folder_path(folder_path: str, can_be_written_to: bool = False, create_if_not_exists: bool = False) -> bool:
if folder_path == "":
return True
msg = f"Validating {folder_path} existence{' and writability' if can_be_written_to else ''}..."
if not os.path.isdir(folder_path):
log.error(f"{msg} FAILED: does not exist")
return False
if can_be_written_to:
if not os.access(folder_path, os.W_OK):
log.error(f"{msg} FAILED: is not writable.")
if create_if_not_exists:
os.makedirs(folder_path)
log.info(f"{msg} SUCCESS")
return True
else:
log.error(f"{msg} FAILED: does not exist")
return False
if can_be_written_to and not os.access(folder_path, os.W_OK):
log.error(f"{msg} FAILED: is not writable.")
return False
log.info(f"{msg} SUCCESS")
return True

Expand Down
4 changes: 2 additions & 2 deletions kohya_gui/dreambooth_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,10 +524,10 @@ def train_model(
if not validate_file_path(log_tracker_config):
return TRAIN_BUTTON_VISIBLE

if not validate_folder_path(logging_dir, can_be_written_to=True):
if not validate_folder_path(logging_dir, can_be_written_to=True, create_if_not_exists=True):
return TRAIN_BUTTON_VISIBLE

if not validate_folder_path(output_dir, can_be_written_to=True):
if not validate_folder_path(output_dir, can_be_written_to=True, create_if_not_exists=True):
return TRAIN_BUTTON_VISIBLE

if not validate_model_path(pretrained_model_name_or_path):
Expand Down
4 changes: 2 additions & 2 deletions kohya_gui/finetune_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,10 +569,10 @@ def train_model(
if not validate_file_path(log_tracker_config):
return TRAIN_BUTTON_VISIBLE

if not validate_folder_path(logging_dir, can_be_written_to=True):
if not validate_folder_path(logging_dir, can_be_written_to=True, create_if_not_exists=True):
return TRAIN_BUTTON_VISIBLE

if not validate_folder_path(output_dir, can_be_written_to=True):
if not validate_folder_path(output_dir, can_be_written_to=True, create_if_not_exists=True):
return TRAIN_BUTTON_VISIBLE

if not validate_model_path(pretrained_model_name_or_path):
Expand Down
4 changes: 2 additions & 2 deletions kohya_gui/lora_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,7 @@ def train_model(
if not validate_file_path(log_tracker_config):
return TRAIN_BUTTON_VISIBLE

if not validate_folder_path(logging_dir, can_be_written_to=True):
if not validate_folder_path(logging_dir, can_be_written_to=True, create_if_not_exists=True):
return TRAIN_BUTTON_VISIBLE

if LyCORIS_preset not in LYCORIS_PRESETS_CHOICES:
Expand All @@ -717,7 +717,7 @@ def train_model(
if not validate_file_path(network_weights):
return TRAIN_BUTTON_VISIBLE

if not validate_folder_path(output_dir, can_be_written_to=True):
if not validate_folder_path(output_dir, can_be_written_to=True, create_if_not_exists=True):
return TRAIN_BUTTON_VISIBLE

if not validate_model_path(pretrained_model_name_or_path):
Expand Down
4 changes: 2 additions & 2 deletions kohya_gui/textual_inversion_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,10 +524,10 @@ def train_model(
if not validate_file_path(log_tracker_config):
return TRAIN_BUTTON_VISIBLE

if not validate_folder_path(logging_dir, can_be_written_to=True):
if not validate_folder_path(logging_dir, can_be_written_to=True, create_if_not_exists=True):
return TRAIN_BUTTON_VISIBLE

if not validate_folder_path(output_dir, can_be_written_to=True):
if not validate_folder_path(output_dir, can_be_written_to=True, create_if_not_exists=True):
return TRAIN_BUTTON_VISIBLE

if not validate_model_path(pretrained_model_name_or_path):
Expand Down
Loading