Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/installing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
117 changes: 49 additions & 68 deletions launch.py
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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'")
Expand All @@ -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():
Expand All @@ -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()
42 changes: 23 additions & 19 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -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
24 changes: 0 additions & 24 deletions requirements_versions.txt

This file was deleted.