Merge pull request #444 from bmaltais/dev

v21.3.3
This commit is contained in:
bmaltais 2023-03-24 13:36:27 -04:00 committed by GitHub
commit 13d82d3593
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 77 additions and 9 deletions

4
.gitignore vendored
View File

@ -7,4 +7,6 @@ cudnn_windows
build
wd14_tagger_model
.DS_Store
locon
locon
gui-user.bat
gui-user.ps1

View File

@ -192,6 +192,10 @@ 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)
- Merge PR to fix refactor naming issue for basic captions. Thank @zrma
* 2023/03/22 (v21.3.0)

13
gui.ps1
View File

@ -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
}
$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
}

View File

@ -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')

View File

@ -1,3 +1,10 @@
from setuptools import setup, find_packages
setup(name = "library", version="1.0.2", packages = find_packages())
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())

View File

@ -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}")