Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update remaining dependent demos that define custom layouts to include default layouts so as to preserve existing behavior #1345

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions lit_nlp/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
3 changes: 2 additions & 1 deletion lit_nlp/examples/coref/coref_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
4 changes: 3 additions & 1 deletion lit_nlp/examples/custom_module/potato_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down Expand Up @@ -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()

Expand Down
5 changes: 3 additions & 2 deletions lit_nlp/examples/dalle/demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 2 additions & 0 deletions lit_nlp/examples/image_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion lit_nlp/examples/is_eval/is_eval_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
3 changes: 2 additions & 1 deletion lit_nlp/examples/lm_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion lit_nlp/examples/penguin_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading