diff --git a/core/installing.py b/core/installing.py index 26f5c845877..a3b48591a2b 100644 --- a/core/installing.py +++ b/core/installing.py @@ -13,7 +13,7 @@ def is_installed(package): try: spec = importlib.util.find_spec(package) - except ModuleNotFoundError: + except (ModuleNotFoundError, AttributeError): return False return spec is not None diff --git a/launch.py b/launch.py index 7abb33fcd5c..3a97a3563ac 100644 --- a/launch.py +++ b/launch.py @@ -1,23 +1,11 @@ -# this scripts installs necessary requirements and launches main program in webui.py -import importlib import os import signal import sys import shlex -from core.cmdargs import cargs -from core.paths import repodir -from core.installing import is_installed, run, git, git_clone, run_python, run_pip, repo_dir, python - -from core.paths import rootdir -from modules.stable_diffusion.SDJob_txt2img import SDJob_txt2img - -taming_transformers_commit_hash = os.environ.get('TAMING_TRANSFORMERS_COMMIT_HASH', "24268930bf1dce879235a7fddd0b2355b84d7ea6") -torch_command = os.environ.get('TORCH_COMMAND', "pip install torch==1.12.1+cu113 torchvision==0.13.1+cu113 --extra-index-url https://download.pytorch.org/whl/cu113") -clip_package = os.environ.get('CLIP_PACKAGE', "git+https://github.com/openai/CLIP.git@d50d76daa670286dd6cacf3bcd80b5e4823fc8e1") -requirements_file = os.environ.get('REQS_FILE', "requirements_versions.txt") -commandline_args = os.environ.get('COMMANDLINE_ARGS', "") - +from core import cmdargs, paths +from core.paths import repodir, rootdir +from core.installing import is_installed, run, git, git_clone, run_python, run_pip def print_info(): try: @@ -29,14 +17,20 @@ def print_info(): def install_core(): - """ - Install all core requirements - """ - + """ Install all core requirements """ + + # Creates required download directory os.makedirs(repodir, exist_ok=True) - - if not is_installed("torch") or not is_installed("torchvision"): - run(f'"{python}" -m {torch_command}', "Installing torch and torchvision", "Couldn't install torch") + + # Setting up installation variables + requirements_file = os.environ.get('REQS_FILE', "requirements.txt") + taming_transformers_commit_hash = os.environ.get('TAMING_TRANSFORMERS_COMMIT_HASH', "24268930bf1dce879235a7fddd0b2355b84d7ea6") + clip_package = os.environ.get('CLIP_PACKAGE', "git+https://github.com/openai/CLIP.git@d50d76daa670286dd6cacf3bcd80b5e4823fc8e1") + + # Updates virtual environment with required modules + run_pip("install torch==1.12.1+cu113 torchvision==0.13.1+cu113 --extra-index-url https://download.pytorch.org/whl/cu113", "Pre-Compiled CUDA torch/torchvision") + run_pip("install --upgrade pip setuptools", "updated Python libraries") + run_pip(f"install -r {requirements_file}", "requirements for Web UI") if not '--skip-torch-cuda-test' in args: run_python("import torch; assert torch.cuda.is_available(), 'Torch is not able to use GPU; add --skip-torch-cuda-test to COMMANDLINE_ARGS variable to disable this check'") @@ -45,10 +39,7 @@ def install_core(): run_pip(f"install {clip_package}", "clip") git_clone("https://github.com/CompVis/taming-transformers.git", repodir / "taming-transformers", "Taming Transformers", taming_transformers_commit_hash) - - -def install_webui(): - run_pip(f"install -r {requirements_file}", "requirements for Web UI") + print("Installations complete") def start_webui(): @@ -62,61 +53,51 @@ def sigint_handler(sig, frame): os._exit(0) -xformers_available = False - -if __name__ == "__main__": - print_info() - - # Prepare CTRL-C handler - signal.signal(signal.SIGINT, sigint_handler) - - # Memory monitor +def memory_monitor(): from core import options, devicelib, memmon - - mem_mon = memmon.MemUsageMonitor("MemMon", devicelib.device, options.opts) # TODO remove options + # TODO: remove options + # mem_mon = memmon.MemUsageMonitor("MemMon", devicelib.device, None) + mem_mon = memmon.MemUsageMonitor("MemMon", devicelib.device, options.opts) mem_mon.start() - # Prepare args for use - from core import cmdargs - - args = shlex.split(commandline_args) - sys.argv += args - cargs = cmdargs.parser.parse_args(args) - - # Prepare plugin system - # ---------------------------------------- - from core import plugins, options, paths - # Iterate all directories in paths.repodir TODO this should be handled automatically by plugin installations +def plugin_handler(): + from core.plugins import broadcast, load_all + + # Iterate all directories in paths.repodir for d in paths.repodir.iterdir(): sys.path.insert(0, d.as_posix()) - sys.path.insert(0, (rootdir / "repositories" / "stable_diffusion" / "ldm").as_posix()) - - # TODO git clone modules from a user list - plugins.load_all(paths.plugindir) - - # Installations - # ---------------------------------------- - install_core() - plugins.broadcast("install") - print("Installations complete") + # TODO: git clone modules from a user list + load_all(paths.plugindir) + broadcast("launch") # doubt we need this + broadcast("install") # Dry run, only install and exit. - # ---------------------------------------- if cargs.dry: print("Exiting because of --dry argument") exit(0) + - # Start server - # ---------------------------------------- - plugins.broadcast("launch") # doubt we need this +if __name__ == "__main__": + """ Installs necessary requirements and launches WebUI """ - plugins.job(SDJob_txt2img(prompt="Beautiful painting of an ultra contorted landscape by Greg Ruktowsky and Salvador Dali. airbrushed, 70s prog rock album cover, psychedelic, elaborate, complex", - cfg=7.75, - steps=22, - sampler='euler-a', - )) + # Prepare args for use & CTRL-C handler + signal.signal(signal.SIGINT, sigint_handler) + args = shlex.split(os.environ.get('COMMANDLINE_ARGS', "")) + cargs = cmdargs.parser.parse_args(args) + + # Initialize + print_info() + install_core() + memory_monitor() + plugin_handler() + + # Imports modules after prerequisites are met + from modules.stable_diffusion.SDJob_txt2img import SDJob_txt2img + from core import plugins - install_webui() + # Start server + default_prompt = "Beautiful painting of an ultra contorted landscape by Greg Ruktowsky, airbrushed" + plugins.job(SDJob_txt2img(prompt=default_prompt, cfg=7.0, steps=20, sampler='euler-a', )) start_webui() diff --git a/requirements.txt b/requirements.txt index bb15f3bc928..bc4db01a902 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,28 +1,32 @@ -basicsr -diffusers -fairscale==0.4.4 +transformers==4.19.2 +diffusers==0.3.0 +basicsr==1.4.2 +gfpgan==1.3.8 +gradio==3.4.1 +numpy==1.23.3 +Pillow==9.2.0 +realesrgan==0.3.0 +torch +omegaconf==2.2.3 +pytorch_lightning==1.7.6 +scikit-image==0.19.2 fonts font-roboto -gfpgan -gradio==3.4.1 +timm==0.6.7 +fairscale==0.4.9 +piexif==1.1.3 +einops==0.4.1 +jsonmerge==1.8.0 +clean-fid==0.1.29 +resize-right==0.0.2 +torchdiffeq==0.2.3 +kornia==0.6.7 +lark==1.1.2 +font-roboto invisible-watermark -numpy -omegaconf -piexif -Pillow -pytorch_lightning -realesrgan scikit-image>=0.19 -timm==0.4.12 -transformers==4.19.2 -torch -einops -jsonmerge clean-fid resize-right -torchdiffeq -kornia -lark flask flask-socketio bunch diff --git a/requirements_versions.txt b/requirements_versions.txt deleted file mode 100644 index 2bbea40b487..00000000000 --- a/requirements_versions.txt +++ /dev/null @@ -1,24 +0,0 @@ -transformers==4.19.2 -diffusers==0.3.0 -basicsr==1.4.2 -gfpgan==1.3.8 -gradio==3.4.1 -numpy==1.23.3 -Pillow==9.2.0 -realesrgan==0.3.0 -torch -omegaconf==2.2.3 -pytorch_lightning==1.7.6 -scikit-image==0.19.2 -fonts -font-roboto -timm==0.6.7 -fairscale==0.4.9 -piexif==1.1.3 -einops==0.4.1 -jsonmerge==1.8.0 -clean-fid==0.1.29 -resize-right==0.0.2 -torchdiffeq==0.2.3 -kornia==0.6.7 -lark==1.1.2