fix broken js

This commit is contained in:
Vladimir Mandic
2023-04-18 10:06:55 -04:00
parent 2711e32c2e
commit e8d8dae4c7
5 changed files with 22 additions and 28 deletions
+1
View File
@@ -95,3 +95,4 @@ Tech that can be integrated as part of the core workflow...
- force unload `xformers` when not used, improves compatibility with AMD/M1
- add `styles.csv` to UI settings to allow customizing path
- add `--disable-queue` to cmd flags that disables Gradio queues and forces it to use HTTP instead of WebSockets
- allow scripts & extensions to set loading priority, fixes `ScuNet`
+2 -2
View File
@@ -106,8 +106,8 @@ svg.feather.feather-image, .feather .feather-image { display: none }
/* custom elements overrides */
#steps-animation, #controlnet { border-width: 0; }
/* gradio built-in theme */
.dark {
/* based on gradio built-in dark theme */
:root {
--body-background-fill: black;
--body-text-color: var(--neutral-100);
--color-accent-soft: var(--neutral-700);
+1 -3
View File
@@ -71,9 +71,7 @@ class Extension:
if os.path.isfile(os.path.join(dirpath, "..", ".priority")):
with open(os.path.join(dirpath, "..", ".priority"), "r", encoding="utf-8") as f:
priority = str(f.read().strip())
_fn, ext = os.path.splitext(filename)
if ext == '.py':
res.append(scripts.ScriptFile(self.path, filename, os.path.join(dirpath, filename), priority))
res.append(scripts.ScriptFile(self.path, filename, os.path.join(dirpath, filename), priority))
res = [x for x in res if os.path.splitext(x.path)[1].lower() == extension and os.path.isfile(x.path)]
+1 -3
View File
@@ -196,9 +196,7 @@ def list_scripts(scriptdirname, extension):
with open(os.path.join(base, "..", ".priority"), "r", encoding="utf-8") as f:
priority = str(f.read().strip())
for filename in sorted(os.listdir(base)):
_fn, ext = os.path.splitext(filename)
if ext == '.py':
scripts_list.append(ScriptFile(paths.script_path, filename, os.path.join(base, filename), priority))
scripts_list.append(ScriptFile(paths.script_path, filename, os.path.join(base, filename), priority))
for ext in extensions.active():
scripts_list += ext.list_files(scriptdirname, extension)
+17 -20
View File
@@ -1689,55 +1689,52 @@ def webpath(fn):
return f'file={web_path}?{os.path.getmtime(fn)}'
def javascript_html():
def html_head():
script_js = os.path.join(script_path, "script.js")
head = f'<script type="text/javascript" src="{webpath(script_js)}"></script>\n'
for script in modules.scripts.list_scripts("javascript", ".js"):
head += f'<script type="text/javascript" src="{webpath(script.path)}"></script>\n'
for script in modules.scripts.list_scripts("javascript", ".mjs"):
head += f'<script type="module" src="{webpath(script.path)}"></script>\n'
return head
def html_body():
body = ''
# inline = f"{localization.localization_js(shared.opts.localization)};"
inline = ''
if cmd_opts.theme is not None:
inline += f"set_theme('{cmd_opts.theme}');"
elif opts.gradio_theme == 'black-orange':
inline += "set_theme('dark');"
for script in modules.scripts.list_scripts("javascript", ".js"):
head += f'<script type="text/javascript" src="{webpath(script.path)}"></script>\n'
for script in modules.scripts.list_scripts("javascript", ".mjs"):
head += f'<script type="module" src="{webpath(script.path)}"></script>\n'
head += f'<script type="text/javascript">{inline}</script>\n'
return head
body += f'<script type="text/javascript">{inline}</script>\n'
return body
def css_html():
def html_css():
head = ""
def stylesheet(fn):
return f'<link rel="stylesheet" property="stylesheet" href="{webpath(fn)}">'
for cssfile in modules.scripts.list_files_with_name("style.css"):
if not os.path.isfile(cssfile):
continue
head += stylesheet(cssfile)
if opts.gradio_theme == 'black-orange':
head += stylesheet(os.path.join(data_path, "javascript", "black-orange.css"))
if os.path.exists(os.path.join(data_path, "user.css")):
head += stylesheet(os.path.join(data_path, "user.css"))
return head
def reload_javascript():
js = javascript_html()
css = css_html()
head = html_head()
css = html_css()
body = html_body()
def template_response(*args, **kwargs):
res = shared.GradioTemplateResponseOriginal(*args, **kwargs)
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.body = res.body.replace(b'</head>', f'{head}</head>'.encode("utf8"))
res.body = res.body.replace(b'</body>', f'{css}{body}</body>'.encode("utf8"))
res.init_headers()
return res