unknown commited on
Commit
d9bc4da
·
1 Parent(s): 53bb790
Files changed (16) hide show
  1. .gitignore +33 -0
  2. .pylintrc +3 -0
  3. CODEOWNERS +12 -0
  4. README.md +169 -0
  5. artists.csv +0 -0
  6. environment-wsl2.yaml +11 -0
  7. launch.py +251 -0
  8. requirements.txt +30 -0
  9. requirements_versions.txt +27 -0
  10. screenshot.png +0 -0
  11. script.js +85 -0
  12. style.css +648 -0
  13. txt2img_Screenshot.png +0 -0
  14. webui.bat +74 -0
  15. webui.py +206 -0
  16. webui.sh +148 -0
.gitignore ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ __pycache__
2
+ *.ckpt
3
+ *.pth
4
+ /ESRGAN/*
5
+ /SwinIR/*
6
+ /repositories
7
+ /venv
8
+ /tmp
9
+ /model.ckpt
10
+ /models/**/*
11
+ /GFPGANv1.3.pth
12
+ /gfpgan/weights/*.pth
13
+ /ui-config.json
14
+ /outputs
15
+ /config.json
16
+ /log
17
+ /webui.settings.bat
18
+ /embeddings
19
+ /styles.csv
20
+ /params.txt
21
+ /styles.csv.bak
22
+ /webui-user.bat
23
+ /webui-user.sh
24
+ /interrogate
25
+ /user.css
26
+ /.idea
27
+ notification.mp3
28
+ /SwinIR
29
+ /textual_inversion
30
+ .vscode
31
+ /extensions
32
+ /test/stdout.txt
33
+ /test/stderr.txt
.pylintrc ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ # See https://pylint.pycqa.org/en/latest/user_guide/messages/message_control.html
2
+ [MESSAGES CONTROL]
3
+ disable=C,R,W,E,I
CODEOWNERS ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ * @AUTOMATIC1111
2
+
3
+ # if you were managing a localization and were removed from this file, this is because
4
+ # the intended way to do localizations now is via extensions. See:
5
+ # https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/Developing-extensions
6
+ # Make a repo with your localization and since you are still listed as a collaborator
7
+ # you can add it to the wiki page yourself. This change is because some people complained
8
+ # the git commit log is cluttered with things unrelated to almost everyone and
9
+ # because I believe this is the best overall for the project to handle localizations almost
10
+ # entirely without my oversight.
11
+
12
+
README.md CHANGED
@@ -0,0 +1,169 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Stable Diffusion web UI
2
+ A browser interface based on Gradio library for Stable Diffusion.
3
+
4
+ ![](txt2img_Screenshot.png)
5
+
6
+ Check the [custom scripts](https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/Custom-Scripts) wiki page for extra scripts developed by users.
7
+
8
+ ## Features
9
+ [Detailed feature showcase with images](https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/Features):
10
+ - Original txt2img and img2img modes
11
+ - One click install and run script (but you still must install python and git)
12
+ - Outpainting
13
+ - Inpainting
14
+ - Color Sketch
15
+ - Prompt Matrix
16
+ - Stable Diffusion Upscale
17
+ - Attention, specify parts of text that the model should pay more attention to
18
+ - a man in a ((tuxedo)) - will pay more attention to tuxedo
19
+ - a man in a (tuxedo:1.21) - alternative syntax
20
+ - select text and press ctrl+up or ctrl+down to automatically adjust attention to selected text (code contributed by anonymous user)
21
+ - Loopback, run img2img processing multiple times
22
+ - X/Y plot, a way to draw a 2 dimensional plot of images with different parameters
23
+ - Textual Inversion
24
+ - have as many embeddings as you want and use any names you like for them
25
+ - use multiple embeddings with different numbers of vectors per token
26
+ - works with half precision floating point numbers
27
+ - train embeddings on 8GB (also reports of 6GB working)
28
+ - Extras tab with:
29
+ - GFPGAN, neural network that fixes faces
30
+ - CodeFormer, face restoration tool as an alternative to GFPGAN
31
+ - RealESRGAN, neural network upscaler
32
+ - ESRGAN, neural network upscaler with a lot of third party models
33
+ - SwinIR and Swin2SR([see here](https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/2092)), neural network upscalers
34
+ - LDSR, Latent diffusion super resolution upscaling
35
+ - Resizing aspect ratio options
36
+ - Sampling method selection
37
+ - Adjust sampler eta values (noise multiplier)
38
+ - More advanced noise setting options
39
+ - Interrupt processing at any time
40
+ - 4GB video card support (also reports of 2GB working)
41
+ - Correct seeds for batches
42
+ - Live prompt token length validation
43
+ - Generation parameters
44
+ - parameters you used to generate images are saved with that image
45
+ - in PNG chunks for PNG, in EXIF for JPEG
46
+ - can drag the image to PNG info tab to restore generation parameters and automatically copy them into UI
47
+ - can be disabled in settings
48
+ - drag and drop an image/text-parameters to promptbox
49
+ - Read Generation Parameters Button, loads parameters in promptbox to UI
50
+ - Settings page
51
+ - Running arbitrary python code from UI (must run with --allow-code to enable)
52
+ - Mouseover hints for most UI elements
53
+ - Possible to change defaults/mix/max/step values for UI elements via text config
54
+ - Random artist button
55
+ - Tiling support, a checkbox to create images that can be tiled like textures
56
+ - Progress bar and live image generation preview
57
+ - Negative prompt, an extra text field that allows you to list what you don't want to see in generated image
58
+ - Styles, a way to save part of prompt and easily apply them via dropdown later
59
+ - Variations, a way to generate same image but with tiny differences
60
+ - Seed resizing, a way to generate same image but at slightly different resolution
61
+ - CLIP interrogator, a button that tries to guess prompt from an image
62
+ - Prompt Editing, a way to change prompt mid-generation, say to start making a watermelon and switch to anime girl midway
63
+ - Batch Processing, process a group of files using img2img
64
+ - Img2img Alternative, reverse Euler method of cross attention control
65
+ - Highres Fix, a convenience option to produce high resolution pictures in one click without usual distortions
66
+ - Reloading checkpoints on the fly
67
+ - Checkpoint Merger, a tab that allows you to merge up to 3 checkpoints into one
68
+ - [Custom scripts](https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/Custom-Scripts) with many extensions from community
69
+ - [Composable-Diffusion](https://energy-based-model.github.io/Compositional-Visual-Generation-with-Composable-Diffusion-Models/), a way to use multiple prompts at once
70
+ - separate prompts using uppercase `AND`
71
+ - also supports weights for prompts: `a cat :1.2 AND a dog AND a penguin :2.2`
72
+ - No token limit for prompts (original stable diffusion lets you use up to 75 tokens)
73
+ - DeepDanbooru integration, creates danbooru style tags for anime prompts
74
+ - [xformers](https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/Xformers), major speed increase for select cards: (add --xformers to commandline args)
75
+ - via extension: [History tab](https://github.com/yfszzx/stable-diffusion-webui-images-browser): view, direct and delete images conveniently within the UI
76
+ - Generate forever option
77
+ - Training tab
78
+ - hypernetworks and embeddings options
79
+ - Preprocessing images: cropping, mirroring, autotagging using BLIP or deepdanbooru (for anime)
80
+ - Clip skip
81
+ - Use Hypernetworks
82
+ - Use VAEs
83
+ - Estimated completion time in progress bar
84
+ - API
85
+ - Support for dedicated [inpainting model](https://github.com/runwayml/stable-diffusion#inpainting-with-stable-diffusion) by RunwayML.
86
+ - via extension: [Aesthetic Gradients](https://github.com/AUTOMATIC1111/stable-diffusion-webui-aesthetic-gradients), a way to generate images with a specific aesthetic by using clip images embds (implementation of [https://github.com/vicgalle/stable-diffusion-aesthetic-gradients](https://github.com/vicgalle/stable-diffusion-aesthetic-gradients))
87
+
88
+ ## Where are Aesthetic Gradients?!?!
89
+ Aesthetic Gradients are now an extension. You can install it using git:
90
+
91
+ ```commandline
92
+ git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui-aesthetic-gradients extensions/aesthetic-gradients
93
+ ```
94
+
95
+ After running this command, make sure that you have `aesthetic-gradients` dir in webui's `extensions` directory and restart
96
+ the UI. The interface for Aesthetic Gradients should appear exactly the same as it was.
97
+
98
+ ## Where is History/Image browser?!?!
99
+ Image browser is now an extension. You can install it using git:
100
+
101
+ ```commandline
102
+ git clone https://github.com/yfszzx/stable-diffusion-webui-images-browser extensions/images-browser
103
+ ```
104
+
105
+ After running this command, make sure that you have `images-browser` dir in webui's `extensions` directory and restart
106
+ the UI. The interface for Image browser should appear exactly the same as it was.
107
+
108
+ ## Installation and Running
109
+ Make sure the required [dependencies](https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/Dependencies) are met and follow the instructions available for both [NVidia](https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/Install-and-Run-on-NVidia-GPUs) (recommended) and [AMD](https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/Install-and-Run-on-AMD-GPUs) GPUs.
110
+
111
+ Alternatively, use online services (like Google Colab):
112
+
113
+ - [List of Online Services](https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/Online-Services)
114
+
115
+ ### Automatic Installation on Windows
116
+ 1. Install [Python 3.10.6](https://www.python.org/downloads/windows/), checking "Add Python to PATH"
117
+ 2. Install [git](https://git-scm.com/download/win).
118
+ 3. Download the stable-diffusion-webui repository, for example by running `git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git`.
119
+ 4. Place `model.ckpt` in the `models` directory (see [dependencies](https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/Dependencies) for where to get it).
120
+ 5. _*(Optional)*_ Place `GFPGANv1.4.pth` in the base directory, alongside `webui.py` (see [dependencies](https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/Dependencies) for where to get it).
121
+ 6. Run `webui-user.bat` from Windows Explorer as normal, non-administrator, user.
122
+
123
+ ### Automatic Installation on Linux
124
+ 1. Install the dependencies:
125
+ ```bash
126
+ # Debian-based:
127
+ sudo apt install wget git python3 python3-venv
128
+ # Red Hat-based:
129
+ sudo dnf install wget git python3
130
+ # Arch-based:
131
+ sudo pacman -S wget git python3
132
+ ```
133
+ 2. To install in `/home/$(whoami)/stable-diffusion-webui/`, run:
134
+ ```bash
135
+ bash <(wget -qO- https://raw.githubusercontent.com/AUTOMATIC1111/stable-diffusion-webui/master/webui.sh)
136
+ ```
137
+
138
+ ### Installation on Apple Silicon
139
+
140
+ Find the instructions [here](https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/Installation-on-Apple-Silicon).
141
+
142
+ ## Contributing
143
+ Here's how to add code to this repo: [Contributing](https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/Contributing)
144
+
145
+ ## Documentation
146
+ The documentation was moved from this README over to the project's [wiki](https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki).
147
+
148
+ ## Credits
149
+ - Stable Diffusion - https://github.com/CompVis/stable-diffusion, https://github.com/CompVis/taming-transformers
150
+ - k-diffusion - https://github.com/crowsonkb/k-diffusion.git
151
+ - GFPGAN - https://github.com/TencentARC/GFPGAN.git
152
+ - CodeFormer - https://github.com/sczhou/CodeFormer
153
+ - ESRGAN - https://github.com/xinntao/ESRGAN
154
+ - SwinIR - https://github.com/JingyunLiang/SwinIR
155
+ - Swin2SR - https://github.com/mv-lab/swin2sr
156
+ - LDSR - https://github.com/Hafiidz/latent-diffusion
157
+ - Ideas for optimizations - https://github.com/basujindal/stable-diffusion
158
+ - Cross Attention layer optimization - Doggettx - https://github.com/Doggettx/stable-diffusion, original idea for prompt editing.
159
+ - Cross Attention layer optimization - InvokeAI, lstein - https://github.com/invoke-ai/InvokeAI (originally http://github.com/lstein/stable-diffusion)
160
+ - Textual Inversion - Rinon Gal - https://github.com/rinongal/textual_inversion (we're not using his code, but we are using his ideas).
161
+ - Idea for SD upscale - https://github.com/jquesnelle/txt2imghd
162
+ - Noise generation for outpainting mk2 - https://github.com/parlance-zz/g-diffuser-bot
163
+ - CLIP interrogator idea and borrowing some code - https://github.com/pharmapsychotic/clip-interrogator
164
+ - Idea for Composable Diffusion - https://github.com/energy-based-model/Compositional-Visual-Generation-with-Composable-Diffusion-Models-PyTorch
165
+ - xformers - https://github.com/facebookresearch/xformers
166
+ - DeepDanbooru - interrogator for anime diffusers https://github.com/KichangKim/DeepDanbooru
167
+ - Security advice - RyotaK
168
+ - Initial Gradio script - posted on 4chan by an Anonymous user. Thank you Anonymous user.
169
+ - (You)
artists.csv ADDED
The diff for this file is too large to render. See raw diff
 
environment-wsl2.yaml ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: automatic
2
+ channels:
3
+ - pytorch
4
+ - defaults
5
+ dependencies:
6
+ - python=3.10
7
+ - pip=22.2.2
8
+ - cudatoolkit=11.3
9
+ - pytorch=1.12.1
10
+ - torchvision=0.13.1
11
+ - numpy=1.23.1
launch.py ADDED
@@ -0,0 +1,251 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # this scripts installs necessary requirements and launches main program in webui.py
2
+ import subprocess
3
+ import os
4
+ import sys
5
+ import importlib.util
6
+ import shlex
7
+ import platform
8
+
9
+ dir_repos = "repositories"
10
+ dir_extensions = "extensions"
11
+ python = sys.executable
12
+ git = os.environ.get('GIT', "git")
13
+ index_url = os.environ.get('INDEX_URL', "")
14
+
15
+
16
+ def extract_arg(args, name):
17
+ return [x for x in args if x != name], name in args
18
+
19
+
20
+ def run(command, desc=None, errdesc=None, custom_env=None):
21
+ if desc is not None:
22
+ print(desc)
23
+
24
+ result = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True, env=os.environ if custom_env is None else custom_env)
25
+
26
+ if result.returncode != 0:
27
+
28
+ message = f"""{errdesc or 'Error running command'}.
29
+ Command: {command}
30
+ Error code: {result.returncode}
31
+ stdout: {result.stdout.decode(encoding="utf8", errors="ignore") if len(result.stdout)>0 else '<empty>'}
32
+ stderr: {result.stderr.decode(encoding="utf8", errors="ignore") if len(result.stderr)>0 else '<empty>'}
33
+ """
34
+ raise RuntimeError(message)
35
+
36
+ return result.stdout.decode(encoding="utf8", errors="ignore")
37
+
38
+
39
+ def check_run(command):
40
+ result = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
41
+ return result.returncode == 0
42
+
43
+
44
+ def is_installed(package):
45
+ try:
46
+ spec = importlib.util.find_spec(package)
47
+ except ModuleNotFoundError:
48
+ return False
49
+
50
+ return spec is not None
51
+
52
+
53
+ def repo_dir(name):
54
+ return os.path.join(dir_repos, name)
55
+
56
+
57
+ def run_python(code, desc=None, errdesc=None):
58
+ return run(f'"{python}" -c "{code}"', desc, errdesc)
59
+
60
+
61
+ def run_pip(args, desc=None):
62
+ index_url_line = f' --index-url {index_url}' if index_url != '' else ''
63
+ return run(f'"{python}" -m pip {args} --prefer-binary{index_url_line}', desc=f"Installing {desc}", errdesc=f"Couldn't install {desc}")
64
+
65
+
66
+ def check_run_python(code):
67
+ return check_run(f'"{python}" -c "{code}"')
68
+
69
+
70
+ def git_clone(url, dir, name, commithash=None):
71
+ # TODO clone into temporary dir and move if successful
72
+
73
+ if os.path.exists(dir):
74
+ if commithash is None:
75
+ return
76
+
77
+ current_hash = run(f'"{git}" -C {dir} rev-parse HEAD', None, f"Couldn't determine {name}'s hash: {commithash}").strip()
78
+ if current_hash == commithash:
79
+ return
80
+
81
+ run(f'"{git}" -C {dir} fetch', f"Fetching updates for {name}...", f"Couldn't fetch {name}")
82
+ run(f'"{git}" -C {dir} checkout {commithash}', f"Checking out commit for {name} with hash: {commithash}...", f"Couldn't checkout commit {commithash} for {name}")
83
+ return
84
+
85
+ run(f'"{git}" clone "{url}" "{dir}"', f"Cloning {name} into {dir}...", f"Couldn't clone {name}")
86
+
87
+ if commithash is not None:
88
+ run(f'"{git}" -C {dir} checkout {commithash}', None, "Couldn't checkout {name}'s hash: {commithash}")
89
+
90
+
91
+ def version_check(commit):
92
+ try:
93
+ import requests
94
+ commits = requests.get('https://api.github.com/repos/AUTOMATIC1111/stable-diffusion-webui/branches/master').json()
95
+ if commit != "<none>" and commits['commit']['sha'] != commit:
96
+ print("--------------------------------------------------------")
97
+ print("| You are not up to date with the most recent release. |")
98
+ print("| Consider running `git pull` to update. |")
99
+ print("--------------------------------------------------------")
100
+ elif commits['commit']['sha'] == commit:
101
+ print("You are up to date with the most recent release.")
102
+ else:
103
+ print("Not a git clone, can't perform version check.")
104
+ except Exception as e:
105
+ print("version check failed", e)
106
+
107
+
108
+ def run_extension_installer(extension_dir):
109
+ path_installer = os.path.join(extension_dir, "install.py")
110
+ if not os.path.isfile(path_installer):
111
+ return
112
+
113
+ try:
114
+ env = os.environ.copy()
115
+ env['PYTHONPATH'] = os.path.abspath(".")
116
+
117
+ print(run(f'"{python}" "{path_installer}"', errdesc=f"Error running install.py for extension {extension_dir}", custom_env=env))
118
+ except Exception as e:
119
+ print(e, file=sys.stderr)
120
+
121
+
122
+ def run_extensions_installers():
123
+ if not os.path.isdir(dir_extensions):
124
+ return
125
+
126
+ for dirname_extension in os.listdir(dir_extensions):
127
+ run_extension_installer(os.path.join(dir_extensions, dirname_extension))
128
+
129
+
130
+ def prepare_enviroment():
131
+ 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")
132
+ requirements_file = os.environ.get('REQS_FILE', "requirements_versions.txt")
133
+ commandline_args = os.environ.get('COMMANDLINE_ARGS', "")
134
+
135
+ gfpgan_package = os.environ.get('GFPGAN_PACKAGE', "git+https://github.com/TencentARC/GFPGAN.git@8d2447a2d918f8eba5a4a01463fd48e45126a379")
136
+ clip_package = os.environ.get('CLIP_PACKAGE', "git+https://github.com/openai/CLIP.git@d50d76daa670286dd6cacf3bcd80b5e4823fc8e1")
137
+
138
+ xformers_windows_package = os.environ.get('XFORMERS_WINDOWS_PACKAGE', 'https://github.com/C43H66N12O12S2/stable-diffusion-webui/releases/download/f/xformers-0.0.14.dev0-cp310-cp310-win_amd64.whl')
139
+
140
+ stable_diffusion_repo = os.environ.get('STABLE_DIFFUSION_REPO', "https://github.com/CompVis/stable-diffusion.git")
141
+ taming_transformers_repo = os.environ.get('TAMING_TRANSFORMERS_REPO', "https://github.com/CompVis/taming-transformers.git")
142
+ k_diffusion_repo = os.environ.get('K_DIFFUSION_REPO', 'https://github.com/crowsonkb/k-diffusion.git')
143
+ codeformer_repo = os.environ.get('CODEFORMER_REPO', 'https://github.com/sczhou/CodeFormer.git')
144
+ blip_repo = os.environ.get('BLIP_REPO', 'https://github.com/salesforce/BLIP.git')
145
+
146
+ stable_diffusion_commit_hash = os.environ.get('STABLE_DIFFUSION_COMMIT_HASH', "69ae4b35e0a0f6ee1af8bb9a5d0016ccb27e36dc")
147
+ taming_transformers_commit_hash = os.environ.get('TAMING_TRANSFORMERS_COMMIT_HASH', "24268930bf1dce879235a7fddd0b2355b84d7ea6")
148
+ k_diffusion_commit_hash = os.environ.get('K_DIFFUSION_COMMIT_HASH', "60e5042ca0da89c14d1dd59d73883280f8fce991")
149
+ codeformer_commit_hash = os.environ.get('CODEFORMER_COMMIT_HASH', "c5b4593074ba6214284d6acd5f1719b6c5d739af")
150
+ blip_commit_hash = os.environ.get('BLIP_COMMIT_HASH', "48211a1594f1321b00f14c9f7a5b4813144b2fb9")
151
+
152
+ sys.argv += shlex.split(commandline_args)
153
+ test_argv = [x for x in sys.argv if x != '--tests']
154
+
155
+ sys.argv, skip_torch_cuda_test = extract_arg(sys.argv, '--skip-torch-cuda-test')
156
+ sys.argv, reinstall_xformers = extract_arg(sys.argv, '--reinstall-xformers')
157
+ sys.argv, update_check = extract_arg(sys.argv, '--update-check')
158
+ sys.argv, run_tests = extract_arg(sys.argv, '--tests')
159
+ xformers = '--xformers' in sys.argv
160
+ ngrok = '--ngrok' in sys.argv
161
+
162
+ try:
163
+ commit = run(f"{git} rev-parse HEAD").strip()
164
+ except Exception:
165
+ commit = "<none>"
166
+
167
+ print(f"Python {sys.version}")
168
+ print(f"Commit hash: {commit}")
169
+
170
+ if not is_installed("torch") or not is_installed("torchvision"):
171
+ run(f'"{python}" -m {torch_command}', "Installing torch and torchvision", "Couldn't install torch")
172
+
173
+ if not skip_torch_cuda_test:
174
+ 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'")
175
+
176
+ if not is_installed("gfpgan"):
177
+ run_pip(f"install {gfpgan_package}", "gfpgan")
178
+
179
+ if not is_installed("clip"):
180
+ run_pip(f"install {clip_package}", "clip")
181
+
182
+ if (not is_installed("xformers") or reinstall_xformers) and xformers:
183
+ if platform.system() == "Windows":
184
+ if platform.python_version().startswith("3.10"):
185
+ run_pip(f"install -U -I --no-deps {xformers_windows_package}", "xformers")
186
+ else:
187
+ print("Installation of xformers is not supported in this version of Python.")
188
+ print("You can also check this and build manually: https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/Xformers#building-xformers-on-windows-by-duckness")
189
+ if not is_installed("xformers"):
190
+ exit(0)
191
+ elif platform.system() == "Linux":
192
+ run_pip("install xformers", "xformers")
193
+
194
+ if not is_installed("pyngrok") and ngrok:
195
+ run_pip("install pyngrok", "ngrok")
196
+
197
+ os.makedirs(dir_repos, exist_ok=True)
198
+
199
+ git_clone(stable_diffusion_repo, repo_dir('stable-diffusion'), "Stable Diffusion", stable_diffusion_commit_hash)
200
+ git_clone(taming_transformers_repo, repo_dir('taming-transformers'), "Taming Transformers", taming_transformers_commit_hash)
201
+ git_clone(k_diffusion_repo, repo_dir('k-diffusion'), "K-diffusion", k_diffusion_commit_hash)
202
+ git_clone(codeformer_repo, repo_dir('CodeFormer'), "CodeFormer", codeformer_commit_hash)
203
+ git_clone(blip_repo, repo_dir('BLIP'), "BLIP", blip_commit_hash)
204
+
205
+ if not is_installed("lpips"):
206
+ run_pip(f"install -r {os.path.join(repo_dir('CodeFormer'), 'requirements.txt')}", "requirements for CodeFormer")
207
+
208
+ run_pip(f"install -r {requirements_file}", "requirements for Web UI")
209
+
210
+ run_extensions_installers()
211
+
212
+ if update_check:
213
+ version_check(commit)
214
+
215
+ if "--exit" in sys.argv:
216
+ print("Exiting because of --exit argument")
217
+ exit(0)
218
+
219
+ if run_tests:
220
+ tests(test_argv)
221
+ exit(0)
222
+
223
+
224
+ def tests(argv):
225
+ if "--api" not in argv:
226
+ argv.append("--api")
227
+
228
+ print(f"Launching Web UI in another process for testing with arguments: {' '.join(argv[1:])}")
229
+
230
+ with open('test/stdout.txt', "w", encoding="utf8") as stdout, open('test/stderr.txt', "w", encoding="utf8") as stderr:
231
+ proc = subprocess.Popen([sys.executable, *argv], stdout=stdout, stderr=stderr)
232
+
233
+ import test.server_poll
234
+ test.server_poll.run_tests()
235
+
236
+ print(f"Stopping Web UI process with id {proc.pid}")
237
+ proc.kill()
238
+
239
+
240
+ def start():
241
+ print(f"Launching {'API server' if '--nowebui' in sys.argv else 'Web UI'} with arguments: {' '.join(sys.argv[1:])}")
242
+ import webui
243
+ if '--nowebui' in sys.argv:
244
+ webui.api_only()
245
+ else:
246
+ webui.webui()
247
+
248
+
249
+ if __name__ == "__main__":
250
+ prepare_enviroment()
251
+ start()
requirements.txt ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ accelerate
2
+ basicsr
3
+ diffusers
4
+ fairscale==0.4.4
5
+ fonts
6
+ font-roboto
7
+ gfpgan
8
+ gradio==3.9
9
+ invisible-watermark
10
+ numpy
11
+ omegaconf
12
+ opencv-python
13
+ requests
14
+ piexif
15
+ Pillow
16
+ pytorch_lightning==1.7.7
17
+ realesrgan
18
+ scikit-image>=0.19
19
+ timm==0.4.12
20
+ transformers==4.19.2
21
+ torch
22
+ einops
23
+ jsonmerge
24
+ clean-fid
25
+ resize-right
26
+ torchdiffeq
27
+ kornia
28
+ lark
29
+ inflection
30
+ GitPython
requirements_versions.txt ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ transformers==4.19.2
2
+ diffusers==0.3.0
3
+ accelerate==0.12.0
4
+ basicsr==1.4.2
5
+ gfpgan==1.3.8
6
+ gradio==3.9
7
+ numpy==1.23.3
8
+ Pillow==9.2.0
9
+ realesrgan==0.3.0
10
+ torch
11
+ omegaconf==2.2.3
12
+ pytorch_lightning==1.7.6
13
+ scikit-image==0.19.2
14
+ fonts
15
+ font-roboto
16
+ timm==0.6.7
17
+ fairscale==0.4.9
18
+ piexif==1.1.3
19
+ einops==0.4.1
20
+ jsonmerge==1.8.0
21
+ clean-fid==0.1.29
22
+ resize-right==0.0.2
23
+ torchdiffeq==0.2.3
24
+ kornia==0.6.7
25
+ lark==1.1.2
26
+ inflection==0.5.1
27
+ GitPython==3.1.27
screenshot.png ADDED
script.js ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ function gradioApp(){
2
+ return document.getElementsByTagName('gradio-app')[0].shadowRoot;
3
+ }
4
+
5
+ function get_uiCurrentTab() {
6
+ return gradioApp().querySelector('.tabs button:not(.border-transparent)')
7
+ }
8
+
9
+ function get_uiCurrentTabContent() {
10
+ return gradioApp().querySelector('.tabitem[id^=tab_]:not([style*="display: none"])')
11
+ }
12
+
13
+ uiUpdateCallbacks = []
14
+ uiTabChangeCallbacks = []
15
+ let uiCurrentTab = null
16
+
17
+ function onUiUpdate(callback){
18
+ uiUpdateCallbacks.push(callback)
19
+ }
20
+ function onUiTabChange(callback){
21
+ uiTabChangeCallbacks.push(callback)
22
+ }
23
+
24
+ function runCallback(x, m){
25
+ try {
26
+ x(m)
27
+ } catch (e) {
28
+ (console.error || console.log).call(console, e.message, e);
29
+ }
30
+ }
31
+ function executeCallbacks(queue, m) {
32
+ queue.forEach(function(x){runCallback(x, m)})
33
+ }
34
+
35
+ document.addEventListener("DOMContentLoaded", function() {
36
+ var mutationObserver = new MutationObserver(function(m){
37
+ executeCallbacks(uiUpdateCallbacks, m);
38
+ const newTab = get_uiCurrentTab();
39
+ if ( newTab && ( newTab !== uiCurrentTab ) ) {
40
+ uiCurrentTab = newTab;
41
+ executeCallbacks(uiTabChangeCallbacks);
42
+ }
43
+ });
44
+ mutationObserver.observe( gradioApp(), { childList:true, subtree:true })
45
+ });
46
+
47
+ /**
48
+ * Add a ctrl+enter as a shortcut to start a generation
49
+ */
50
+ document.addEventListener('keydown', function(e) {
51
+ var handled = false;
52
+ if (e.key !== undefined) {
53
+ if((e.key == "Enter" && (e.metaKey || e.ctrlKey || e.altKey))) handled = true;
54
+ } else if (e.keyCode !== undefined) {
55
+ if((e.keyCode == 13 && (e.metaKey || e.ctrlKey || e.altKey))) handled = true;
56
+ }
57
+ if (handled) {
58
+ button = get_uiCurrentTabContent().querySelector('button[id$=_generate]');
59
+ if (button) {
60
+ button.click();
61
+ }
62
+ e.preventDefault();
63
+ }
64
+ })
65
+
66
+ /**
67
+ * checks that a UI element is not in another hidden element or tab content
68
+ */
69
+ function uiElementIsVisible(el) {
70
+ let isVisible = !el.closest('.\\!hidden');
71
+ if ( ! isVisible ) {
72
+ return false;
73
+ }
74
+
75
+ while( isVisible = el.closest('.tabitem')?.style.display !== 'none' ) {
76
+ if ( ! isVisible ) {
77
+ return false;
78
+ } else if ( el.parentElement ) {
79
+ el = el.parentElement
80
+ } else {
81
+ break;
82
+ }
83
+ }
84
+ return isVisible;
85
+ }
style.css ADDED
@@ -0,0 +1,648 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .container {
2
+ max-width: 100%;
3
+ }
4
+
5
+ #txt2img_token_counter {
6
+ height: 0px;
7
+ }
8
+
9
+ #img2img_token_counter {
10
+ height: 0px;
11
+ }
12
+
13
+ #sh{
14
+ min-width: 2em;
15
+ min-height: 2em;
16
+ max-width: 2em;
17
+ max-height: 2em;
18
+ flex-grow: 0;
19
+ padding-left: 0.25em;
20
+ padding-right: 0.25em;
21
+ margin: 0.1em 0;
22
+ opacity: 0%;
23
+ cursor: default;
24
+ }
25
+
26
+ .output-html p {margin: 0 0.5em;}
27
+
28
+ .row > *,
29
+ .row > .gr-form > * {
30
+ min-width: min(120px, 100%);
31
+ flex: 1 1 0%;
32
+ }
33
+
34
+ .performance {
35
+ font-size: 0.85em;
36
+ color: #444;
37
+ }
38
+
39
+ .performance p{
40
+ display: inline-block;
41
+ }
42
+
43
+ .performance .time {
44
+ margin-right: 0;
45
+ }
46
+
47
+ .performance .vram {
48
+ }
49
+
50
+ #txt2img_generate, #img2img_generate {
51
+ min-height: 4.5em;
52
+ }
53
+
54
+ @media screen and (min-width: 2500px) {
55
+ #txt2img_gallery, #img2img_gallery {
56
+ min-height: 768px;
57
+ }
58
+ }
59
+
60
+ #txt2img_gallery img, #img2img_gallery img{
61
+ object-fit: scale-down;
62
+ }
63
+
64
+ .justify-center.overflow-x-scroll {
65
+ justify-content: left;
66
+ }
67
+
68
+ .justify-center.overflow-x-scroll button:first-of-type {
69
+ margin-left: auto;
70
+ }
71
+
72
+ .justify-center.overflow-x-scroll button:last-of-type {
73
+ margin-right: auto;
74
+ }
75
+
76
+ #random_seed, #random_subseed, #reuse_seed, #reuse_subseed, #open_folder{
77
+ min-width: auto;
78
+ flex-grow: 0;
79
+ padding-left: 0.25em;
80
+ padding-right: 0.25em;
81
+ }
82
+
83
+ #hidden_element{
84
+ display: none;
85
+ }
86
+
87
+ #seed_row, #subseed_row{
88
+ gap: 0.5rem;
89
+ }
90
+
91
+ #subseed_show_box{
92
+ min-width: auto;
93
+ flex-grow: 0;
94
+ }
95
+
96
+ #subseed_show_box > div{
97
+ border: 0;
98
+ height: 100%;
99
+ }
100
+
101
+ #subseed_show{
102
+ min-width: auto;
103
+ flex-grow: 0;
104
+ padding: 0;
105
+ }
106
+
107
+ #subseed_show label{
108
+ height: 100%;
109
+ }
110
+
111
+ #roll_col{
112
+ min-width: unset !important;
113
+ flex-grow: 0 !important;
114
+ padding: 0.4em 0;
115
+ }
116
+
117
+ #roll, #paste, #style_create, #style_apply{
118
+ min-width: 2em;
119
+ min-height: 2em;
120
+ max-width: 2em;
121
+ max-height: 2em;
122
+ flex-grow: 0;
123
+ padding-left: 0.25em;
124
+ padding-right: 0.25em;
125
+ margin: 0.1em 0;
126
+ }
127
+
128
+ #interrogate_col{
129
+ min-width: 0 !important;
130
+ max-width: 8em !important;
131
+ }
132
+ #interrogate, #deepbooru{
133
+ margin: 0em 0.25em 0.9em 0.25em;
134
+ min-width: 8em;
135
+ max-width: 8em;
136
+ }
137
+
138
+ #style_pos_col, #style_neg_col{
139
+ min-width: 8em !important;
140
+ }
141
+
142
+ #txt2img_style_index, #txt2img_style2_index, #img2img_style_index, #img2img_style2_index{
143
+ margin-top: 1em;
144
+ }
145
+
146
+ .gr-form{
147
+ background: transparent;
148
+ }
149
+
150
+ .my-4{
151
+ margin-top: 0;
152
+ margin-bottom: 0;
153
+ }
154
+
155
+ #toprow div{
156
+ border: none;
157
+ gap: 0;
158
+ background: transparent;
159
+ }
160
+
161
+ #resize_mode{
162
+ flex: 1.5;
163
+ }
164
+
165
+ button{
166
+ align-self: stretch !important;
167
+ }
168
+
169
+ .overflow-hidden, .gr-panel{
170
+ overflow: visible !important;
171
+ }
172
+
173
+ #x_type, #y_type{
174
+ max-width: 10em;
175
+ }
176
+
177
+ #txt2img_preview, #img2img_preview, #ti_preview{
178
+ position: absolute;
179
+ width: 320px;
180
+ left: 0;
181
+ right: 0;
182
+ margin-left: auto;
183
+ margin-right: auto;
184
+ margin-top: 34px;
185
+ z-index: 100;
186
+ border: none;
187
+ border-top-left-radius: 0;
188
+ border-top-right-radius: 0;
189
+ }
190
+
191
+ @media screen and (min-width: 768px) {
192
+ #txt2img_preview, #img2img_preview, #ti_preview {
193
+ position: absolute;
194
+ }
195
+ }
196
+
197
+ @media screen and (max-width: 767px) {
198
+ #txt2img_preview, #img2img_preview, #ti_preview {
199
+ position: relative;
200
+ }
201
+ }
202
+
203
+ #txt2img_preview div.left-0.top-0, #img2img_preview div.left-0.top-0, #ti_preview div.left-0.top-0{
204
+ display: none;
205
+ }
206
+
207
+ fieldset span.text-gray-500, .gr-block.gr-box span.text-gray-500, label.block span{
208
+ position: absolute;
209
+ top: -0.6em;
210
+ line-height: 1.2em;
211
+ padding: 0 0.5em;
212
+ margin: 0;
213
+
214
+ background-color: white;
215
+ border-top: 1px solid #eee;
216
+ border-left: 1px solid #eee;
217
+ border-right: 1px solid #eee;
218
+
219
+ z-index: 300;
220
+ }
221
+
222
+ .dark fieldset span.text-gray-500, .dark .gr-block.gr-box span.text-gray-500, .dark label.block span{
223
+ background-color: rgb(31, 41, 55);
224
+ border-top: 1px solid rgb(55 65 81);
225
+ border-left: 1px solid rgb(55 65 81);
226
+ border-right: 1px solid rgb(55 65 81);
227
+ }
228
+
229
+ #settings fieldset span.text-gray-500, #settings .gr-block.gr-box span.text-gray-500, #settings label.block span{
230
+ position: relative;
231
+ border: none;
232
+ margin-right: 8em;
233
+ }
234
+
235
+ .gr-panel div.flex-col div.justify-between label span{
236
+ margin: 0;
237
+ }
238
+
239
+ #settings .gr-panel div.flex-col div.justify-between div{
240
+ position: relative;
241
+ z-index: 200;
242
+ }
243
+
244
+ input[type="range"]{
245
+ margin: 0.5em 0 -0.3em 0;
246
+ }
247
+
248
+ #txt2img_sampling label{
249
+ padding-left: 0.6em;
250
+ padding-right: 0.6em;
251
+ }
252
+
253
+ #mask_bug_info {
254
+ text-align: center;
255
+ display: block;
256
+ margin-top: -0.75em;
257
+ margin-bottom: -0.75em;
258
+ }
259
+
260
+ #txt2img_negative_prompt, #img2img_negative_prompt{
261
+ }
262
+
263
+ /* gradio 3.8 adds opacity to progressbar which makes it blink; disable it here */
264
+ .transition.opacity-20 {
265
+ opacity: 1 !important;
266
+ }
267
+
268
+ /* more gradio's garbage cleanup */
269
+ .min-h-\[4rem\] {
270
+ min-height: unset !important;
271
+ }
272
+
273
+ #txt2img_progressbar, #img2img_progressbar, #ti_progressbar{
274
+ position: absolute;
275
+ z-index: 1000;
276
+ right: 0;
277
+ padding-left: 5px;
278
+ padding-right: 5px;
279
+ display: block;
280
+ }
281
+
282
+ #txt2img_progress_row, #img2img_progress_row{
283
+ margin-bottom: 10px;
284
+ margin-top: -18px;
285
+ }
286
+
287
+ .progressDiv{
288
+ width: 100%;
289
+ height: 20px;
290
+ background: #b4c0cc;
291
+ border-radius: 8px;
292
+ }
293
+
294
+ .dark .progressDiv{
295
+ background: #424c5b;
296
+ }
297
+
298
+ .progressDiv .progress{
299
+ width: 0%;
300
+ height: 20px;
301
+ background: #0060df;
302
+ color: white;
303
+ font-weight: bold;
304
+ line-height: 20px;
305
+ padding: 0 8px 0 0;
306
+ text-align: right;
307
+ border-radius: 8px;
308
+ }
309
+
310
+ #lightboxModal{
311
+ display: none;
312
+ position: fixed;
313
+ z-index: 1001;
314
+ padding-top: 100px;
315
+ left: 0;
316
+ top: 0;
317
+ width: 100%;
318
+ height: 100%;
319
+ overflow: auto;
320
+ background-color: rgba(20, 20, 20, 0.95);
321
+ user-select: none;
322
+ -webkit-user-select: none;
323
+ }
324
+
325
+ .modalControls {
326
+ display: grid;
327
+ grid-template-columns: 32px 32px 32px 1fr 32px;
328
+ grid-template-areas: "zoom tile save space close";
329
+ position: absolute;
330
+ top: 0;
331
+ left: 0;
332
+ right: 0;
333
+ padding: 16px;
334
+ gap: 16px;
335
+ background-color: rgba(0,0,0,0.2);
336
+ }
337
+
338
+ .modalClose {
339
+ grid-area: close;
340
+ }
341
+
342
+ .modalZoom {
343
+ grid-area: zoom;
344
+ }
345
+
346
+ .modalSave {
347
+ grid-area: save;
348
+ }
349
+
350
+ .modalTileImage {
351
+ grid-area: tile;
352
+ }
353
+
354
+ .modalClose,
355
+ .modalZoom,
356
+ .modalTileImage {
357
+ color: white;
358
+ font-size: 35px;
359
+ font-weight: bold;
360
+ cursor: pointer;
361
+ }
362
+
363
+ .modalSave {
364
+ color: white;
365
+ font-size: 28px;
366
+ margin-top: 8px;
367
+ font-weight: bold;
368
+ cursor: pointer;
369
+ }
370
+
371
+ .modalClose:hover,
372
+ .modalClose:focus,
373
+ .modalSave:hover,
374
+ .modalSave:focus,
375
+ .modalZoom:hover,
376
+ .modalZoom:focus {
377
+ color: #999;
378
+ text-decoration: none;
379
+ cursor: pointer;
380
+ }
381
+
382
+ #modalImage {
383
+ display: block;
384
+ margin-left: auto;
385
+ margin-right: auto;
386
+ margin-top: auto;
387
+ width: auto;
388
+ }
389
+
390
+ .modalImageFullscreen {
391
+ object-fit: contain;
392
+ height: 90%;
393
+ }
394
+
395
+ .modalPrev,
396
+ .modalNext {
397
+ cursor: pointer;
398
+ position: absolute;
399
+ top: 50%;
400
+ width: auto;
401
+ padding: 16px;
402
+ margin-top: -50px;
403
+ color: white;
404
+ font-weight: bold;
405
+ font-size: 20px;
406
+ transition: 0.6s ease;
407
+ border-radius: 0 3px 3px 0;
408
+ user-select: none;
409
+ -webkit-user-select: none;
410
+ }
411
+
412
+ .modalNext {
413
+ right: 0;
414
+ border-radius: 3px 0 0 3px;
415
+ }
416
+
417
+ .modalPrev:hover,
418
+ .modalNext:hover {
419
+ background-color: rgba(0, 0, 0, 0.8);
420
+ }
421
+
422
+ #imageARPreview{
423
+ position:absolute;
424
+ top:0px;
425
+ left:0px;
426
+ border:2px solid red;
427
+ background:rgba(255, 0, 0, 0.3);
428
+ z-index: 900;
429
+ pointer-events:none;
430
+ display:none
431
+ }
432
+
433
+ #txt2img_interrupt, #img2img_interrupt{
434
+ position: absolute;
435
+ width: 50%;
436
+ height: 72px;
437
+ background: #b4c0cc;
438
+ border-radius: 0px;
439
+ display: none;
440
+ }
441
+
442
+ #txt2img_skip, #img2img_skip{
443
+ position: absolute;
444
+ width: 50%;
445
+ right: 0px;
446
+ height: 72px;
447
+ background: #b4c0cc;
448
+ border-radius: 0px;
449
+ display: none;
450
+ }
451
+
452
+ .red {
453
+ color: red;
454
+ }
455
+
456
+ .gallery-item {
457
+ --tw-bg-opacity: 0 !important;
458
+ }
459
+
460
+ #context-menu{
461
+ z-index:9999;
462
+ position:absolute;
463
+ display:block;
464
+ padding:0px 0;
465
+ border:2px solid #a55000;
466
+ border-radius:8px;
467
+ box-shadow:1px 1px 2px #CE6400;
468
+ width: 200px;
469
+ }
470
+
471
+ .context-menu-items{
472
+ list-style: none;
473
+ margin: 0;
474
+ padding: 0;
475
+ }
476
+
477
+ .context-menu-items a{
478
+ display:block;
479
+ padding:5px;
480
+ cursor:pointer;
481
+ }
482
+
483
+ .context-menu-items a:hover{
484
+ background: #a55000;
485
+ }
486
+
487
+ #quicksettings {
488
+ gap: 0.4em;
489
+ }
490
+
491
+ #quicksettings > div{
492
+ border: none;
493
+ background: none;
494
+ flex: unset;
495
+ gap: 0.5em;
496
+ }
497
+
498
+ #quicksettings > div > div{
499
+ max-width: 32em;
500
+ min-width: 24em;
501
+ padding: 0;
502
+ }
503
+
504
+ #refresh_sd_model_checkpoint, #refresh_sd_vae, #refresh_sd_hypernetwork, #refresh_train_hypernetwork_name, #refresh_train_embedding_name, #refresh_localization{
505
+ max-width: 2.5em;
506
+ min-width: 2.5em;
507
+ height: 2.4em;
508
+ }
509
+
510
+
511
+ canvas[key="mask"] {
512
+ z-index: 12 !important;
513
+ filter: invert();
514
+ mix-blend-mode: multiply;
515
+ pointer-events: none;
516
+ }
517
+
518
+
519
+ /* gradio 3.4.1 stuff for editable scrollbar values */
520
+ .gr-box > div > div > input.gr-text-input{
521
+ position: absolute;
522
+ right: 0.5em;
523
+ top: -0.6em;
524
+ z-index: 200;
525
+ width: 8em;
526
+ }
527
+ #quicksettings .gr-box > div > div > input.gr-text-input {
528
+ top: -1.12em;
529
+ }
530
+
531
+ .row.gr-compact{
532
+ overflow: visible;
533
+ }
534
+
535
+ #img2img_image, #img2img_image > .h-60, #img2img_image > .h-60 > div, #img2img_image > .h-60 > div > img,
536
+ img2maskimg, #img2maskimg > .h-60, #img2maskimg > .h-60 > div, #img2maskimg > .h-60 > div > img
537
+ {
538
+ height: 480px !important;
539
+ max-height: 480px !important;
540
+ min-height: 480px !important;
541
+ }
542
+
543
+ /* Extensions */
544
+
545
+ #tab_extensions table{
546
+ border-collapse: collapse;
547
+ }
548
+
549
+ #tab_extensions table td, #tab_extensions table th{
550
+ border: 1px solid #ccc;
551
+ padding: 0.25em 0.5em;
552
+ }
553
+
554
+ #tab_extensions table input[type="checkbox"]{
555
+ margin-right: 0.5em;
556
+ }
557
+
558
+ #tab_extensions button{
559
+ max-width: 16em;
560
+ }
561
+
562
+ #tab_extensions input[disabled="disabled"]{
563
+ opacity: 0.5;
564
+ }
565
+
566
+ .extension-tag{
567
+ font-weight: bold;
568
+ font-size: 95%;
569
+ }
570
+
571
+ /* The following handles localization for right-to-left (RTL) languages like Arabic.
572
+ The rtl media type will only be activated by the logic in javascript/localization.js.
573
+ If you change anything above, you need to make sure it is RTL compliant by just running
574
+ your changes through converters like https://cssjanus.github.io/ or https://rtlcss.com/.
575
+ Then, you will need to add the RTL counterpart only if needed in the rtl section below.*/
576
+ @media rtl {
577
+ /* this part was added manually */
578
+ :host {
579
+ direction: rtl;
580
+ }
581
+ select, .file-preview, .gr-text-input, .output-html:has(.performance), #ti_progress {
582
+ direction: ltr;
583
+ }
584
+ #script_list > label > select,
585
+ #x_type > label > select,
586
+ #y_type > label > select {
587
+ direction: rtl;
588
+ }
589
+ .gr-radio, .gr-checkbox{
590
+ margin-left: 0.25em;
591
+ }
592
+
593
+ /* automatically generated with few manual modifications */
594
+ .performance .time {
595
+ margin-right: unset;
596
+ margin-left: 0;
597
+ }
598
+ .justify-center.overflow-x-scroll {
599
+ justify-content: right;
600
+ }
601
+ .justify-center.overflow-x-scroll button:first-of-type {
602
+ margin-left: unset;
603
+ margin-right: auto;
604
+ }
605
+ .justify-center.overflow-x-scroll button:last-of-type {
606
+ margin-right: unset;
607
+ margin-left: auto;
608
+ }
609
+ #settings fieldset span.text-gray-500, #settings .gr-block.gr-box span.text-gray-500, #settings label.block span{
610
+ margin-right: unset;
611
+ margin-left: 8em;
612
+ }
613
+ #txt2img_progressbar, #img2img_progressbar, #ti_progressbar{
614
+ right: unset;
615
+ left: 0;
616
+ }
617
+ .progressDiv .progress{
618
+ padding: 0 0 0 8px;
619
+ text-align: left;
620
+ }
621
+ #lightboxModal{
622
+ left: unset;
623
+ right: 0;
624
+ }
625
+ .modalPrev, .modalNext{
626
+ border-radius: 3px 0 0 3px;
627
+ }
628
+ .modalNext {
629
+ right: unset;
630
+ left: 0;
631
+ border-radius: 0 3px 3px 0;
632
+ }
633
+ #imageARPreview{
634
+ left:unset;
635
+ right:0px;
636
+ }
637
+ #txt2img_skip, #img2img_skip{
638
+ right: unset;
639
+ left: 0px;
640
+ }
641
+ #context-menu{
642
+ box-shadow:-1px 1px 2px #CE6400;
643
+ }
644
+ .gr-box > div > div > input.gr-text-input{
645
+ right: unset;
646
+ left: 0.5em;
647
+ }
648
+ }
txt2img_Screenshot.png ADDED
webui.bat ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @echo off
2
+
3
+ if not defined PYTHON (set PYTHON=python)
4
+ if not defined VENV_DIR (set VENV_DIR=venv)
5
+
6
+ set ERROR_REPORTING=FALSE
7
+
8
+ mkdir tmp 2>NUL
9
+
10
+ %PYTHON% -c "" >tmp/stdout.txt 2>tmp/stderr.txt
11
+ if %ERRORLEVEL% == 0 goto :start_venv
12
+ echo Couldn't launch python
13
+ goto :show_stdout_stderr
14
+
15
+ :start_venv
16
+ if [%VENV_DIR%] == [-] goto :skip_venv
17
+
18
+ dir %VENV_DIR%\Scripts\Python.exe >tmp/stdout.txt 2>tmp/stderr.txt
19
+ if %ERRORLEVEL% == 0 goto :activate_venv
20
+
21
+ for /f "delims=" %%i in ('CALL %PYTHON% -c "import sys; print(sys.executable)"') do set PYTHON_FULLNAME="%%i"
22
+ echo Creating venv in directory %VENV_DIR% using python %PYTHON_FULLNAME%
23
+ %PYTHON_FULLNAME% -m venv %VENV_DIR% >tmp/stdout.txt 2>tmp/stderr.txt
24
+ if %ERRORLEVEL% == 0 goto :activate_venv
25
+ echo Unable to create venv in directory %VENV_DIR%
26
+ goto :show_stdout_stderr
27
+
28
+ :activate_venv
29
+ set PYTHON="%~dp0%VENV_DIR%\Scripts\Python.exe"
30
+ echo venv %PYTHON%
31
+ if [%ACCELERATE%] == ["True"] goto :accelerate
32
+ goto :launch
33
+
34
+ :skip_venv
35
+
36
+ :accelerate
37
+ echo "Checking for accelerate"
38
+ set ACCELERATE="%~dp0%VENV_DIR%\Scripts\accelerate.exe"
39
+ if EXIST %ACCELERATE% goto :accelerate_launch
40
+
41
+ :launch
42
+ %PYTHON% launch.py %*
43
+ pause
44
+ exit /b
45
+
46
+ :accelerate_launch
47
+ echo "Accelerating"
48
+ %ACCELERATE% launch --num_cpu_threads_per_process=6 launch.py
49
+ pause
50
+ exit /b
51
+
52
+ :show_stdout_stderr
53
+
54
+ echo.
55
+ echo exit code: %errorlevel%
56
+
57
+ for /f %%i in ("tmp\stdout.txt") do set size=%%~zi
58
+ if %size% equ 0 goto :show_stderr
59
+ echo.
60
+ echo stdout:
61
+ type tmp\stdout.txt
62
+
63
+ :show_stderr
64
+ for /f %%i in ("tmp\stderr.txt") do set size=%%~zi
65
+ if %size% equ 0 goto :show_stderr
66
+ echo.
67
+ echo stderr:
68
+ type tmp\stderr.txt
69
+
70
+ :endofscript
71
+
72
+ echo.
73
+ echo Launch unsuccessful. Exiting.
74
+ pause
webui.py ADDED
@@ -0,0 +1,206 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import threading
3
+ import time
4
+ import importlib
5
+ import signal
6
+ import threading
7
+ from fastapi import FastAPI
8
+ from fastapi.middleware.cors import CORSMiddleware
9
+ from fastapi.middleware.gzip import GZipMiddleware
10
+
11
+ from modules.paths import script_path
12
+
13
+ from modules import devices, sd_samplers, upscaler, extensions, localization
14
+ import modules.codeformer_model as codeformer
15
+ import modules.extras
16
+ import modules.face_restoration
17
+ import modules.gfpgan_model as gfpgan
18
+ import modules.img2img
19
+
20
+ import modules.lowvram
21
+ import modules.paths
22
+ import modules.scripts
23
+ import modules.sd_hijack
24
+ import modules.sd_models
25
+ import modules.sd_vae
26
+ import modules.shared as shared
27
+ import modules.txt2img
28
+ import modules.script_callbacks
29
+
30
+ import modules.ui
31
+ from modules import modelloader
32
+ from modules.shared import cmd_opts
33
+ import modules.hypernetworks.hypernetwork
34
+
35
+ queue_lock = threading.Lock()
36
+ if cmd_opts.server_name:
37
+ server_name = cmd_opts.server_name
38
+ else:
39
+ server_name = "0.0.0.0" if cmd_opts.listen else None
40
+
41
+ def wrap_queued_call(func):
42
+ def f(*args, **kwargs):
43
+ with queue_lock:
44
+ res = func(*args, **kwargs)
45
+
46
+ return res
47
+
48
+ return f
49
+
50
+
51
+ def wrap_gradio_gpu_call(func, extra_outputs=None):
52
+ def f(*args, **kwargs):
53
+
54
+ shared.state.begin()
55
+
56
+ with queue_lock:
57
+ res = func(*args, **kwargs)
58
+
59
+ shared.state.end()
60
+
61
+ return res
62
+
63
+ return modules.ui.wrap_gradio_call(f, extra_outputs=extra_outputs, add_stats=True)
64
+
65
+
66
+ def initialize():
67
+ extensions.list_extensions()
68
+ localization.list_localizations(cmd_opts.localizations_dir)
69
+
70
+ if cmd_opts.ui_debug_mode:
71
+ shared.sd_upscalers = upscaler.UpscalerLanczos().scalers
72
+ modules.scripts.load_scripts()
73
+ return
74
+
75
+ modelloader.cleanup_models()
76
+ modules.sd_models.setup_model()
77
+ codeformer.setup_model(cmd_opts.codeformer_models_path)
78
+ gfpgan.setup_model(cmd_opts.gfpgan_models_path)
79
+ shared.face_restorers.append(modules.face_restoration.FaceRestoration())
80
+ modelloader.load_upscalers()
81
+
82
+ modules.scripts.load_scripts()
83
+
84
+ modules.sd_vae.refresh_vae_list()
85
+ modules.sd_models.load_model()
86
+ shared.opts.onchange("sd_model_checkpoint", wrap_queued_call(lambda: modules.sd_models.reload_model_weights()))
87
+ shared.opts.onchange("sd_vae", wrap_queued_call(lambda: modules.sd_vae.reload_vae_weights()), call=False)
88
+ shared.opts.onchange("sd_vae_as_default", wrap_queued_call(lambda: modules.sd_vae.reload_vae_weights()), call=False)
89
+ shared.opts.onchange("sd_hypernetwork", wrap_queued_call(lambda: modules.hypernetworks.hypernetwork.load_hypernetwork(shared.opts.sd_hypernetwork)))
90
+ shared.opts.onchange("sd_hypernetwork_strength", modules.hypernetworks.hypernetwork.apply_strength)
91
+
92
+ if cmd_opts.tls_keyfile is not None and cmd_opts.tls_keyfile is not None:
93
+
94
+ try:
95
+ if not os.path.exists(cmd_opts.tls_keyfile):
96
+ print("Invalid path to TLS keyfile given")
97
+ if not os.path.exists(cmd_opts.tls_certfile):
98
+ print(f"Invalid path to TLS certfile: '{cmd_opts.tls_certfile}'")
99
+ except TypeError:
100
+ cmd_opts.tls_keyfile = cmd_opts.tls_certfile = None
101
+ print("TLS setup invalid, running webui without TLS")
102
+ else:
103
+ print("Running with TLS")
104
+
105
+ # make the program just exit at ctrl+c without waiting for anything
106
+ def sigint_handler(sig, frame):
107
+ print(f'Interrupted with signal {sig} in {frame}')
108
+ os._exit(0)
109
+
110
+ signal.signal(signal.SIGINT, sigint_handler)
111
+
112
+
113
+ def setup_cors(app):
114
+ if cmd_opts.cors_allow_origins:
115
+ app.add_middleware(CORSMiddleware, allow_origins=cmd_opts.cors_allow_origins.split(','), allow_methods=['*'])
116
+
117
+
118
+ def create_api(app):
119
+ from modules.api.api import Api
120
+ api = Api(app, queue_lock)
121
+ return api
122
+
123
+
124
+ def wait_on_server(demo=None):
125
+ while 1:
126
+ time.sleep(0.5)
127
+ if shared.state.need_restart:
128
+ shared.state.need_restart = False
129
+ time.sleep(0.5)
130
+ demo.close()
131
+ time.sleep(0.5)
132
+ break
133
+
134
+
135
+ def api_only():
136
+ initialize()
137
+
138
+ app = FastAPI()
139
+ setup_cors(app)
140
+ app.add_middleware(GZipMiddleware, minimum_size=1000)
141
+ api = create_api(app)
142
+
143
+ modules.script_callbacks.app_started_callback(None, app)
144
+
145
+ api.launch(server_name="0.0.0.0" if cmd_opts.listen else "127.0.0.1", port=cmd_opts.port if cmd_opts.port else 7861)
146
+
147
+
148
+ def webui():
149
+ launch_api = cmd_opts.api
150
+ initialize()
151
+
152
+ while 1:
153
+ demo = modules.ui.create_ui(wrap_gradio_gpu_call=wrap_gradio_gpu_call)
154
+
155
+ app, local_url, share_url = demo.launch(
156
+ share=cmd_opts.share,
157
+ server_name=server_name,
158
+ server_port=cmd_opts.port,
159
+ ssl_keyfile=cmd_opts.tls_keyfile,
160
+ ssl_certfile=cmd_opts.tls_certfile,
161
+ debug=cmd_opts.gradio_debug,
162
+ auth=[tuple(cred.split(':')) for cred in cmd_opts.gradio_auth.strip('"').split(',')] if cmd_opts.gradio_auth else None,
163
+ inbrowser=cmd_opts.autolaunch,
164
+ prevent_thread_lock=True
165
+ )
166
+ # after initial launch, disable --autolaunch for subsequent restarts
167
+ cmd_opts.autolaunch = False
168
+
169
+ # gradio uses a very open CORS policy via app.user_middleware, which makes it possible for
170
+ # an attacker to trick the user into opening a malicious HTML page, which makes a request to the
171
+ # running web ui and do whatever the attcker wants, including installing an extension and
172
+ # runnnig its code. We disable this here. Suggested by RyotaK.
173
+ app.user_middleware = [x for x in app.user_middleware if x.cls.__name__ != 'CORSMiddleware']
174
+
175
+ setup_cors(app)
176
+
177
+ app.add_middleware(GZipMiddleware, minimum_size=1000)
178
+
179
+ if launch_api:
180
+ create_api(app)
181
+
182
+ modules.script_callbacks.app_started_callback(demo, app)
183
+
184
+ wait_on_server(demo)
185
+
186
+ sd_samplers.set_samplers()
187
+
188
+ print('Reloading extensions')
189
+ extensions.list_extensions()
190
+
191
+ localization.list_localizations(cmd_opts.localizations_dir)
192
+
193
+ print('Reloading custom scripts')
194
+ modules.scripts.reload_scripts()
195
+ print('Reloading modules: modules.ui')
196
+ importlib.reload(modules.ui)
197
+ print('Refreshing Model List')
198
+ modules.sd_models.list_models()
199
+ print('Restarting Gradio')
200
+
201
+
202
+ if __name__ == "__main__":
203
+ if cmd_opts.nowebui:
204
+ api_only()
205
+ else:
206
+ webui()
webui.sh ADDED
@@ -0,0 +1,148 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ #################################################
3
+ # Please do not make any changes to this file, #
4
+ # change the variables in webui-user.sh instead #
5
+ #################################################
6
+ # Read variables from webui-user.sh
7
+ # shellcheck source=/dev/null
8
+ if [[ -f webui-user.sh ]]
9
+ then
10
+ source ./webui-user.sh
11
+ fi
12
+
13
+ # Set defaults
14
+ # Install directory without trailing slash
15
+ if [[ -z "${install_dir}" ]]
16
+ then
17
+ install_dir="/home/$(whoami)"
18
+ fi
19
+
20
+ # Name of the subdirectory (defaults to stable-diffusion-webui)
21
+ if [[ -z "${clone_dir}" ]]
22
+ then
23
+ clone_dir="stable-diffusion-webui"
24
+ fi
25
+
26
+ # python3 executable
27
+ if [[ -z "${python_cmd}" ]]
28
+ then
29
+ python_cmd="python3"
30
+ fi
31
+
32
+ # git executable
33
+ if [[ -z "${GIT}" ]]
34
+ then
35
+ export GIT="git"
36
+ fi
37
+
38
+ # python3 venv without trailing slash (defaults to ${install_dir}/${clone_dir}/venv)
39
+ if [[ -z "${venv_dir}" ]]
40
+ then
41
+ venv_dir="venv"
42
+ fi
43
+
44
+ if [[ -z "${LAUNCH_SCRIPT}" ]]
45
+ then
46
+ LAUNCH_SCRIPT="launch.py"
47
+ fi
48
+
49
+ # Disable sentry logging
50
+ export ERROR_REPORTING=FALSE
51
+
52
+ # Do not reinstall existing pip packages on Debian/Ubuntu
53
+ export PIP_IGNORE_INSTALLED=0
54
+
55
+ # Pretty print
56
+ delimiter="################################################################"
57
+
58
+ printf "\n%s\n" "${delimiter}"
59
+ printf "\e[1m\e[32mInstall script for stable-diffusion + Web UI\n"
60
+ printf "\e[1m\e[34mTested on Debian 11 (Bullseye)\e[0m"
61
+ printf "\n%s\n" "${delimiter}"
62
+
63
+ # Do not run as root
64
+ if [[ $(id -u) -eq 0 ]]
65
+ then
66
+ printf "\n%s\n" "${delimiter}"
67
+ printf "\e[1m\e[31mERROR: This script must not be launched as root, aborting...\e[0m"
68
+ printf "\n%s\n" "${delimiter}"
69
+ exit 1
70
+ else
71
+ printf "\n%s\n" "${delimiter}"
72
+ printf "Running on \e[1m\e[32m%s\e[0m user" "$(whoami)"
73
+ printf "\n%s\n" "${delimiter}"
74
+ fi
75
+
76
+ if [[ -d .git ]]
77
+ then
78
+ printf "\n%s\n" "${delimiter}"
79
+ printf "Repo already cloned, using it as install directory"
80
+ printf "\n%s\n" "${delimiter}"
81
+ install_dir="${PWD}/../"
82
+ clone_dir="${PWD##*/}"
83
+ fi
84
+
85
+ # Check prerequisites
86
+ for preq in "${GIT}" "${python_cmd}"
87
+ do
88
+ if ! hash "${preq}" &>/dev/null
89
+ then
90
+ printf "\n%s\n" "${delimiter}"
91
+ printf "\e[1m\e[31mERROR: %s is not installed, aborting...\e[0m" "${preq}"
92
+ printf "\n%s\n" "${delimiter}"
93
+ exit 1
94
+ fi
95
+ done
96
+
97
+ if ! "${python_cmd}" -c "import venv" &>/dev/null
98
+ then
99
+ printf "\n%s\n" "${delimiter}"
100
+ printf "\e[1m\e[31mERROR: python3-venv is not installed, aborting...\e[0m"
101
+ printf "\n%s\n" "${delimiter}"
102
+ exit 1
103
+ fi
104
+
105
+ cd "${install_dir}"/ || { printf "\e[1m\e[31mERROR: Can't cd to %s/, aborting...\e[0m" "${install_dir}"; exit 1; }
106
+ if [[ -d "${clone_dir}" ]]
107
+ then
108
+ cd "${clone_dir}"/ || { printf "\e[1m\e[31mERROR: Can't cd to %s/%s/, aborting...\e[0m" "${install_dir}" "${clone_dir}"; exit 1; }
109
+ else
110
+ printf "\n%s\n" "${delimiter}"
111
+ printf "Clone stable-diffusion-webui"
112
+ printf "\n%s\n" "${delimiter}"
113
+ "${GIT}" clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git "${clone_dir}"
114
+ cd "${clone_dir}"/ || { printf "\e[1m\e[31mERROR: Can't cd to %s/%s/, aborting...\e[0m" "${install_dir}" "${clone_dir}"; exit 1; }
115
+ fi
116
+
117
+ printf "\n%s\n" "${delimiter}"
118
+ printf "Create and activate python venv"
119
+ printf "\n%s\n" "${delimiter}"
120
+ cd "${install_dir}"/"${clone_dir}"/ || { printf "\e[1m\e[31mERROR: Can't cd to %s/%s/, aborting...\e[0m" "${install_dir}" "${clone_dir}"; exit 1; }
121
+ if [[ ! -d "${venv_dir}" ]]
122
+ then
123
+ "${python_cmd}" -m venv "${venv_dir}"
124
+ first_launch=1
125
+ fi
126
+ # shellcheck source=/dev/null
127
+ if [[ -f "${venv_dir}"/bin/activate ]]
128
+ then
129
+ source "${venv_dir}"/bin/activate
130
+ else
131
+ printf "\n%s\n" "${delimiter}"
132
+ printf "\e[1m\e[31mERROR: Cannot activate python venv, aborting...\e[0m"
133
+ printf "\n%s\n" "${delimiter}"
134
+ exit 1
135
+ fi
136
+
137
+ if [[ ! -z "${ACCELERATE}" ]] && [ ${ACCELERATE}="True" ] && [ -x "$(command -v accelerate)" ]
138
+ then
139
+ printf "\n%s\n" "${delimiter}"
140
+ printf "Accelerating launch.py..."
141
+ printf "\n%s\n" "${delimiter}"
142
+ accelerate launch --num_cpu_threads_per_process=6 "${LAUNCH_SCRIPT}" "$@"
143
+ else
144
+ printf "\n%s\n" "${delimiter}"
145
+ printf "Launching launch.py..."
146
+ printf "\n%s\n" "${delimiter}"
147
+ "${python_cmd}" "${LAUNCH_SCRIPT}" "$@"
148
+ fi