From c47cb10384e7b52fafcf8aed07ddeca5294ccd2b Mon Sep 17 00:00:00 2001 From: bmaltais Date: Thu, 23 Mar 2023 14:21:02 -0400 Subject: [PATCH 1/3] Fix _ issue --- README.md | 2 ++ library/wd14_caption_gui.py | 17 ++++++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 1af6bf8..842e4e8 100644 --- a/README.md +++ b/README.md @@ -192,6 +192,8 @@ This will store your a backup file with your current locally installed pip packa ## Change History +* 2023/03/23 (v21.3.2) + - Fix issue reported: https://github.com/bmaltais/kohya_ss/issues/439 * 2023/03/23 (v21.3.1) - Merge PR to fix refactor naming issue for basic captions. Thank @zrma * 2023/03/22 (v21.3.0) diff --git a/library/wd14_caption_gui.py b/library/wd14_caption_gui.py index d8d8205..1970849 100644 --- a/library/wd14_caption_gui.py +++ b/library/wd14_caption_gui.py @@ -5,6 +5,16 @@ from .common_gui import get_folder_path import os +def replace_underscore_with_space(folder_path, file_extension): + for file_name in os.listdir(folder_path): + if file_name.endswith(file_extension): + file_path = os.path.join(folder_path, file_name) + with open(file_path, 'r') as file: + file_content = file.read() + new_file_content = file_content.replace('_', ' ') + with open(file_path, 'w') as file: + file.write(new_file_content) + def caption_images( train_data_dir, caption_extension, batch_size, thresh, replace_underscores ): @@ -26,9 +36,7 @@ def caption_images( run_cmd = f'accelerate launch "./finetune/tag_images_by_wd14_tagger.py"' run_cmd += f' --batch_size="{int(batch_size)}"' run_cmd += f' --thresh="{thresh}"' - run_cmd += f' --replace_underscores' if replace_underscores else '' - if caption_extension != '': - run_cmd += f' --caption_extension="{caption_extension}"' + run_cmd += f' --caption_extension="{caption_extension}"' run_cmd += f' "{train_data_dir}"' print(run_cmd) @@ -38,6 +46,9 @@ def caption_images( os.system(run_cmd) else: subprocess.run(run_cmd) + + if replace_underscores: + replace_underscore_with_space(train_data_dir, caption_extension) print('...captioning done') From acf7d4785f79d858fb1660ae28456d2865f97af6 Mon Sep 17 00:00:00 2001 From: bmaltais Date: Fri, 24 Mar 2023 13:26:29 -0400 Subject: [PATCH 2/3] Add support for custom user gui startup files --- .gitignore | 4 +++- gui.ps1 | 13 ++++++++++--- setup.py | 11 +++++++++-- tools/create_user_files.py | 37 +++++++++++++++++++++++++++++++++++++ 4 files changed, 59 insertions(+), 6 deletions(-) create mode 100644 tools/create_user_files.py diff --git a/.gitignore b/.gitignore index 454625e..b7e99e2 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,6 @@ cudnn_windows build wd14_tagger_model .DS_Store -locon \ No newline at end of file +locon +gui-user.bat +gui-user.ps1 diff --git a/gui.ps1 b/gui.ps1 index 81b43a0..349ce97 100644 --- a/gui.ps1 +++ b/gui.ps1 @@ -4,7 +4,14 @@ # Validate the requirements and store the exit code python.exe .\tools\validate_requirements.py -# If the exit code is 0, run the kohya_gui.py script with the command-line arguments +# If the exit code is 0, read arguments from gui_parameters.txt (if it exists) +# and run the kohya_gui.py script with the command-line arguments if ($LASTEXITCODE -eq 0) { - python.exe kohya_gui.py $args -} \ No newline at end of file + $argsFromFile = @() + if (Test-Path .\gui_parameters.txt) { + $argsFromFile = Get-Content .\gui_parameters.txt -Encoding UTF8 | Where-Object { $_ -notmatch "^#" } | Foreach-Object { $_ -split " " } + } + $args_combo = $argsFromFile + $args + Write-Host "The arguments passed to this script were: $args_combo" + python.exe kohya_gui.py $args_combo +} diff --git a/setup.py b/setup.py index 55fe23b..8aa7c07 100644 --- a/setup.py +++ b/setup.py @@ -1,3 +1,10 @@ from setuptools import setup, find_packages - -setup(name = "library", version="1.0.2", packages = find_packages()) \ No newline at end of file +import subprocess +import os +import sys + +# Call the create_user_files.py script +script_path = os.path.join("tools", "create_user_files.py") +subprocess.run([sys.executable, script_path]) + +setup(name="library", version="1.0.3", packages=find_packages()) diff --git a/tools/create_user_files.py b/tools/create_user_files.py new file mode 100644 index 0000000..9c3d003 --- /dev/null +++ b/tools/create_user_files.py @@ -0,0 +1,37 @@ +import os + +bat_content = r'''@echo off +REM Example of how to start the GUI with custom arguments. In this case how to auto launch the browser: +REM call gui.bat --inbrowser +REM +REM You can add many arguments on the same line +REM +call gui.bat --inbrowser +''' + +ps1_content = r'''# Example of how to start the GUI with custom arguments. In this case how to auto launch the browser: +# .\gui.ps1 --inbrowser +# +# You can add many arguments on the same line +# +# & .\gui.ps1 --inbrowser --server_port 2345 + +& .\gui.ps1 --inbrowser +''' + +bat_filename = 'gui-user.bat' +ps1_filename = 'gui-user.ps1' + +if not os.path.exists(bat_filename): + with open(bat_filename, 'w') as bat_file: + bat_file.write(bat_content) + print(f"File created: {bat_filename}") +else: + print(f"File already exists: {bat_filename}") + +if not os.path.exists(ps1_filename): + with open(ps1_filename, 'w') as ps1_file: + ps1_file.write(ps1_content) + print(f"File created: {ps1_filename}") +else: + print(f"File already exists: {ps1_filename}") From 5bee4bda3fa65012d103cc62c1f7fc103743ce03 Mon Sep 17 00:00:00 2001 From: bmaltais Date: Fri, 24 Mar 2023 13:35:55 -0400 Subject: [PATCH 3/3] Update README --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 842e4e8..d29666d 100644 --- a/README.md +++ b/README.md @@ -192,6 +192,8 @@ This will store your a backup file with your current locally installed pip packa ## Change History +* 2023/03/24 (v21.3.3) + - Add support for custom user gui files. THey will be created at installation time or when upgrading is missing. You will see two files in the root of the folder. One named `gui-user.bat` and the other `gui-user.ps1`. Edit the file based on your prefered terminal. Simply add the parameters you want to pass the gui in there and execute it to start the gui with them. Enjoy! * 2023/03/23 (v21.3.2) - Fix issue reported: https://github.com/bmaltais/kohya_ss/issues/439 * 2023/03/23 (v21.3.1)