generated from Start9Labs/hello-world-startos
-
Notifications
You must be signed in to change notification settings - Fork 3
/
webui.patch
297 lines (273 loc) · 11.4 KB
/
webui.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
From 873be88f960bcfd60803235dbc0fd0f3af09aa9f Mon Sep 17 00:00:00 2001
From: Sam Sartor <[email protected]>
Date: Thu, 22 Feb 2024 14:43:51 -0500
Subject: [PATCH] patches for startos
---
.../sdxl-turbo-ux/scripts/sdxl_turbo_ux.py | 95 +++++++++++++++++++
javascript/ui.js | 1 +
modules/script_callbacks.py | 15 +++
modules/sd_hijack.py | 7 ++
modules/shared_options.py | 2 +-
modules/ui.py | 5 +-
modules/ui_gradio_extensions.py | 2 +
style.css | 13 ++-
webui.py | 1 +
9 files changed, 137 insertions(+), 4 deletions(-)
create mode 100644 extensions-builtin/sdxl-turbo-ux/scripts/sdxl_turbo_ux.py
diff --git a/extensions-builtin/sdxl-turbo-ux/scripts/sdxl_turbo_ux.py b/extensions-builtin/sdxl-turbo-ux/scripts/sdxl_turbo_ux.py
new file mode 100644
index 00000000..2183317f
--- /dev/null
+++ b/extensions-builtin/sdxl-turbo-ux/scripts/sdxl_turbo_ux.py
@@ -0,0 +1,95 @@
+import gradio as gr
+from modules import scripts, shared, script_callbacks
+from typing import Any
+
+TUBO_SETTINGS = {
+ ('sd_xl_turbo_1.0', 'sampling'): 'Euler a',
+ ('sd_xl_turbo_1.0', 'cfg_scale'): 1,
+ ('sd_xl_turbo_1.0', 'steps'): [1, 2, 4],
+ ('dreamshaperXL_v21TurboDPMSDE', 'sampling'): 'DPM++ SDE Karras',
+ ('dreamshaperXL_v21TurboDPMSDE', 'cfg_scale'): 2,
+ ('dreamshaperXL_v21TurboDPMSDE', 'steps'): [4, 4, 8],
+}
+
+class Script(scripts.Script):
+ def __init__(self):
+ self.name = 'sdxl_turbo_ux'
+ #self.setup_for_ui_only = True
+
+ self.checkpoint_ui_component: Any = None
+ self.ui_components: dict[str, Any] = { k: None for (_, k) in TUBO_SETTINGS.keys() }
+
+ script_callbacks.on_after_ui_settings(self.setup_checkpoint_changed)
+
+ def title(self):
+ return "SDXL Turbo UX"
+
+ def show(self, is_img2img):
+ return scripts.AlwaysVisible
+
+ def ui(self, is_img2img):
+ pass
+
+ def after_component(self, component, **kwargs):
+ if component.elem_id is None:
+ return
+
+ id = component.elem_id.removeprefix('img2img_' if self.is_img2img else 'txt2img_')
+ if id in self.ui_components:
+ self.ui_components[id] = component
+
+ def setup_checkpoint_changed(self, params: script_callbacks.AfterUiSettingsParams):
+ self.checkpoint_ui_component = shared.settings_components['sd_model_checkpoint']
+ components = list(self.ui_components.values())
+ self.checkpoint_ui_component.change(
+ fn=self.checkpoint_changed,
+ inputs=[self.checkpoint_ui_component, *components],
+ outputs=components,
+ show_progress='hidden',
+ )
+ params.block.load(
+ fn=self.checkpoint_changed,
+ inputs=[self.checkpoint_ui_component, *components],
+ outputs=components,
+ show_progress='hidden',
+ )
+
+ def checkpoint_changed(self, title, *values):
+ values = dict(zip(self.ui_components.keys(), values))
+ specs = {k: v for ((ckpt, k), v) in TUBO_SETTINGS.items() if ckpt in title}
+
+ for (key, original) in self.ui_components.items():
+ spec = specs.get(key)
+ if isinstance(original, gr.Slider):
+ if spec is None:
+ values[key] = gr.update(
+ minimum=original.minimum,
+ maximum=original.maximum,
+ value=original.value,
+ interactive=True,
+ )
+ elif isinstance(spec, list):
+ values[key] = gr.update(
+ minimum=spec[0],
+ maximum=spec[2],
+ value=spec[1],
+ interactive=False,
+ )
+ else:
+ values[key] = gr.update(
+ value=spec,
+ interactive=False,
+ )
+ else:
+ if spec is None:
+ values[key] = gr.update(
+ value=original.value,
+ interactive=True,
+ )
+ else:
+ values[key] = gr.update(
+ value=spec,
+ interactive=False,
+ )
+
+ return list(values.values())
diff --git a/javascript/ui.js b/javascript/ui.js
index 3d079b3d..e4e74f75 100644
--- a/javascript/ui.js
+++ b/javascript/ui.js
@@ -259,6 +259,7 @@ onUiLoaded(function() {
showRestoreProgressButton('img2img', localGet("img2img_task_id"));
setupResolutionPasting('txt2img');
setupResolutionPasting('img2img');
+ gradioApp().getElementById(tabname + "_restore_progress").click();
});
diff --git a/modules/script_callbacks.py b/modules/script_callbacks.py
index 08bc5256..2f4f5369 100644
--- a/modules/script_callbacks.py
+++ b/modules/script_callbacks.py
@@ -106,6 +106,10 @@ class ImageGridLoopParams:
self.cols = cols
self.rows = rows
+class AfterUiSettingsParams:
+ def __init__(self, block):
+ self.block = block
+
@dataclasses.dataclass
class BeforeTokenCounterParams:
@@ -123,6 +127,7 @@ callback_map = dict(
callbacks_ui_tabs=[],
callbacks_ui_train_tabs=[],
callbacks_ui_settings=[],
+ callbacks_after_ui_settings=[],
callbacks_before_image_saved=[],
callbacks_image_saved=[],
callbacks_extra_noise=[],
@@ -199,6 +204,12 @@ def ui_settings_callback():
except Exception:
report_exception(c, 'ui_settings_callback')
+def after_ui_settings_callback(params: AfterUiSettingsParams):
+ for c in callback_map['callbacks_after_ui_settings']:
+ try:
+ c.callback(params)
+ except Exception:
+ report_exception(c, 'after_ui_settings_callback')
def before_image_saved_callback(params: ImageSaveParams):
for c in callback_map['callbacks_before_image_saved']:
@@ -393,6 +404,10 @@ def on_ui_settings(callback):
by using shared.opts.add_option(shared.OptionInfo(...)) """
add_callback(callback_map['callbacks_ui_settings'], callback)
+def on_after_ui_settings(callback):
+ """register a function to be called after all UI settings components are created
+ """
+ add_callback(callback_map['callbacks_after_ui_settings'], callback)
def on_before_image_saved(callback):
"""register a function to be called before an image is saved to a file.
diff --git a/modules/sd_hijack.py b/modules/sd_hijack.py
index e139d996..98661b6e 100644
--- a/modules/sd_hijack.py
+++ b/modules/sd_hijack.py
@@ -271,6 +271,13 @@ class StableDiffusionModelHijack:
else:
sd_unet.original_forward = None
+ if cmd_opts.use_ipex and devices.xpu_specific.has_ipex:
+ print('applying ipex optimization')
+ m.model.diffusion_model.eval()
+ devices.xpu_specific.ipex.optimize(m.model.diffusion_model, weights_prepack=False)
+ else:
+ print('skipping ipex optimization')
+
def undo_hijack(self, m):
conditioner = getattr(m, 'conditioner', None)
diff --git a/modules/shared_options.py b/modules/shared_options.py
index e1d11c8e..fe79a233 100644
--- a/modules/shared_options.py
+++ b/modules/shared_options.py
@@ -81,7 +81,7 @@ options_templates.update(options_section(('saving-paths', "Paths for saving", "s
"outdir_grids": OptionInfo("", "Output directory for grids; if empty, defaults to two directories below", component_args=hide_dirs),
"outdir_txt2img_grids": OptionInfo(util.truncate_path(os.path.join(default_output_dir, 'txt2img-grids')), 'Output directory for txt2img grids', component_args=hide_dirs),
"outdir_img2img_grids": OptionInfo(util.truncate_path(os.path.join(default_output_dir, 'img2img-grids')), 'Output directory for img2img grids', component_args=hide_dirs),
- "outdir_save": OptionInfo(util.truncate_path(os.path.join(data_path, 'log', 'images')), "Directory for saving images using the Save button", component_args=hide_dirs),
+ "outdir_save": OptionInfo(util.truncate_path(os.path.join(data_path, 'saved')), "Directory for saving images using the Save button", component_args=hide_dirs),
"outdir_init_images": OptionInfo(util.truncate_path(os.path.join(default_output_dir, 'init-images')), "Directory for saving init images when using img2img", component_args=hide_dirs),
}))
diff --git a/modules/ui.py b/modules/ui.py
index dcba8e88..e5799adc 100644
--- a/modules/ui.py
+++ b/modules/ui.py
@@ -1124,8 +1124,8 @@ def create_ui():
(img2img_interface, "img2img", "img2img"),
(extras_interface, "Extras", "extras"),
(pnginfo_interface, "PNG Info", "pnginfo"),
- (modelmerger_ui.blocks, "Checkpoint Merger", "modelmerger"),
- (train_interface, "Train", "train"),
+ #(modelmerger_ui.blocks, "Checkpoint Merger", "modelmerger"),
+ #(train_interface, "Train", "train"),
]
interfaces += script_callbacks.ui_tabs_callback()
@@ -1142,6 +1142,7 @@ def create_ui():
settings.add_quicksettings()
parameters_copypaste.connect_paste_params_buttons()
+ script_callbacks.after_ui_settings_callback(script_callbacks.AfterUiSettingsParams(demo))
with gr.Tabs(elem_id="tabs") as tabs:
tab_order = {k: i for i, k in enumerate(opts.ui_tab_order)}
diff --git a/modules/ui_gradio_extensions.py b/modules/ui_gradio_extensions.py
index f5278d22..5070bdb1 100644
--- a/modules/ui_gradio_extensions.py
+++ b/modules/ui_gradio_extensions.py
@@ -1,5 +1,6 @@
import os
import gradio as gr
+import re
from modules import localization, shared, scripts, util
from modules.paths import script_path, data_path
@@ -50,6 +51,7 @@ def reload_javascript():
def template_response(*args, **kwargs):
res = shared.GradioTemplateResponseOriginal(*args, **kwargs)
+ res.body = re.sub(b'<script\\s[^>]*src="https:\\/\\/[^"]+"[^>]*>\\s*<\\/script>', b'', res.body)
res.body = res.body.replace(b'</head>', f'{js}</head>'.encode("utf8"))
res.body = res.body.replace(b'</body>', f'{css}</body>'.encode("utf8"))
res.init_headers()
diff --git a/style.css b/style.css
index 8ce78ff0..61eb3601 100644
--- a/style.css
+++ b/style.css
@@ -9,6 +9,17 @@ div.gradio-image button[aria-label="Edit"] {
display: none;
}
+/*
+ Hack to prevent width/height-batch-size from showing.
+ Because those are footguns on start9's pure server.
+ */
+#txt2img_column_size,
+#txt2img_dimensions_row,
+#img2img_column_size,
+#txt2img_batch_size,
+#img2img_batch_size {
+ display: none;
+}
/* general gradio fixes */
@@ -1348,7 +1359,7 @@ body.resizing .resize-handle {
flex-basis: 100%;
}
/* Buttons for directories. */
-.extra-network-tree .tree-list-content-dir {}
+.extra-network-tree .tree-list-content-dir {}
/* Buttons for files. */
.extra-network-tree .tree-list-item--has-subitem .tree-list--subgroup > li:first-child {
diff --git a/webui.py b/webui.py
index 2c417168..2d9ac5a2 100644
--- a/webui.py
+++ b/webui.py
@@ -93,6 +93,7 @@ def webui():
"redoc_url": "/redoc",
},
root_path=f"/{cmd_opts.subpath}" if cmd_opts.subpath else "",
+ favicon_path="icon.png",
)
startup_timer.record("gradio launch")
--
2.42.0