diff --git a/lit_nlp/app.py b/lit_nlp/app.py index 2ce66896..a83eabb7 100644 --- a/lit_nlp/app.py +++ b/lit_nlp/app.py @@ -899,11 +899,7 @@ def __init__( id_hash_fn=caching.input_hash, ) - # TODO(lit-dev): override layouts instead of merging, to allow clients - # to opt-out of the default bundled layouts. This will require updating - # client code to manually merge when this is the desired behavior. - self._layouts = dict(layout.DEFAULT_LAYOUTS, **(layouts or {})) - + self._layouts = layouts if layouts else layout.DEFAULT_LAYOUTS self._model_loaders: ModelLoadersMap = model_loaders or {} self._models: dict[str, caching.CachingModelWrapper] = {} for name, model in models.items(): diff --git a/lit_nlp/examples/coref/coref_demo.py b/lit_nlp/examples/coref/coref_demo.py index cb395b17..95ff9549 100644 --- a/lit_nlp/examples/coref/coref_demo.py +++ b/lit_nlp/examples/coref/coref_demo.py @@ -123,7 +123,8 @@ }, description="Custom layout for the Winogender coreference demo.", ) -CUSTOM_LAYOUTS = {"winogender": WINOGENDER_LAYOUT} + +CUSTOM_LAYOUTS = layout.DEFAULT_LAYOUTS | {"winogender": WINOGENDER_LAYOUT} FLAGS.set_default("default_layout", "winogender") diff --git a/lit_nlp/examples/custom_module/potato_demo.py b/lit_nlp/examples/custom_module/potato_demo.py index 25c6b17a..de580f54 100644 --- a/lit_nlp/examples/custom_module/potato_demo.py +++ b/lit_nlp/examples/custom_module/potato_demo.py @@ -57,6 +57,8 @@ description="Custom layout with our spud-tastic potato module.", ) +CUSTOM_LAYOUTS = layout.DEFAULT_LAYOUTS | {"potato": POTATO_LAYOUT} + def get_wsgi_app() -> Optional[dev_server.LitServerType]: """Returns a LitApp instance for consumption by gunicorn.""" @@ -88,7 +90,7 @@ def main(argv: Sequence[str]) -> Optional[dev_server.LitServerType]: lit_demo = dev_server.Server( models, datasets, - layouts={"potato": POTATO_LAYOUT}, + layouts=CUSTOM_LAYOUTS, **server_flags.get_flags()) return lit_demo.serve() diff --git a/lit_nlp/examples/dalle/demo.py b/lit_nlp/examples/dalle/demo.py index 1a466d4b..ea049178 100644 --- a/lit_nlp/examples/dalle/demo.py +++ b/lit_nlp/examples/dalle/demo.py @@ -58,7 +58,8 @@ }, description="Custom layout for Text to Image models.", ) -_CUSTOM_LAYOUTS = {"DALLE_LAYOUT": _DALLE_LAYOUT} + +CUSTOM_LAYOUTS = layout.DEFAULT_LAYOUTS | {"DALLE_LAYOUT": _DALLE_LAYOUT} def get_wsgi_app() -> Optional[dev_server.LitServerType]: @@ -92,7 +93,7 @@ def main(argv: Sequence[str]) -> Optional[dev_server.LitServerType]: lit_demo = dev_server.Server( models, datasets, - layouts=_CUSTOM_LAYOUTS, + layouts=CUSTOM_LAYOUTS, **server_flags.get_flags(), ) return lit_demo.serve() diff --git a/lit_nlp/examples/image_demo.py b/lit_nlp/examples/image_demo.py index 459ef6d6..5d9d25a4 100644 --- a/lit_nlp/examples/image_demo.py +++ b/lit_nlp/examples/image_demo.py @@ -66,6 +66,8 @@ def get_wsgi_app(): description='Basic layout for image demo', ) +CUSTOM_LAYOUTS = layout.DEFAULT_LAYOUTS | {'default': DEMO_LAYOUT} + def main(argv: Sequence[str]) -> Optional[dev_server.LitServerType]: if len(argv) > 1: diff --git a/lit_nlp/examples/is_eval/is_eval_demo.py b/lit_nlp/examples/is_eval/is_eval_demo.py index b75abe65..0621adef 100644 --- a/lit_nlp/examples/is_eval/is_eval_demo.py +++ b/lit_nlp/examples/is_eval/is_eval_demo.py @@ -91,7 +91,7 @@ ], }, description="Custom layout for evaluating input salience methods.") -CUSTOM_LAYOUTS = {"is_eval": IS_EVAL_LAYOUT} +CUSTOM_LAYOUTS = layout.DEFAULT_LAYOUTS | {"is_eval": IS_EVAL_LAYOUT} # You can change this back via URL param, e.g. localhost:5432/?layout=default FLAGS.set_default("default_layout", "is_eval") diff --git a/lit_nlp/examples/lm_demo.py b/lit_nlp/examples/lm_demo.py index b1cef5ab..928f423b 100644 --- a/lit_nlp/examples/lm_demo.py +++ b/lit_nlp/examples/lm_demo.py @@ -86,7 +86,8 @@ }, description="Custom layout for language models.", ) -CUSTOM_LAYOUTS = {"lm": LM_LAYOUT} + +CUSTOM_LAYOUTS = dict(layout.DEFAULT_LAYOUTS, **{"lm": LM_LAYOUT}) # You can also change this via URL param e.g. localhost:5432/?layout=default FLAGS.set_default("default_layout", "lm") diff --git a/lit_nlp/examples/penguin_demo.py b/lit_nlp/examples/penguin_demo.py index 109f9ea9..79cc077c 100644 --- a/lit_nlp/examples/penguin_demo.py +++ b/lit_nlp/examples/penguin_demo.py @@ -49,7 +49,7 @@ lower=layout.STANDARD_LAYOUT.lower, description='Custom layout for the Palmer Penguins demo.', ) -CUSTOM_LAYOUTS = {'penguins': PENGUIN_LAYOUT} +CUSTOM_LAYOUTS = layout.DEFAULT_LAYOUTS | {'penguins': PENGUIN_LAYOUT} # Function for running demo through gunicorn instead of the local dev server.