aboutsummaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
Diffstat (limited to 'modules')
-rw-r--r--modules/localization.py4
-rw-r--r--modules/paths_internal.py5
-rw-r--r--modules/safe.py2
-rw-r--r--modules/shared.py9
-rw-r--r--modules/ui.py12
5 files changed, 21 insertions, 11 deletions
diff --git a/modules/localization.py b/modules/localization.py
index f6a6f2fb..ee9c65e7 100644
--- a/modules/localization.py
+++ b/modules/localization.py
@@ -23,7 +23,7 @@ def list_localizations(dirname):
localizations[fn] = file.path
-def localization_js(current_localization_name):
+def localization_js(current_localization_name: str) -> str:
fn = localizations.get(current_localization_name, None)
data = {}
if fn is not None:
@@ -34,4 +34,4 @@ def localization_js(current_localization_name):
print(f"Error loading localization from {fn}:", file=sys.stderr)
print(traceback.format_exc(), file=sys.stderr)
- return f"var localization = {json.dumps(data)}\n"
+ return f"window.localization = {json.dumps(data)}"
diff --git a/modules/paths_internal.py b/modules/paths_internal.py
index a23f6d70..005a9b0a 100644
--- a/modules/paths_internal.py
+++ b/modules/paths_internal.py
@@ -2,6 +2,11 @@
import argparse
import os
+import sys
+import shlex
+
+commandline_args = os.environ.get('COMMANDLINE_ARGS', "")
+sys.argv += shlex.split(commandline_args)
modules_path = os.path.dirname(os.path.realpath(__file__))
script_path = os.path.dirname(modules_path)
diff --git a/modules/safe.py b/modules/safe.py
index 1e791c5b..e8f50774 100644
--- a/modules/safe.py
+++ b/modules/safe.py
@@ -40,7 +40,7 @@ class RestrictedUnpickler(pickle.Unpickler):
return getattr(collections, name)
if module == 'torch._utils' and name in ['_rebuild_tensor_v2', '_rebuild_parameter', '_rebuild_device_tensor_from_numpy']:
return getattr(torch._utils, name)
- if module == 'torch' and name in ['FloatStorage', 'HalfStorage', 'IntStorage', 'LongStorage', 'DoubleStorage', 'ByteStorage', 'float32']:
+ if module == 'torch' and name in ['FloatStorage', 'HalfStorage', 'IntStorage', 'LongStorage', 'DoubleStorage', 'ByteStorage', 'float32', 'BFloat16Storage']:
return getattr(torch, name)
if module == 'torch.nn.modules.container' and name in ['ParameterDict']:
return getattr(torch.nn.modules.container, name)
diff --git a/modules/shared.py b/modules/shared.py
index 1df1dd45..96a20a6b 100644
--- a/modules/shared.py
+++ b/modules/shared.py
@@ -665,14 +665,19 @@ def reload_gradio_theme(theme_name=None):
if not theme_name:
theme_name = opts.gradio_theme
+ default_theme_args = dict(
+ font=["Source Sans Pro", 'ui-sans-serif', 'system-ui', 'sans-serif'],
+ font_mono=['IBM Plex Mono', 'ui-monospace', 'Consolas', 'monospace'],
+ )
+
if theme_name == "Default":
- gradio_theme = gr.themes.Default()
+ gradio_theme = gr.themes.Default(**default_theme_args)
else:
try:
gradio_theme = gr.themes.ThemeClass.from_hub(theme_name)
except Exception as e:
errors.display(e, "changing gradio theme")
- gradio_theme = gr.themes.Default()
+ gradio_theme = gr.themes.Default(**default_theme_args)
diff --git a/modules/ui.py b/modules/ui.py
index ff82fff6..ff25c4ce 100644
--- a/modules/ui.py
+++ b/modules/ui.py
@@ -1771,12 +1771,11 @@ def webpath(fn):
def javascript_html():
- script_js = os.path.join(script_path, "script.js")
- head = f'<script type="text/javascript" src="{webpath(script_js)}"></script>\n'
+ # Ensure localization is in `window` before scripts
+ head = f'<script type="text/javascript">{localization.localization_js(shared.opts.localization)}</script>\n'
- inline = f"{localization.localization_js(shared.opts.localization)};"
- if cmd_opts.theme is not None:
- inline += f"set_theme('{cmd_opts.theme}');"
+ 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'
@@ -1784,7 +1783,8 @@ def javascript_html():
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'
+ if cmd_opts.theme:
+ head += f'<script type="text/javascript">set_theme(\"{cmd_opts.theme}\");</script>\n'
return head