use subprocess.run(run_cmd, shell=True, env=env)

pull/2025/head
Won-Kyu Park 2024-03-02 13:57:48 +09:00
parent 644c911207
commit d6120017aa
No known key found for this signature in database
GPG Key ID: 53AA79C8C9535D15
15 changed files with 64 additions and 58 deletions

View File

@ -3,12 +3,14 @@ from easygui import msgbox
import subprocess
from .common_gui import get_folder_path, add_pre_postfix, find_replace, scriptdir
import os
import sys
from .custom_logging import setup_logging
# Set up logging
log = setup_logging()
PYTHON = sys.executable
def caption_images(
caption_text,
@ -36,7 +38,7 @@ def caption_images(
log.info(f'Captioning files in {images_dir} with {caption_text}...')
# Build the command to run caption.py
run_cmd = fr'python "{scriptdir}/tools/caption.py"'
run_cmd = fr'{PYTHON} "{scriptdir}/tools/caption.py"'
run_cmd += f' --caption_text="{caption_text}"'
# Add optional flags to the command
@ -49,11 +51,11 @@ def caption_images(
log.info(run_cmd)
env = os.environ.copy()
env['PYTHONPATH'] = fr"{scriptdir}{os.pathsep}{env.get('PYTHONPATH', '')}"
# Run the command based on the operating system
if os.name == 'posix':
os.system(run_cmd)
else:
subprocess.run(run_cmd)
subprocess.run(run_cmd, shell=True, env=env)
# Check if overwrite option is enabled
if overwrite:

View File

@ -52,11 +52,11 @@ def caption_images(
log.info(run_cmd)
env = os.environ.copy()
env['PYTHONPATH'] = fr"{scriptdir}{os.pathsep}{env.get('PYTHONPATH', '')}"
# Run the command
if os.name == 'posix':
os.system(run_cmd)
else:
subprocess.run(run_cmd)
subprocess.run(run_cmd, shell=True, env=env)
# Add prefix and postfix
add_pre_postfix(

View File

@ -39,11 +39,11 @@ def convert_lcm(
log.info(run_cmd)
env = os.environ.copy()
env['PYTHONPATH'] = fr"{scriptdir}{os.pathsep}{env.get('PYTHONPATH', '')}"
# Run the command
if os.name == "posix":
os.system(run_cmd)
else:
subprocess.run(run_cmd)
subprocess.run(run_cmd, shell=True, env=env)
# Return a success message
log.info("Done extracting...")

View File

@ -103,11 +103,11 @@ def convert_model(
log.info(run_cmd)
env = os.environ.copy()
env['PYTHONPATH'] = fr"{scriptdir}{os.pathsep}{env.get('PYTHONPATH', '')}"
# Run the command
if os.name == 'posix':
os.system(run_cmd)
else:
subprocess.run(run_cmd)
subprocess.run(run_cmd, shell=True, env=env)
if (
not target_model_type == 'diffuser'

View File

@ -46,11 +46,11 @@ def extract_dylora(
log.info(run_cmd)
env = os.environ.copy()
env['PYTHONPATH'] = fr"{scriptdir}{os.pathsep}{env.get('PYTHONPATH', '')}"
# Run the command
if os.name == 'posix':
os.system(run_cmd)
else:
subprocess.run(run_cmd)
subprocess.run(run_cmd, shell=True, env=env)
log.info('Done extracting DyLoRA...')

View File

@ -84,11 +84,11 @@ def extract_lora(
log.info(run_cmd)
env = os.environ.copy()
env['PYTHONPATH'] = fr"{scriptdir}{os.pathsep}{env.get('PYTHONPATH', '')}"
# Run the command
if os.name == 'posix':
os.system(run_cmd)
else:
subprocess.run(run_cmd)
subprocess.run(run_cmd, shell=True, env=env)
###

View File

@ -92,11 +92,11 @@ def extract_lycoris_locon(
log.info(run_cmd)
env = os.environ.copy()
env['PYTHONPATH'] = fr"{scriptdir}{os.pathsep}{env.get('PYTHONPATH', '')}"
# Run the command
if os.name == "posix":
os.system(run_cmd)
else:
subprocess.run(run_cmd)
subprocess.run(run_cmd, shell=True, env=env)
log.info('Done extracting...')

View File

@ -47,11 +47,11 @@ def caption_images(
log.info(run_cmd)
env = os.environ.copy()
env['PYTHONPATH'] = fr"{scriptdir}{os.pathsep}{env.get('PYTHONPATH', '')}"
# Run the command
if os.name == 'posix':
os.system(run_cmd)
else:
subprocess.run(run_cmd)
subprocess.run(run_cmd, shell=True, env=env)
# Add prefix and postfix
add_pre_postfix(

View File

@ -47,10 +47,11 @@ def group_images(
log.info(run_cmd)
if os.name == 'posix':
os.system(run_cmd)
else:
subprocess.run(run_cmd)
env = os.environ.copy()
env['PYTHONPATH'] = fr"{scriptdir}{os.pathsep}{env.get('PYTHONPATH', '')}"
# Run the command
subprocess.run(run_cmd, shell=True, env=env)
log.info('...grouping done')

View File

@ -312,10 +312,10 @@ class GradioMergeLoRaTab:
log.info(run_cmd)
env = os.environ.copy()
env['PYTHONPATH'] = fr"{scriptdir}{os.pathsep}{env.get('PYTHONPATH', '')}"
# Run the command
if os.name == 'posix':
os.system(run_cmd)
else:
subprocess.run(run_cmd)
subprocess.run(run_cmd, shell=True, env=env)
log.info('Done merging...')

View File

@ -48,11 +48,11 @@ def merge_lycoris(
log.info(run_cmd)
env = os.environ.copy()
env['PYTHONPATH'] = fr"{scriptdir}{os.pathsep}{env.get('PYTHONPATH', '')}"
# Run the command
if os.name == 'posix':
os.system(run_cmd)
else:
subprocess.run(run_cmd)
subprocess.run(run_cmd, shell=True, env=env)
log.info('Done merging...')

View File

@ -73,11 +73,11 @@ def resize_lora(
log.info(run_cmd)
env = os.environ.copy()
env['PYTHONPATH'] = fr"{scriptdir}{os.pathsep}{env.get('PYTHONPATH', '')}"
# Run the command
if os.name == 'posix':
os.system(run_cmd)
else:
subprocess.run(run_cmd)
subprocess.run(run_cmd, shell=True, env=env)
log.info('Done resizing...')

View File

@ -92,11 +92,11 @@ def svd_merge_lora(
log.info(run_cmd)
env = os.environ.copy()
env['PYTHONPATH'] = fr"{scriptdir}{os.pathsep}{env.get('PYTHONPATH', '')}"
# Run the command
if os.name == 'posix':
os.system(run_cmd)
else:
subprocess.run(run_cmd)
subprocess.run(run_cmd, shell=True, env=env)
###

View File

@ -44,9 +44,12 @@ def verify_lora(
log.info(' '.join(run_cmd))
env = os.environ.copy()
env['PYTHONPATH'] = fr"{scriptdir}{os.pathsep}{env.get('PYTHONPATH', '')}"
# Run the command
process = subprocess.Popen(
run_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE
run_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=env,
)
output, error = process.communicate()

View File

@ -72,11 +72,11 @@ def caption_images(
log.info(run_cmd)
env = os.environ.copy()
env['PYTHONPATH'] = fr"{scriptdir}{os.pathsep}{env.get('PYTHONPATH', '')}"
# Run the command
if os.name == 'posix':
os.system(run_cmd)
else:
subprocess.run(run_cmd)
subprocess.run(run_cmd, shell=True, env=env)
# Add prefix and postfix
add_pre_postfix(