Spaces:
No application file
No application file
yakubashsd
commited on
Commit
•
c78284a
1
Parent(s):
6393321
Upload oim__stable_diffusion_webui__.py
Browse files- oim__stable_diffusion_webui__.py +175 -0
oim__stable_diffusion_webui__.py
ADDED
@@ -0,0 +1,175 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# -*- coding: utf-8 -*-
|
2 |
+
"""Oim "Stable Diffusion WebUi "
|
3 |
+
|
4 |
+
Automatically generated by Colaboratory.
|
5 |
+
|
6 |
+
Original file is located at
|
7 |
+
https://colab.research.google.com/drive/1EiNg8Q0RbfxgNGZ70THUhKPNmGIfxhX7
|
8 |
+
|
9 |
+
# Welcome to Stable Diffusion WebUI 1.4! by [@altryne](https://twitter.com/altryne/) | [![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/N4N3DWMR1)
|
10 |
+
|
11 |
+
This colab runs the latest webui version from the repo https://github.com/hlky/stable-diffusion-webui
|
12 |
+
|
13 |
+
---
|
14 |
+
|
15 |
+
If this colab helped you, support me on ko-fi and don't forget to subscribe to my awesome list https://github.com/altryne/awesome-ai-art-image-synthesis
|
16 |
+
|
17 |
+
## 1 - Setup stage
|
18 |
+
"""
|
19 |
+
|
20 |
+
!nvidia-smi -L
|
21 |
+
|
22 |
+
"""### 1.1 Download repo and install
|
23 |
+
|
24 |
+
Clone git repo and setup miniconda
|
25 |
+
|
26 |
+
After runtime is executed, colab will complain that it crashed, but everything is fine, just hit run on the next cell or Runtime-> Run After
|
27 |
+
|
28 |
+
|
29 |
+
"""
|
30 |
+
|
31 |
+
# Commented out IPython magic to ensure Python compatibility.
|
32 |
+
#@markdown ## Download the stable-diffusion repo from hlky
|
33 |
+
#@markdown And install colab related conda
|
34 |
+
!git clone https://github.com/hlky/stable-diffusion
|
35 |
+
# %cd /content/stable-diffusion
|
36 |
+
!git checkout c0c2a7c0d55561cfb6f42a3681346b9b70749ff1
|
37 |
+
!pip install -e .
|
38 |
+
!pip install condacolab
|
39 |
+
import condacolab
|
40 |
+
condacolab.install_miniconda()
|
41 |
+
|
42 |
+
"""### 1.2 Environment setup
|
43 |
+
Setup envoroment, Gfpgan and Real-ESRGAN
|
44 |
+
Setup takes about 5-6 minutes
|
45 |
+
"""
|
46 |
+
|
47 |
+
#@markdown ### Set up conda environment - Takes a while
|
48 |
+
!conda env update -n base -f /content/stable-diffusion/environment.yaml
|
49 |
+
|
50 |
+
"""### 1.3 Setup Upscalers - CFPGan and ESRGAN"""
|
51 |
+
|
52 |
+
# Commented out IPython magic to ensure Python compatibility.
|
53 |
+
|
54 |
+
#@markdown ### Build upscalers support
|
55 |
+
#@markdown **GFPGAN** Automatically correct distorted faces with a built-in GFPGAN option, fixes them in less than half a second
|
56 |
+
#@markdown **ESRGAN** Boosts the resolution of images with a built-in RealESRGAN option
|
57 |
+
add_CFP = True #@param {type:"boolean"}
|
58 |
+
add_ESR = True #@param {type:"boolean"}
|
59 |
+
|
60 |
+
if add_CFP:
|
61 |
+
# %cd /content/stable-diffusion/src/gfpgan/
|
62 |
+
!pip install basicsr facexlib yapf lmdb opencv-python pyyaml tb-nightly --no-deps
|
63 |
+
!python setup.py develop
|
64 |
+
!pip install realesrgan
|
65 |
+
!wget https://github.com/TencentARC/GFPGAN/releases/download/v1.3.0/GFPGANv1.3.pth -P experiments/pretrained_models
|
66 |
+
if add_ESR:
|
67 |
+
# %cd /content/stable-diffusion/src/realesrgan/
|
68 |
+
!wget https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.0/RealESRGAN_x4plus.pth -P experiments/pretrained_models
|
69 |
+
!wget https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.2.4/RealESRGAN_x4plus_anime_6B.pth -P experiments/pretrained_models
|
70 |
+
|
71 |
+
# %cd /content/stable-diffusion/
|
72 |
+
!wget https://github.com/matomo-org/travis-scripts/blob/master/fonts/Arial.ttf?raw=true -O arial.ttf
|
73 |
+
|
74 |
+
#@markdown # Load the stable-diffusion model (requires Gdrive)
|
75 |
+
#@markdown If you don't already have it in your google drive, download the stable-diffusion model from [hugging face](https://huggingface.co/CompVis/stable-diffusion-v1-4)
|
76 |
+
|
77 |
+
#@markdown Then upload the file to your google drive (you'll be asked to connect it in the next step)
|
78 |
+
|
79 |
+
#@markdown **Model Path Variables**
|
80 |
+
# ask for the link
|
81 |
+
print("Local Path Variables:\n")
|
82 |
+
|
83 |
+
models_path = "/content/models" #@param {type:"string"}
|
84 |
+
output_path = "/content/output" #@param {type:"string"}
|
85 |
+
|
86 |
+
#@markdown **Google Drive Path Variables (Optional)**
|
87 |
+
mount_google_drive = True #@param {type:"boolean"}
|
88 |
+
force_remount = False
|
89 |
+
|
90 |
+
if mount_google_drive:
|
91 |
+
from google.colab import drive
|
92 |
+
try:
|
93 |
+
drive_path = "/content/drive"
|
94 |
+
drive.mount(drive_path,force_remount=force_remount)
|
95 |
+
models_path_gdrive = "/content/drive/MyDrive/AI/models" #@param {type:"string"}
|
96 |
+
output_path_gdrive = "/content/drive/MyDrive/AI/StableDiffusion" #@param {type:"string"}
|
97 |
+
models_path = models_path_gdrive
|
98 |
+
output_path = output_path_gdrive
|
99 |
+
except:
|
100 |
+
print("...error mounting drive or with drive path variables")
|
101 |
+
print("...reverting to default path variables")
|
102 |
+
|
103 |
+
import os
|
104 |
+
os.makedirs(models_path, exist_ok=True)
|
105 |
+
os.makedirs(output_path, exist_ok=True)
|
106 |
+
|
107 |
+
print(f"models_path: {models_path}")
|
108 |
+
print(f"output_path: {output_path}")
|
109 |
+
|
110 |
+
"""## 2 - Run the Stable Diffusion webui
|
111 |
+
|
112 |
+
### 2.1 Optional - Set webUI settings and configs before running
|
113 |
+
"""
|
114 |
+
|
115 |
+
#@markdown # Launch preferences - Advanced
|
116 |
+
share_password="oimetagi" #@param {type:"string"}
|
117 |
+
#@markdown * Add a password to your webui
|
118 |
+
defaults="configs/webui/webui.yaml" #@param {type:"string"}
|
119 |
+
#@markdown * path to configuration file providing UI defaults, uses same format as cli parameter)
|
120 |
+
#@markdown Edit this file if you want to change the default settings UI launches with
|
121 |
+
|
122 |
+
#@markdown ---
|
123 |
+
save_metadata = False #@param {type:"boolean"}
|
124 |
+
#@markdown * Whether to embed the generation parameters in the sample images
|
125 |
+
skip_grid = False #@param {type:"boolean"}
|
126 |
+
#@markdown * Do not save a grid, only individual samples. Helpful when evaluating lots of samples
|
127 |
+
skip_save = False #@param {type:"boolean"}
|
128 |
+
#@markdown * Do not save individual samples as files. For speed measurements
|
129 |
+
optimized = False #@param {type:"boolean"}
|
130 |
+
#@markdown * Load the model onto the device piecemeal instead of all at once to reduce VRAM usage at the cost of performance
|
131 |
+
optimized_turbo = True #@param {type:"boolean"}
|
132 |
+
#@markdown * Alternative optimization mode that does not save as much VRAM but runs siginificantly faster
|
133 |
+
no_verify_input = False #@param {type:"boolean"}
|
134 |
+
#@markdown * Do not verify input to check if it's too long
|
135 |
+
no_half = False #@param {type:"boolean"}
|
136 |
+
#@markdown * Do not switch the model to 16-bit floats
|
137 |
+
no_progressbar_hiding = True #@param {type:"boolean"}
|
138 |
+
#@markdown * Do not hide progressbar in gradio UI
|
139 |
+
extra_models_cpu = False #@param {type:"boolean"}
|
140 |
+
#@markdown * Run extra models (GFGPAN/ESRGAN) on cpu
|
141 |
+
esrgan_cpu = True #@param {type:"boolean"}
|
142 |
+
#@markdown * run ESRGAN on cpu
|
143 |
+
gfpgan_cpu = True #@param {type:"boolean"}
|
144 |
+
#@markdown * run GFPGAN on cpu
|
145 |
+
|
146 |
+
|
147 |
+
run_string_with_variables = {
|
148 |
+
'--save-metadata': f'{save_metadata}',
|
149 |
+
'--skip-grid': f'{skip_grid}',
|
150 |
+
'--skip-save': f'{skip_save}',
|
151 |
+
'--optimized': f'{optimized}',
|
152 |
+
'--optimized-turbo': f'{optimized_turbo}',
|
153 |
+
'--no-verify-input': f'{no_verify_input}',
|
154 |
+
'--no-half': f'{no_half}',
|
155 |
+
'--no-progressbar-hiding': f'{no_progressbar_hiding}',
|
156 |
+
'--extra-models-cpu': f'{extra_models_cpu}',
|
157 |
+
'--esrgan-cpu': f'{esrgan_cpu}',
|
158 |
+
'--gfpgan-cpu': f'{gfpgan_cpu}'}
|
159 |
+
|
160 |
+
only_true_vars = {k for (k,v) in run_string_with_variables.items() if v == 'True'}
|
161 |
+
vars = " ".join(only_true_vars)
|
162 |
+
|
163 |
+
"""## 3 - Launch WebUI for stable diffusion"""
|
164 |
+
|
165 |
+
# Commented out IPython magic to ensure Python compatibility.
|
166 |
+
#@markdown ** keep in mind that this script is set to run for ever, google will disconnect you after 90 minutes on free tiers
|
167 |
+
|
168 |
+
#@markdown # Important - click the public URL to launch WebUI in another tab
|
169 |
+
#@markdown ![](https://user-images.githubusercontent.com/463317/187105407-dd9b0f4e-c8da-49d3-8c78-1767f5c9aa83.jpg)
|
170 |
+
|
171 |
+
# %cd /content/stable-diffusion
|
172 |
+
!python /content/stable-diffusion/scripts/webui.py \
|
173 |
+
--ckpt '{models_path}/sd-v1-4.ckpt' \
|
174 |
+
--outdir '{output_path}' \
|
175 |
+
--share {vars}
|