Prevent the file selection GUI from running
This commit is contained in:
parent
0e25977a09
commit
c38c018197
@ -213,6 +213,9 @@ This will store your a backup file with your current locally installed pip packa
|
|||||||
|
|
||||||
## Change History
|
## Change History
|
||||||
|
|
||||||
|
* 2023/03/26 (v21.3.5)
|
||||||
|
- Fix for https://github.com/bmaltais/kohya_ss/issues/230
|
||||||
|
- Added detection for Google Colab to not bring up the GUI file/folder window on the platform. Instead it will only use the file/folder path provided in the input field.
|
||||||
* 2023/03/25 (v21.3.4)
|
* 2023/03/25 (v21.3.4)
|
||||||
- Added untested support for MacOS base on this gist: https://gist.github.com/jstayco/9f5733f05b9dc29de95c4056a023d645
|
- Added untested support for MacOS base on this gist: https://gist.github.com/jstayco/9f5733f05b9dc29de95c4056a023d645
|
||||||
|
|
||||||
|
@ -118,54 +118,58 @@ def get_dir_and_file(file_path):
|
|||||||
def get_file_path(
|
def get_file_path(
|
||||||
file_path='', default_extension='.json', extension_name='Config files'
|
file_path='', default_extension='.json', extension_name='Config files'
|
||||||
):
|
):
|
||||||
current_file_path = file_path
|
if not any(var in os.environ for var in ['COLAB_GPU', 'RUNPOD_ENVIRONMENT']):
|
||||||
# print(f'current file path: {current_file_path}')
|
current_file_path = file_path
|
||||||
|
# print(f'current file path: {current_file_path}')
|
||||||
|
|
||||||
initial_dir, initial_file = get_dir_and_file(file_path)
|
initial_dir, initial_file = get_dir_and_file(file_path)
|
||||||
|
|
||||||
# Create a hidden Tkinter root window
|
# Create a hidden Tkinter root window
|
||||||
root = Tk()
|
root = Tk()
|
||||||
root.wm_attributes('-topmost', 1)
|
root.wm_attributes('-topmost', 1)
|
||||||
root.withdraw()
|
root.withdraw()
|
||||||
|
|
||||||
# Show the open file dialog and get the selected file path
|
# Show the open file dialog and get the selected file path
|
||||||
file_path = filedialog.askopenfilename(
|
file_path = filedialog.askopenfilename(
|
||||||
filetypes=(
|
filetypes=(
|
||||||
(extension_name, f'*{default_extension}'),
|
(extension_name, f'*{default_extension}'),
|
||||||
('All files', '*.*'),
|
('All files', '*.*'),
|
||||||
),
|
),
|
||||||
defaultextension=default_extension,
|
defaultextension=default_extension,
|
||||||
initialfile=initial_file,
|
initialfile=initial_file,
|
||||||
initialdir=initial_dir,
|
initialdir=initial_dir,
|
||||||
)
|
)
|
||||||
|
|
||||||
# Destroy the hidden root window
|
# Destroy the hidden root window
|
||||||
root.destroy()
|
root.destroy()
|
||||||
|
|
||||||
# If no file is selected, use the current file path
|
# If no file is selected, use the current file path
|
||||||
if not file_path:
|
if not file_path:
|
||||||
file_path = current_file_path
|
file_path = current_file_path
|
||||||
|
current_file_path = file_path
|
||||||
|
# print(f'current file path: {current_file_path}')
|
||||||
|
|
||||||
return file_path
|
return file_path
|
||||||
|
|
||||||
|
|
||||||
def get_any_file_path(file_path=''):
|
def get_any_file_path(file_path=''):
|
||||||
current_file_path = file_path
|
if not any(var in os.environ for var in ['COLAB_GPU', 'RUNPOD_ENVIRONMENT']):
|
||||||
# print(f'current file path: {current_file_path}')
|
current_file_path = file_path
|
||||||
|
# print(f'current file path: {current_file_path}')
|
||||||
|
|
||||||
initial_dir, initial_file = get_dir_and_file(file_path)
|
initial_dir, initial_file = get_dir_and_file(file_path)
|
||||||
|
|
||||||
root = Tk()
|
root = Tk()
|
||||||
root.wm_attributes('-topmost', 1)
|
root.wm_attributes('-topmost', 1)
|
||||||
root.withdraw()
|
root.withdraw()
|
||||||
file_path = filedialog.askopenfilename(
|
file_path = filedialog.askopenfilename(
|
||||||
initialdir=initial_dir,
|
initialdir=initial_dir,
|
||||||
initialfile=initial_file,
|
initialfile=initial_file,
|
||||||
)
|
)
|
||||||
root.destroy()
|
root.destroy()
|
||||||
|
|
||||||
if file_path == '':
|
if file_path == '':
|
||||||
file_path = current_file_path
|
file_path = current_file_path
|
||||||
|
|
||||||
return file_path
|
return file_path
|
||||||
|
|
||||||
@ -191,18 +195,19 @@ def remove_doublequote(file_path):
|
|||||||
|
|
||||||
|
|
||||||
def get_folder_path(folder_path=''):
|
def get_folder_path(folder_path=''):
|
||||||
current_folder_path = folder_path
|
if not any(var in os.environ for var in ['COLAB_GPU', 'RUNPOD_ENVIRONMENT']):
|
||||||
|
current_folder_path = folder_path
|
||||||
|
|
||||||
initial_dir, initial_file = get_dir_and_file(folder_path)
|
initial_dir, initial_file = get_dir_and_file(folder_path)
|
||||||
|
|
||||||
root = Tk()
|
root = Tk()
|
||||||
root.wm_attributes('-topmost', 1)
|
root.wm_attributes('-topmost', 1)
|
||||||
root.withdraw()
|
root.withdraw()
|
||||||
folder_path = filedialog.askdirectory(initialdir=initial_dir)
|
folder_path = filedialog.askdirectory(initialdir=initial_dir)
|
||||||
root.destroy()
|
root.destroy()
|
||||||
|
|
||||||
if folder_path == '':
|
if folder_path == '':
|
||||||
folder_path = current_folder_path
|
folder_path = current_folder_path
|
||||||
|
|
||||||
return folder_path
|
return folder_path
|
||||||
|
|
||||||
@ -210,34 +215,35 @@ def get_folder_path(folder_path=''):
|
|||||||
def get_saveasfile_path(
|
def get_saveasfile_path(
|
||||||
file_path='', defaultextension='.json', extension_name='Config files'
|
file_path='', defaultextension='.json', extension_name='Config files'
|
||||||
):
|
):
|
||||||
current_file_path = file_path
|
if not any(var in os.environ for var in ['COLAB_GPU', 'RUNPOD_ENVIRONMENT']):
|
||||||
# print(f'current file path: {current_file_path}')
|
current_file_path = file_path
|
||||||
|
# print(f'current file path: {current_file_path}')
|
||||||
|
|
||||||
initial_dir, initial_file = get_dir_and_file(file_path)
|
initial_dir, initial_file = get_dir_and_file(file_path)
|
||||||
|
|
||||||
root = Tk()
|
root = Tk()
|
||||||
root.wm_attributes('-topmost', 1)
|
root.wm_attributes('-topmost', 1)
|
||||||
root.withdraw()
|
root.withdraw()
|
||||||
save_file_path = filedialog.asksaveasfile(
|
save_file_path = filedialog.asksaveasfile(
|
||||||
filetypes=(
|
filetypes=(
|
||||||
(f'{extension_name}', f'{defaultextension}'),
|
(f'{extension_name}', f'{defaultextension}'),
|
||||||
('All files', '*'),
|
('All files', '*'),
|
||||||
),
|
),
|
||||||
defaultextension=defaultextension,
|
defaultextension=defaultextension,
|
||||||
initialdir=initial_dir,
|
initialdir=initial_dir,
|
||||||
initialfile=initial_file,
|
initialfile=initial_file,
|
||||||
)
|
)
|
||||||
root.destroy()
|
root.destroy()
|
||||||
|
|
||||||
# print(save_file_path)
|
# print(save_file_path)
|
||||||
|
|
||||||
if save_file_path == None:
|
if save_file_path == None:
|
||||||
file_path = current_file_path
|
file_path = current_file_path
|
||||||
else:
|
else:
|
||||||
print(save_file_path.name)
|
print(save_file_path.name)
|
||||||
file_path = save_file_path.name
|
file_path = save_file_path.name
|
||||||
|
|
||||||
# print(file_path)
|
# print(file_path)
|
||||||
|
|
||||||
return file_path
|
return file_path
|
||||||
|
|
||||||
@ -245,27 +251,28 @@ def get_saveasfile_path(
|
|||||||
def get_saveasfilename_path(
|
def get_saveasfilename_path(
|
||||||
file_path='', extensions='*', extension_name='Config files'
|
file_path='', extensions='*', extension_name='Config files'
|
||||||
):
|
):
|
||||||
current_file_path = file_path
|
if not any(var in os.environ for var in ['COLAB_GPU', 'RUNPOD_ENVIRONMENT']):
|
||||||
# print(f'current file path: {current_file_path}')
|
current_file_path = file_path
|
||||||
|
# print(f'current file path: {current_file_path}')
|
||||||
|
|
||||||
initial_dir, initial_file = get_dir_and_file(file_path)
|
initial_dir, initial_file = get_dir_and_file(file_path)
|
||||||
|
|
||||||
root = Tk()
|
root = Tk()
|
||||||
root.wm_attributes('-topmost', 1)
|
root.wm_attributes('-topmost', 1)
|
||||||
root.withdraw()
|
root.withdraw()
|
||||||
save_file_path = filedialog.asksaveasfilename(
|
save_file_path = filedialog.asksaveasfilename(
|
||||||
filetypes=((f'{extension_name}', f'{extensions}'), ('All files', '*')),
|
filetypes=((f'{extension_name}', f'{extensions}'), ('All files', '*')),
|
||||||
defaultextension=extensions,
|
defaultextension=extensions,
|
||||||
initialdir=initial_dir,
|
initialdir=initial_dir,
|
||||||
initialfile=initial_file,
|
initialfile=initial_file,
|
||||||
)
|
)
|
||||||
root.destroy()
|
root.destroy()
|
||||||
|
|
||||||
if save_file_path == '':
|
if save_file_path == '':
|
||||||
file_path = current_file_path
|
file_path = current_file_path
|
||||||
else:
|
else:
|
||||||
# print(save_file_path)
|
# print(save_file_path)
|
||||||
file_path = save_file_path
|
file_path = save_file_path
|
||||||
|
|
||||||
return file_path
|
return file_path
|
||||||
|
|
||||||
@ -316,33 +323,6 @@ def add_pre_postfix(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
# def add_pre_postfix(
|
|
||||||
# folder='', prefix='', postfix='', caption_file_ext='.caption'
|
|
||||||
# ):
|
|
||||||
# if not has_ext_files(folder, caption_file_ext):
|
|
||||||
# msgbox(
|
|
||||||
# f'No files with extension {caption_file_ext} were found in {folder}...'
|
|
||||||
# )
|
|
||||||
# return
|
|
||||||
|
|
||||||
# if prefix == '' and postfix == '':
|
|
||||||
# return
|
|
||||||
|
|
||||||
# files = [f for f in os.listdir(folder) if f.endswith(caption_file_ext)]
|
|
||||||
# if not prefix == '':
|
|
||||||
# prefix = f'{prefix} '
|
|
||||||
# if not postfix == '':
|
|
||||||
# postfix = f' {postfix}'
|
|
||||||
|
|
||||||
# for file in files:
|
|
||||||
# with open(os.path.join(folder, file), 'r+') as f:
|
|
||||||
# content = f.read()
|
|
||||||
# content = content.rstrip()
|
|
||||||
# f.seek(0, 0)
|
|
||||||
# f.write(f'{prefix} {content} {postfix}')
|
|
||||||
# f.close()
|
|
||||||
|
|
||||||
|
|
||||||
def has_ext_files(folder_path: str, file_extension: str) -> bool:
|
def has_ext_files(folder_path: str, file_extension: str) -> bool:
|
||||||
"""
|
"""
|
||||||
Check if there are any files with the specified extension in the given folder.
|
Check if there are any files with the specified extension in the given folder.
|
||||||
@ -402,28 +382,6 @@ def find_replace(
|
|||||||
f.write(content)
|
f.write(content)
|
||||||
|
|
||||||
|
|
||||||
# def find_replace(folder='', caption_file_ext='.caption', find='', replace=''):
|
|
||||||
# print('Running caption find/replace')
|
|
||||||
# if not has_ext_files(folder, caption_file_ext):
|
|
||||||
# msgbox(
|
|
||||||
# f'No files with extension {caption_file_ext} were found in {folder}...'
|
|
||||||
# )
|
|
||||||
# return
|
|
||||||
|
|
||||||
# if find == '':
|
|
||||||
# return
|
|
||||||
|
|
||||||
# files = [f for f in os.listdir(folder) if f.endswith(caption_file_ext)]
|
|
||||||
# for file in files:
|
|
||||||
# with open(os.path.join(folder, file), 'r', errors='ignore') as f:
|
|
||||||
# content = f.read()
|
|
||||||
# f.close
|
|
||||||
# content = content.replace(find, replace)
|
|
||||||
# with open(os.path.join(folder, file), 'w') as f:
|
|
||||||
# f.write(content)
|
|
||||||
# f.close()
|
|
||||||
|
|
||||||
|
|
||||||
def color_aug_changed(color_aug):
|
def color_aug_changed(color_aug):
|
||||||
if color_aug:
|
if color_aug:
|
||||||
msgbox(
|
msgbox(
|
||||||
|
@ -30,7 +30,7 @@ if command -v python3.10 >/dev/null; then
|
|||||||
pip install torch==2.0.0 torchvision==0.15.1 -f https://download.pytorch.org/whl/cpu/torch_stable.html
|
pip install torch==2.0.0 torchvision==0.15.1 -f https://download.pytorch.org/whl/cpu/torch_stable.html
|
||||||
python -m pip install --use-pep517 --upgrade -r requirements_macos.txt
|
python -m pip install --use-pep517 --upgrade -r requirements_macos.txt
|
||||||
accelerate config
|
accelerate config
|
||||||
echo -e "Setup finished! Run ./gui.sh to start."
|
echo -e "Setup finished! Run ./gui_macos.sh to start."
|
||||||
else
|
else
|
||||||
echo "Python not found. Please ensure you install Python."
|
echo "Python not found. Please ensure you install Python."
|
||||||
echo "The brew command for Python 3.10 is: brew install python@3.10"
|
echo "The brew command for Python 3.10 is: brew install python@3.10"
|
||||||
|
Loading…
Reference in New Issue
Block a user