From c9d4dde5561f8cc118b8c456057fb4e9900d389d Mon Sep 17 00:00:00 2001 From: James Wexler Date: Tue, 7 Nov 2023 11:28:31 -0800 Subject: [PATCH 1/3] Fix LIT rendering in colab PiperOrigin-RevId: 580246237 --- lit_nlp/notebook.py | 43 +++++-------------------------------------- 1 file changed, 5 insertions(+), 38 deletions(-) diff --git a/lit_nlp/notebook.py b/lit_nlp/notebook.py index 57610e70..87a051cd 100644 --- a/lit_nlp/notebook.py +++ b/lit_nlp/notebook.py @@ -22,15 +22,16 @@ from lit_nlp.api import layout from lit_nlp.lib import wsgi_serving +is_colab = False try: import google.colab # pylint: disable=g-import-not-at-top,unused-import + from google.colab import output # pylint: disable=g-import-not-at-top,unused-import # pytype: disable=import-error is_colab = True # Can disable import error as this package is always # included in colab kernels. from colabtools import interactive_widgets # pylint: disable=g-import-not-at-top # pytype: disable=import-error progress_indicator = interactive_widgets.ProgressIter except (ImportError, ModuleNotFoundError): - is_colab = False from tqdm import notebook # pylint: disable=g-import-not-at-top progress_indicator = notebook.tqdm @@ -167,46 +168,12 @@ def _display_colab(port, height, open_in_new_tab, ui_params: RenderConfig): """ params = ui_params.get_query_str() + path = f'/{params}' if open_in_new_tab: - shell = """ - (async () => { - const proxyPort = await google.colab.kernel.proxyPort( - %PORT%, {'cache': true}) - const url = new URL(proxyPort + '%PARAMS%') - const a = document.createElement('a'); - a.href = "javascript:void(0);" - a.onclick = (e) => window.open(url, "_blank"); - a.innerHTML = url; - document.body.appendChild(a); - window.open(url, "_blank"); - })(); - """ + output.serve_kernel_port_as_window(port, path=path) else: - shell = """ - (async () => { - const proxyPort = await google.colab.kernel.proxyPort( - %PORT%, {'cache': true}) - const url = new URL(proxyPort + '%PARAMS%') - const iframe = document.createElement('iframe'); - iframe.src = url; - iframe.setAttribute('width', '100%'); - iframe.setAttribute('height', '%HEIGHT%px'); - iframe.setAttribute('frameborder', 0); - document.body.appendChild(iframe); - })(); - """ - - replacements = [ - ('%PORT%', '%d' % port), - ('%HEIGHT%', '%d' % height), - ('%PARAMS%', '%s' % params), - ] - for (k, v) in replacements: - shell = shell.replace(k, v) - - script = display.Javascript(shell) - display.display(script) + output.serve_kernel_port_as_iframe(port, height=f'{height}', path=path) def _display_jupyter( From b421a61dcab8ed15330fd4858dd1008b184cab28 Mon Sep 17 00:00:00 2001 From: James Wexler Date: Wed, 8 Nov 2023 08:55:40 -0500 Subject: [PATCH 2/3] update version --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 3c8bb401..736bf9f5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "lit-nlp" -version = "1.0.1" +version = "1.0.2" authors = [ { name="Google, LLC", email="lit-dev@google.com" } ] From 18e71ce246a09e13694583e401dd897ccb98e0ae Mon Sep 17 00:00:00 2001 From: James Wexler Date: Wed, 8 Nov 2023 10:19:54 -0500 Subject: [PATCH 3/3] updating jax version --- requirements_examples.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements_examples.txt b/requirements_examples.txt index 87d542b2..e078388b 100644 --- a/requirements_examples.txt +++ b/requirements_examples.txt @@ -18,7 +18,7 @@ sentencepiece==0.1.99 tensorflow-datasets==4.8.0 torch==2.0.1 transformers==4.27.1 -jax==0.3.16 -jaxlib==0.3.15 +jax==0.4.1 +jaxlib==0.4.1 flax==0.5.3 # LINT.ThenChange(./pyproject.toml)