From 6d648681e4c03cf1f64336ac6eed5b0773775a16 Mon Sep 17 00:00:00 2001 From: David Sage <162500231+DavidDragonsage@users.noreply.github.com> Date: Thu, 26 Dec 2024 18:42:50 -0800 Subject: [PATCH] Alternate Startup Protocols Signed-off-by: David Sage <162500231+DavidDragonsage@users.noreply.github.com> --- argparser.py | 25 +++ entry_with_update.py | 139 +++++-------- launch.py | 481 +++++++++++++++---------------------------- pip_modules.txt | 44 ++++ version.py | 1 + 5 files changed, 280 insertions(+), 410 deletions(-) create mode 100644 argparser.py create mode 100644 pip_modules.txt create mode 100644 version.py diff --git a/argparser.py b/argparser.py new file mode 100644 index 000000000..7fa876209 --- /dev/null +++ b/argparser.py @@ -0,0 +1,25 @@ +import argparse + +parser = argparse.ArgumentParser() +parser.add_argument("--port", type=int, default=None, help="Set the listen port.") +parser.add_argument( + "--share", action="store_true", help="Set whether to share on Gradio." +) +parser.add_argument("--auth", type=str, help="Set credentials username/password.") +parser.add_argument( + "--listen", + type=str, + default=None, + metavar="IP", + nargs="?", + const="0.0.0.0", + help="Set the listen interface.", +) +parser.add_argument( + "--nobrowser", action="store_true", help="Do not launch in browser." +) +parser.add_argument("--gpu-device-id", type=int, default=None, metavar="DEVICE_ID") + + +args = parser.parse_args() + diff --git a/entry_with_update.py b/entry_with_update.py index 641999f6c..b1a603660 100644 --- a/entry_with_update.py +++ b/entry_with_update.py @@ -1,90 +1,49 @@ -import os -import sys - - -root = os.path.dirname(os.path.abspath(__file__)) -sys.path.append(root) -os.chdir(root) - - -try: - import pygit2 - pygit2.option(pygit2.GIT_OPT_SET_OWNER_VALIDATION, 0) - - repo = pygit2.Repository(os.path.abspath(os.path.dirname(__file__))) - - branch_name = repo.head.shorthand - - remote_name = 'origin' - remote = repo.remotes[remote_name] - - remote.fetch() - - origin_name = 'FooocusPlus' - main_name = 'FooocusPlus' - dev_name = 'FooocusPlus_dev' - local_branch_ref = f'refs/heads/{branch_name}' - if '--dev' in (sys.argv): - if branch_name != dev_name: - branch_name = dev_name - print(f'Ready to checkout {branch_name}') - local_branch_ref = f'refs/heads/{branch_name}' - if local_branch_ref not in list(repo.references): - remote_reference = f'refs/remotes/{remote_name}/{branch_name}' - remote_branch = repo.references[remote_reference] - new_branch = repo.create_branch(branch_name, repo[remote_branch.target]) - new_branch.upstream = remote_branch - else: - new_branch = repo.lookup_branch(branch_name) - repo.checkout(new_branch) - local_branch_ref = f'refs/heads/{branch_name}' - elif '--main' in (sys.argv): - if branch_name != origin_name: - branch_name = origin_name - print(f'Ready to checkout Fooocus') - local_branch_ref = f'refs/heads/{branch_name}' - if local_branch_ref not in list(repo.references): - remote_reference = f'refs/remotes/{remote_name}/{branch_name}' - remote_branch = repo.references[remote_reference] - new_branch = repo.create_branch(branch_name, repo[remote_branch.target]) - new_branch.upstream = remote_branch - else: - new_branch = repo.lookup_branch(branch_name) - repo.checkout(new_branch) - local_branch_ref = f'refs/heads/{branch_name}' - else: - if branch_name != main_name: - branch_name = main_name - print(f'Ready to checkout {branch_name}') - local_branch_ref = f'refs/heads/{branch_name}' - new_branch = repo.lookup_branch(branch_name) - repo.checkout(new_branch) - - local_branch = repo.lookup_reference(local_branch_ref) - local_commit = repo.revparse_single(local_branch_ref) - - remote_reference = f'refs/remotes/{remote_name}/{branch_name}' - remote_commit = repo.revparse_single(remote_reference) - - merge_result, _ = repo.merge_analysis(remote_commit.id) - - if merge_result & pygit2.GIT_MERGE_ANALYSIS_UP_TO_DATE: - print(f'{branch_name if branch_name!="main" else "Fooocus"}: Already up-to-date, {str(local_commit.id)[:7]}') - elif merge_result & pygit2.GIT_MERGE_ANALYSIS_FASTFORWARD: - local_branch.set_target(remote_commit.id) - repo.head.set_target(remote_commit.id) - repo.checkout_tree(repo.get(remote_commit.id)) - repo.reset(local_branch.target, pygit2.GIT_RESET_HARD) - print(f'{branch_name if branch_name!="main" else "Fooocus"}: Fast-forward merge, {str(local_commit.id)[:7]} <- {str(remote_commit.id)[:7]}') - elif merge_result & pygit2.GIT_MERGE_ANALYSIS_NORMAL: - print(f'{branch_name if branch_name!="main" else "Fooocus"}: Update failed - Did you modify any file? {str(local_commit.id)[:7]} <- {str(remote_commit.id)[:7]}') -except Exception as e: - print(f'{branch_name if branch_name!="main" else "Fooocus"}: Update failed.') - print(str(e)) - - -if __name__ == '__main__': - import multiprocessing as mp - mp.set_start_method('spawn') - -from launch import * +import os +import sys +from pathlib import Path + +root = Path(__file__).resolve().parent +sys.path.append(str(root)) +os.chdir(root) + +bupdated = False +try: + import pygit2 + + pygit2.option(pygit2.GIT_OPT_SET_OWNER_VALIDATION, 0) + + repo_path = Path(__file__).resolve().parent + repo = pygit2.Repository(str(repo_path)) + + branch_name = repo.head.shorthand + + remote_name = "origin" + remote = repo.remotes[remote_name] + + remote.fetch() + + local_branch_ref = f"refs/heads/{branch_name}" + local_branch = repo.lookup_reference(local_branch_ref) + + remote_reference = f"refs/remotes/{remote_name}/{branch_name}" + remote_commit = repo.revparse_single(remote_reference) + + merge_result, _ = repo.merge_analysis(remote_commit.id) + + if merge_result & pygit2.GIT_MERGE_ANALYSIS_UP_TO_DATE: + print("You have the latest version") + elif merge_result & pygit2.GIT_MERGE_ANALYSIS_FASTFORWARD: + local_branch.set_target(remote_commit.id) + repo.head.set_target(remote_commit.id) + repo.checkout_tree(repo.get(remote_commit.id)) + repo.reset(local_branch.target, pygit2.GIT_RESET_HARD) + print("Updating Files") + bupdated = True + elif merge_result & pygit2.GIT_MERGE_ANALYSIS_NORMAL: + print("Update failed, Did you modify any files?") +except Exception as e: + print("Update failed...") + print(str(e)) +if bupdated: + print("Update succeeded!!") +from launch import * diff --git a/launch.py b/launch.py index 74a236574..20eef808e 100644 --- a/launch.py +++ b/launch.py @@ -1,320 +1,161 @@ -import os -import ssl -import sys -import json -import importlib -import packaging.version -import platform -import time -import shared -import fooocus_version -import comfy.comfy_version as comfy_version -import enhanced.version as version - -from pathlib import Path -from build_launcher import build_launcher, is_win32_standalone_build, python_embeded_path -from modules.launch_util import is_installed, is_installed_version, run, python, run_pip, requirements_met, delete_folder_content, git_clone, index_url, target_path_install, met_diff - -#print('[System PATH] ' + str(sys.path)) -print('[System ARGV] ' + str(sys.argv)) - -root = os.path.dirname(os.path.abspath(__file__)) -sys.path.append(root) -os.chdir(root) - -os.environ["PYTORCH_ENABLE_MPS_FALLBACK"] = "1" -os.environ["PYTORCH_MPS_HIGH_WATERMARK_RATIO"] = "0.0" -os.environ["translators_default_region"] = "China" -if "GRADIO_SERVER_PORT" not in os.environ: - os.environ["GRADIO_SERVER_PORT"] = "7865" - -ssl._create_default_https_context = ssl._create_unverified_context - - -def check_base_environment(): - #import fooocus_version - #import comfy.comfy_version as comfy_version - #import enhanced.version as version - - print(f"Python {sys.version}") - print(f"Fooocus version: {fooocus_version.version}") - print(f"Comfy version: {comfy_version.version}") - print(f'{version.get_branch()} version: {version.get_simplesdxl_ver()}') - - base_pkg = "simpleai_base" - ver_required = "0.3.21" - REINSTALL_BASE = False if '_dev' not in version.get_branch() else True - base_file = { - "Windows": f'enhanced/libs/simpleai_base-{ver_required}-cp310-none-win_amd64.whl', - "Linux": f'enhanced/libs/simpleai_base-{ver_required}-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl' - } - #index_url = "https://pypi.org/simple" - if not is_installed(base_pkg): - run(f'"{python}" -m pip install {base_file[platform.system()]}', f'Install {base_pkg} {ver_required}') - else: - version_installed = importlib.metadata.version(base_pkg) - if REINSTALL_BASE or packaging.version.parse(ver_required) != packaging.version.parse(version_installed): - run(f'"{python}" -m pip uninstall -y {base_pkg}', f'Uninstall {base_pkg} {version_installed}') - run(f'"{python}" -m pip install {base_file[platform.system()]}', f'Install {base_pkg} {ver_required}') - - #extra_pkg = 'lark-parser' - #if not is_installed(extra_pkg): - # pkg_command = f'pip install {extra_pkg} -i {index_url}' - # run(f'"{python}" -m {pkg_command}', f'Installing {extra_pkg}', f"Couldn't install {extra_pkg}", live=True) - - if platform.system() == 'Windows' and is_installed("rembg") and not is_installed("facexlib") and not is_installed("insightface"): - print(f'Due to Windows restrictions, The new version of SimpleSDXL requires downloading a new installation package, updating the system environment, and then running it. Download URL: https://hf-mirror.com/metercai/SimpleSDXL2/') - print(f'受组件安装限制,SimpleSDXL2新版本(增加对混元、可图和SD3支持)需要下载新的程序包和基本模型包。具体操作详见:https://hf-mirror.com/metercai/SimpleSDXL2/') - print(f'If not updated, you can run the commit version using the following scripte: run_SimpleSDXL_commit.bat') - print(f'如果不升级,可下载SimpleSDXL1的独立分支完全包(未来仅修bug不加功能): https://hf-mirror.com/metercai/SimpleSDXL2/resolve/main/SimpleSDXL1_win64_all.exe.7z; 也可点击run_SimpleSDXL_commit.bat继续运行旧版本(历史存档,无法修bug也不加功能)。') - print(f'有任何疑问可到SimpleSDXL的QQ群交流: 938075852') - sys.exit(0) - if platform.system() == 'Windows' and is_installed("facexlib") and is_installed("insightface") and (not is_installed("cpm_kernels") or not is_installed_version("bitsandbytes", "0.43.3")): - print(f'运行环境中缺乏必要组件或组件版本不匹配, SimpleSDXL2的程序环境包已升级。请参照 https://hf-mirror.com/metercai/SimpleSDXL2/ 的指引, 下载安装最新程序环境包.') - print(f'The program running environment lacks necessary components. The program environment package for SimpleSDXL2 has been upgraded. Please go to https://hf-mirror.com/metercai/SimpleSDXL2/ Download and install the latest program environment package.') - print(f'有任何疑问可到SimpleSDXL的QQ群交流: 938075852') - sys.exit(0) - - from simpleai_base import simpleai_base - print("Checking ...") - token = simpleai_base.init_local(f'SimpleSDXL_User') - sysinfo = json.loads(token.get_sysinfo().to_json()) - sysinfo.update(dict(did=token.get_did())) - print(f'[SimpleAI] GPU: {sysinfo["gpu_name"]}, RAM: {sysinfo["ram_total"]}MB, SWAP: {sysinfo["ram_swap"]}MB, VRAM: {sysinfo["gpu_memory"]}MB, DiskFree: {sysinfo["disk_free"]}MB, CUDA: {sysinfo["cuda"]}') - - if (sysinfo["ram_total"]+sysinfo["ram_swap"])<40960: - print(f'The total virtual memory capacity of the system is too small, which will affect the loading and computing efficiency of the model. Please expand the total virtual memory capacity of the system to be greater than 40G.') - print(f'系统虚拟内存总容量过小,会影响模型的加载与计算效率,请扩充系统虚拟内存总容量(RAM+SWAP)大于40G。') - print(f'有任何疑问可到SimpleSDXL的QQ群交流: 938075852') - sys.exit(0) - - return token, sysinfo - - - #Intel Arc - #conda install pkg-config libuv - #python -m pip install torch==2.1.0.post2 torchvision==0.16.0.post2 torchaudio==2.1.0.post2 intel-extension-for-pytorch==2.1.30 --extra-index-url https://pytorch-extension.intel.com/release-whl/stable/xpu/cn/ - -def prepare_environment(): - REINSTALL_ALL = False - TRY_INSTALL_XFORMERS = False - - target_path_win = os.path.join(python_embeded_path, 'Lib/site-packages') - - torch_ver = '2.3.1' - torchvisio_ver = '0.18.1' - if shared.sysinfo['gpu_brand'] == 'NVIDIA': - torch_index_url = "https://download.pytorch.org/whl/cu121" - elif shared.sysinfo['gpu_brand'] == 'AMD': - if platform.system() == "Windows": - #pip uninstall torch torchvision torchaudio torchtext functorch xformers -y - #pip install torch-directml - torch_index_url = "https://download.pytorch.org/whl/" - else: - torch_index_url = "https://download.pytorch.org/whl/rocm6.0" - torch_ver = '2.3.1' - torchvisio_ver = '0.18.1' - elif shared.sysinfo['gpu_brand'] == 'INTEL': - torch_index_url = "https://pytorch-extension.intel.com/release-whl/stable/xpu/cn/" - else: - torch_index_url = "https://download.pytorch.org/whl/" - torch_index_url = os.environ.get('TORCH_INDEX_URL', torch_index_url) - torch_command = os.environ.get('TORCH_COMMAND', - f"pip install torch=={torch_ver} torchvision=={torchvisio_ver} --extra-index-url {torch_index_url}") - requirements_file = os.environ.get('REQS_FILE', "requirements_versions.txt") - torch_command += target_path_install - torch_command += f' -i {index_url} ' - - if REINSTALL_ALL or not is_installed("torch") or not is_installed("torchvision"): - run(f'"{python}" -m {torch_command}', "Installing torch and torchvision", "Couldn't install torch", live=True) - - if shared.sysinfo['gpu_brand'] == 'AMD' and platform.system() == "Windows" and not is_installed("torch-directml"): - run_pip(f"install -U -I --no-deps torch-directml", "torch-directml") - - if not is_installed("torchaudio"): - torch_command = f'pip install torchaudio=={torch_ver} -i {index_url}' - run(f'"{python}" -m {torch_command}', "Installing torchaudio", "Couldn't install torchaudio", live=True) - - if TRY_INSTALL_XFORMERS: - xformers_whl_url_win = 'https://download.pytorch.org/whl/cu121/xformers-0.0.26-cp310-cp310-win_amd64.whl' - xformers_whl_url_linux = 'https://download.pytorch.org/whl/cu121/xformers-0.0.26-cp310-cp310-manylinux2014_x86_64.whl' - if not is_installed("xformers"): - xformers_package = os.environ.get('XFORMERS_PACKAGE', 'xformers==0.0.26') - if platform.system() == "Windows": - if platform.python_version().startswith("3.10"): - run_pip(f"install -U -I --no-deps {xformers_whl_url_win}", "xformers 0.0.26", live=True) - else: - print("Installation of xformers is not supported in this version of Python.") - print( - "You can also check this and build manually: https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/Xformers#building-xformers-on-windows-by-duckness") - if not is_installed("xformers"): - exit(0) - elif platform.system() == "Linux": - run_pip(f"install -U -I --no-deps {xformers_whl_url_linux}", "xformers 0.0.26") - - if REINSTALL_ALL or not requirements_met(requirements_file): - if len(met_diff.keys())>0: - for p in met_diff.keys(): - print(f'Uninstall {p}.{met_diff[p]} ...') - run(f'"{python}" -m pip uninstall -y {p}=={met_diff[p]}') - if is_win32_standalone_build: - run_pip(f"install -r \"{requirements_file}\" -t {target_path_win}", "requirements") - else: - run_pip(f"install -r \"{requirements_file}\"", "requirements") - - patch_requirements = "requirements_patch.txt" - if (REINSTALL_ALL or not requirements_met(patch_requirements)) and not is_win32_standalone_build: - run_pip(f"install -r \"{patch_requirements}\"", "requirements patching") - return - -def ini_args(): - from args_manager import args - return args - - -def is_ipynb(): - return True if 'ipykernel' in sys.modules and hasattr(sys, '_jupyter_kernel') else False - - -def download_models(default_model, previous_default_models, checkpoint_downloads, embeddings_downloads, lora_downloads, vae_downloads): - from modules.model_loader import load_file_from_url - - vae_approx_filenames = [ - ('xlvaeapp.pth', 'https://huggingface.co/lllyasviel/misc/resolve/main/xlvaeapp.pth'), - ('vaeapp_sd15.pth', 'https://huggingface.co/lllyasviel/misc/resolve/main/vaeapp_sd15.pt'), - ('xl-to-v1_interposer-v4.0.safetensors', - 'https://huggingface.co/mashb1t/misc/resolve/main/xl-to-v1_interposer-v4.0.safetensors') - ] - - for file_name, url in vae_approx_filenames: - load_file_from_url(url=url, model_dir=config.path_vae_approx, file_name=file_name) - - load_file_from_url( - url='https://huggingface.co/lllyasviel/misc/resolve/main/fooocus_expansion.bin', - model_dir=config.path_fooocus_expansion, - file_name='pytorch_model.bin' - ) - - if shared.args.disable_preset_download: - print('Skipped model download.') - return default_model, checkpoint_downloads - - if not shared.args.always_download_new_model: - if not os.path.isfile(shared.modelsinfo.get_file_path_by_name('checkpoints', default_model)): - for alternative_model_name in previous_default_models: - if os.path.isfile(shared.modelsinfo.get_file_path_by_name('checkpoints', alternative_model_name)): - print(f'You do not have [{default_model}] but you have [{alternative_model_name}].') - print(f'Fooocus will use [{alternative_model_name}] to avoid downloading new models, ' - f'but you are not using the latest models.') - print('Use --always-download-new-model to avoid fallback and always get new models.') - checkpoint_downloads = {} - default_model = alternative_model_name - break - - for file_name, url in checkpoint_downloads.items(): - model_dir = os.path.dirname(shared.modelsinfo.get_file_path_by_name('checkpoints', file_name)) - load_file_from_url(url=url, model_dir=model_dir, file_name=os.path.basename(file_name)) - for file_name, url in embeddings_downloads.items(): - load_file_from_url(url=url, model_dir=config.path_embeddings, file_name=file_name) - for file_name, url in lora_downloads.items(): - model_dir = os.path.dirname(shared.modelsinfo.get_file_path_by_name('loras', file_name)) - load_file_from_url(url=url, model_dir=model_dir, file_name=os.path.basename(file_name)) - for file_name, url in vae_downloads.items(): - load_file_from_url(url=url, model_dir=config.path_vae, file_name=file_name) - - return default_model, checkpoint_downloads - -def reset_env_args(): - shared.sysinfo = json.loads(shared.token.get_sysinfo().to_json()) - shared.sysinfo.update(dict(did=shared.token.get_did())) - #print(f'sysinfo/基础环境信息:{sysinfo}') - - if '--location' in sys.argv: - shared.sysinfo["location"] = args.location - - if shared.sysinfo["location"] == 'CN': - os.environ['HF_MIRROR'] = 'hf-mirror.com' - if '--language' not in sys.argv: - shared.args.language='cn' - - if '--listen' not in sys.argv: - if is_ipynb(): - shared.args.listen = '127.0.0.1' - else: - shared.args.listen = shared.sysinfo["local_ip"] - if '--port' not in sys.argv: - shared.args.port = shared.sysinfo["local_port"] - - from enhanced.simpleai import reset_simpleai_args - reset_simpleai_args() - - -#build_launcher() -shared.token, shared.sysinfo = check_base_environment() -print(f'[SimpleAI] local_did/本地身份ID: {shared.token.get_did()}') - -prepare_environment() -shared.args = ini_args() - -if shared.args.gpu_device_id is not None: - os.environ['CUDA_VISIBLE_DEVICES'] = str(shared.args.gpu_device_id) - print("Set device to:", shared.args.gpu_device_id) - -if shared.sysinfo["gpu_memory"]<4000: - print(f'The GPU memory capacity of the system is too small to run the latest models such as Flux, SD3m, Kolors, and HyDiT properly, and the Comfyd engine will be automatically disabled.') - print(f'系统GPU显存容量太小,无法正常运行Flux, SD3m, Kolors和HyDiT等最新模型,将自动禁用Comfyd引擎。请知晓,尽早升级硬件。') - print(f'有任何疑问可到SimpleSDXL的QQ群交流: 938075852') - shared.args.async_cuda_allocation = False - shared.args.disable_async_cuda_allocation = True - shared.args.disable_comfyd = True - -if shared.args.async_cuda_allocation: - env_var = os.environ.get('PYTORCH_CUDA_ALLOC_CONF', None) - if env_var is None: - env_var = "backend:cudaMallocAsync" - else: - env_var += ",backend:cudaMallocAsync" - os.environ['PYTORCH_CUDA_ALLOC_CONF'] = env_var - - -import warnings -import logging -logging.basicConfig(level=logging.ERROR) -warnings.filterwarnings("ignore", category=UserWarning, module="comfy.custom_nodes, torch.utils") - -from modules import config -from modules.hash_cache import init_cache -os.environ["U2NET_HOME"] = config.paths_inpaint[0] -os.environ["BERT_HOME"] = config.paths_llms[0] -os.environ['GRADIO_TEMP_DIR'] = config.temp_path - -if shared.args.hf_mirror is not None : - os.environ['HF_MIRROR'] = str(shared.args.hf_mirror) - print("Set hf_mirror to:", shared.args.hf_mirror) - -if config.temp_path_cleanup_on_launch: - print(f'[Cleanup] Attempting to delete content of temp dir {config.temp_path}') - result = delete_folder_content(config.temp_path, '[Cleanup] ') - if result: - print("[Cleanup] Cleanup successful") - else: - print(f"[Cleanup] Failed to delete content of temp dir.") - -pyhash_key = shared.token.get_pyhash_key(fooocus_version.version, comfy_version.version, version.get_simplesdxl_ver()) -reset_env_args() -env_ready_code = shared.token.check_ready(fooocus_version.version, comfy_version.version, version.get_simplesdxl_ver(), config.path_models_root) -print(f'Env_ready_code: {env_ready_code}') -#if env_ready_code!=0 and env_ready_code!=4: -# print("系统环境检测不达标。请根据前面提示信息,重新检查并更新后再启动!") -# print(f'有任何疑问可到SimpleSDXL的QQ群交流: 938075852') -# sys.exit(0) - -config.default_base_model_name, config.checkpoint_downloads = download_models( - config.default_base_model_name, config.previous_default_models, config.checkpoint_downloads, - config.embeddings_downloads, config.lora_downloads, config.vae_downloads) - -config.update_files() -init_cache(config.model_filenames, config.paths_checkpoints, config.lora_filenames, config.paths_loras) - -from webui import * - +import os +import sys +import platform +import version +import warnings +from pathlib import Path +import ssl +import argparse + +ssl._create_default_https_context = ssl._create_unverified_context + +warnings.filterwarnings("ignore", category=FutureWarning, module="insightface") +warnings.filterwarnings("ignore", category=FutureWarning, module="transformers") +warnings.filterwarnings("ignore", category=UserWarning, module="torchvision") +warnings.filterwarnings("ignore", category=UserWarning, module="gradio") +warnings.filterwarnings("ignore", category=UserWarning, module="torchsde") +warnings.filterwarnings("ignore", category=UserWarning) + +warnings.filterwarnings( + "ignore", category=UserWarning, module="torchvision.transforms.functional_tensor" +) +warnings.filterwarnings( + "ignore", category=UserWarning, message="TypedStorage is deprecated" +) + +from modules.launch_util import ( + is_installed, + run, + python, + run_pip, + repo_dir, + requirements_met, + script_path, + dir_repos, +) + +torch_index_url = "https://download.pytorch.org/whl/cu121" +requirements_file = "requirements_versions.txt" +launch_pip_file = "pip_modules.txt" + +git_repos = [ + { + "name": "ComfyUI", + "path": "ComfyUI", + "url": "https://github.com/comfyanonymous/ComfyUI", + "hash": "935ae153e154813ace36db4c4656a5e96f403eba", + "add_path": "ComfyUI", + }, + { + "name": "Stable Fast 3D", + "path": "stable-fast-3d", + "url": "https://github.com/Stability-AI/stable-fast-3d.git", + "hash": "070ece138459e38e1fe9f54aa19edb834bced85e", + "add_path": "stable-fast-3d", + }, + { + "name": "ComfyUI-GGUF", + "path": "comfyui_gguf", + "url": "https://github.com/city96/ComfyUI-GGUF.git", + "hash": "6561064dcfb3dfa638e3739506acfd34924e1cc5", + "add_path": "", + }, +] + +REINSTALL_ALL = False +if os.path.exists("reinstall"): + REINSTALL_ALL = True + +def prepare_environment(): + print(f"Python {sys.version}") + print(f"FooocusPlus version: {version.version}") + + run(f'"{python}" -m pip install --upgrade pip', "Check pip", "Couldn't check pip", live=False) + run(f'"{python}" -m pip install -r "{requirements_file}"', "Check pre-requirements", "Couldn't check pre-reqs", live=False) + + if REINSTALL_ALL or not requirements_met(launch_pip_file): + print("This next step may take a while") + os.environ["FLASH_ATTENTION_SKIP_CUDA_BUILD"] = "TRUE" + run_pip(f'install -r "{launch_pip_file}" --extra-index-url {torch_index_url}', "required modules") + +def clone_git_repos(): + from modules.launch_util import git_clone + + for repo in git_repos: + git_clone(repo["url"], repo_dir(repo["path"]), repo["name"], repo["hash"]) + add_path = str(Path(script_path) / dir_repos / repo["add_path"]) + if add_path not in sys.path: + sys.path.append(add_path) + +def download_models(): + from modules.util import load_file_from_url + from shared import path_manager + + model_filenames = [ + ( + path_manager.model_paths["modelfile_path"], + "sd_xl_base_1.0_0.9vae.safetensors", + "https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0/resolve/main/sd_xl_base_1.0_0.9vae.safetensors", + ), + ( + path_manager.model_paths["lorafile_path"], + "sd_xl_offset_example-lora_1.0.safetensors", + "https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0/resolve/main/sd_xl_offset_example-lora_1.0.safetensors", + ), + ( + path_manager.model_paths["lorafile_path"], + "lcm-lora-sdxl.safetensors", + "https://huggingface.co/latent-consistency/lcm-lora-sdxl/resolve/main/pytorch_lora_weights.safetensors", + ), + ( + path_manager.model_paths["lorafile_path"], + "lcm-lora-ssd-1b.safetensors", + "https://huggingface.co/latent-consistency/lcm-lora-ssd-1b/resolve/main/pytorch_lora_weights.safetensors", + ), + ( + path_manager.model_paths["vae_approx_path"], + "taesdxl_decoder", + "https://github.com/madebyollin/taesd/raw/main/taesdxl_decoder.pth", + ), + ( + "prompt_expansion", + "pytorch_model.bin", + "https://huggingface.co/lllyasviel/misc/resolve/main/fooocus_expansion.bin", + ), + ( + "models/layerdiffuse/", + "layer_xl_transparent_attn.safetensors", + "https://huggingface.co/LayerDiffusion/layerdiffusion-v1/resolve/main/layer_xl_transparent_attn.safetensors", + ), + ( + "models/layerdiffuse/", + "vae_transparent_decoder.safetensors", + "https://huggingface.co/LayerDiffusion/layerdiffusion-v1/resolve/main/vae_transparent_decoder.safetensors", + ), + ] + + for model_dir, file_name, url in model_filenames: + load_file_from_url( + url=url, + model_dir=model_dir, + file_name=file_name, + ) + +from argparser import args + +if args.gpu_device_id is not None: + os.environ['CUDA_VISIBLE_DEVICES'] = str(args.gpu_device_id) + print("Set device to:", args.gpu_device_id) + +prepare_environment() +if os.path.exists("reinstall"): + os.remove("reinstall") + +try: + clone_git_repos() +except: + print(f"WARNING: Failed checking git-repos. Trying to start without update.") + +download_models() + +from webui import * diff --git a/pip_modules.txt b/pip_modules.txt new file mode 100644 index 000000000..209f39911 --- /dev/null +++ b/pip_modules.txt @@ -0,0 +1,44 @@ +torch==2.3.1+cu121 +torchvision==0.18.1+cu121 +torchsde==0.2.6 +einops==0.4.1 +transformers==4.42.4 +safetensors==0.4.3 +accelerate==0.32.1 +pyyaml==6.0.1 +Pillow==10.4.0 +scipy==1.14.0 +tqdm==4.66.4 +psutil==6.0.0 +numpy==1.26.4 +pytorch_lightning==2.3.3 +omegaconf==2.3.0 +gradio==3.41.2 +aiohttp==3.9.5 +playsound2==1.3.0 +diffusers==0.29.2 +ftfy==6.2.0 +clip_interrogator==0.6.0 +opencv-python==4.10.0.82 +kornia==0.7.2 +sentencepiece==0.1.99 +spandrel==0.3.4 +imageio[pyav]==2.34.1 +xformers==0.0.27 +beautifulsoup4==4.12.3 +protobuf==3.19.0 +rembg==2.0.57 +trimesh==4.4.4 +jaxtyping==0.2.33 +gpytoolbox==0.3.2 +pynim==1.0.5 +slangtorch==1.2.3 +numpy-stl==3.1.2 +pyrender==0.1.45 +gguf==0.10.0 +huggingface-hub==0.23.4 +typing-extensions==4.12.0 +diskcache==5.6.3 +jinja2==3.1.4 +llama_cpp_python==0.3.0; platform_system == "Linux" +https://github.com/abetlen/llama-cpp-python/releases/download/v0.3.0/llama_cpp_python-0.3.0-cp310-cp310-win_amd64.whl; platform_system == "Windows" diff --git a/version.py b/version.py new file mode 100644 index 000000000..e3415acc6 --- /dev/null +++ b/version.py @@ -0,0 +1 @@ +version = "0.9.0"