Skip to content

Commit 42e4fe8

Browse files
committed
Revert "Revert "Merge pull request AUTOMATIC1111#9031 from AUTOMATIC1111/serve-css-as-files""
This reverts commit 4ca1dc5.
1 parent 34d2f51 commit 42e4fe8

File tree

1 file changed

+41
-33
lines changed

1 file changed

+41
-33
lines changed

modules/ui.py

Lines changed: 41 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,6 @@ def gr_show(visible=True):
7070
sample_img2img = "assets/stable-samples/img2img/sketch-mountains-input.jpg"
7171
sample_img2img = sample_img2img if os.path.exists(sample_img2img) else None
7272

73-
css_hide_progressbar = """
74-
.wrap .m-12 svg { display:none!important; }
75-
.wrap .m-12::before { content:"Loading..." }
76-
.wrap .z-20 svg { display:none!important; }
77-
.wrap .z-20::before { content:"Loading..." }
78-
.wrap.cover-bg .z-20::before { content:"" }
79-
.progress-bar { display:none!important; }
80-
.meta-text { display:none!important; }
81-
.meta-text-center { display:none!important; }
82-
"""
83-
8473
# Using constants for these since the variation selector isn't visible.
8574
# Important that they exactly match script.js for tooltip to work.
8675
random_symbol = '\U0001f3b2\ufe0f' # 🎲️
@@ -1566,22 +1555,6 @@ def request_restart():
15661555
(train_interface, "Train", "ti"),
15671556
]
15681557

1569-
css = ""
1570-
1571-
for cssfile in modules.scripts.list_files_with_name("style.css"):
1572-
if not os.path.isfile(cssfile):
1573-
continue
1574-
1575-
with open(cssfile, "r", encoding="utf8") as file:
1576-
css += file.read() + "\n"
1577-
1578-
if os.path.exists(os.path.join(data_path, "user.css")):
1579-
with open(os.path.join(data_path, "user.css"), "r", encoding="utf8") as file:
1580-
css += file.read() + "\n"
1581-
1582-
if not cmd_opts.no_progressbar_hiding:
1583-
css += css_hide_progressbar
1584-
15851558
interfaces += script_callbacks.ui_tabs_callback()
15861559
interfaces += [(settings_interface, "Settings", "settings")]
15871560

@@ -1592,7 +1565,7 @@ def request_restart():
15921565
for _interface, label, _ifid in interfaces:
15931566
shared.tab_names.append(label)
15941567

1595-
with gr.Blocks(css=css, analytics_enabled=False, title="Stable Diffusion") as demo:
1568+
with gr.Blocks(analytics_enabled=False, title="Stable Diffusion") as demo:
15961569
with gr.Row(elem_id="quicksettings", variant="compact"):
15971570
for i, k, item in sorted(quicksettings_list, key=lambda x: quicksettings_names.get(x[1], x[0])):
15981571
component = create_setting_component(k, is_quicksettings=True)
@@ -1777,25 +1750,60 @@ def check_dropdown(val):
17771750
return demo
17781751

17791752

1780-
def reload_javascript():
1753+
def webpath(fn):
1754+
if fn.startswith(script_path):
1755+
web_path = os.path.relpath(fn, script_path).replace('\\', '/')
1756+
else:
1757+
web_path = os.path.abspath(fn)
1758+
1759+
return f'file={web_path}?{os.path.getmtime(fn)}'
1760+
1761+
1762+
def javascript_html():
17811763
script_js = os.path.join(script_path, "script.js")
1782-
head = f'<script type="text/javascript" src="file={os.path.abspath(script_js)}?{os.path.getmtime(script_js)}"></script>\n'
1764+
head = f'<script type="text/javascript" src="{webpath(script_js)}"></script>\n'
17831765

17841766
inline = f"{localization.localization_js(shared.opts.localization)};"
17851767
if cmd_opts.theme is not None:
17861768
inline += f"set_theme('{cmd_opts.theme}');"
17871769

17881770
for script in modules.scripts.list_scripts("javascript", ".js"):
1789-
head += f'<script type="text/javascript" src="file={script.path}?{os.path.getmtime(script.path)}"></script>\n'
1771+
head += f'<script type="text/javascript" src="{webpath(script.path)}"></script>\n'
17901772

17911773
for script in modules.scripts.list_scripts("javascript", ".mjs"):
1792-
head += f'<script type="module" src="file={script.path}?{os.path.getmtime(script.path)}"></script>\n'
1774+
head += f'<script type="module" src="{webpath(script.path)}"></script>\n'
17931775

17941776
head += f'<script type="text/javascript">{inline}</script>\n'
17951777

1778+
return head
1779+
1780+
1781+
def css_html():
1782+
head = ""
1783+
1784+
def stylesheet(fn):
1785+
return f'<link rel="stylesheet" property="stylesheet" href="{webpath(fn)}">'
1786+
1787+
for cssfile in modules.scripts.list_files_with_name("style.css"):
1788+
if not os.path.isfile(cssfile):
1789+
continue
1790+
1791+
head += stylesheet(cssfile)
1792+
1793+
if os.path.exists(os.path.join(data_path, "user.css")):
1794+
head += stylesheet(os.path.join(data_path, "user.css"))
1795+
1796+
return head
1797+
1798+
1799+
def reload_javascript():
1800+
js = javascript_html()
1801+
css = css_html()
1802+
17961803
def template_response(*args, **kwargs):
17971804
res = shared.GradioTemplateResponseOriginal(*args, **kwargs)
1798-
res.body = res.body.replace(b'</head>', f'{head}</head>'.encode("utf8"))
1805+
res.body = res.body.replace(b'</head>', f'{js}</head>'.encode("utf8"))
1806+
res.body = res.body.replace(b'</body>', f'{css}</body>'.encode("utf8"))
17991807
res.init_headers()
18001808
return res
18011809

0 commit comments

Comments
 (0)