Skip to content

Commit cc7d75c

Browse files
author
tf-model-analysis-team
committed
Fixed supporting running TFMA UI outside of notebooks by loading vulcanized_tfma.js from the Webpack public path when defined.
PiperOrigin-RevId: 369895211
1 parent 5d941c8 commit cc7d75c

File tree

6 files changed

+213
-105
lines changed

6 files changed

+213
-105
lines changed

RELEASE.md

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
* metrics_plots_and_validations_writer was failing while writing cross
5555
slice comparison results to metrics file.
5656
* Fairness widget view was not compatible with cross slicing key type.
57+
* Fix support for exporting the UI from a notebook to a standalone HTML page.
5758
* Depends on `absl-py>=0.9,<0.13`.
5859
* Depends on `tensorflow-metadata>=0.29.0,<0.30.0`.
5960
* Depends on `tfx-bsl>=0.29.0,<0.30.0`.

tensorflow_model_analysis/notebook/jupyter/js/lib/labplugin.js

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ module.exports = {
2020
id: 'tensorflow_model_analysis',
2121
requires: [base.IJupyterWidgetRegistry],
2222
activate: function(app, widgets) {
23+
// Set a global variable to mark plugin as being run within Jupyter Lab.
24+
window['isJupyterLab'] = true;
2325
widgets.registerWidget({
2426
name: 'tensorflow_model_analysis',
2527
version: plugin.version,

tensorflow_model_analysis/notebook/jupyter/js/lib/widget.js

+17-3
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,23 @@ const version = require('../package.json').version;
2121
* Helper method to load the vulcanized templates.
2222
*/
2323
function loadVulcanizedTemplate() {
24-
const templateLocation =
25-
(document.querySelector('body').getAttribute('data-base-url') || '/') +
26-
'nbextensions/tensorflow_model_analysis/vulcanized_tfma.js';
24+
let templatePath;
25+
const dataBaseUrl =
26+
document.querySelector('body').getAttribute('data-base-url');
27+
// Jupyter Classic
28+
if (dataBaseUrl) {
29+
templatePath = dataBaseUrl + 'nbextensions/tensorflow_model_analysis/';
30+
}
31+
// Jupyter Lab
32+
else if (window['isJupyterLab']) {
33+
templatePath = '/nbextensions/tensorflow_model_analysis/';
34+
}
35+
// Kubeflow
36+
else {
37+
templatePath = __webpack_public_path__;
38+
}
39+
// templatePath ends with a slash.
40+
const templateLocation = `${templatePath}vulcanized_tfma.js`;
2741

2842
// If the vulcanizes tempalets are not loaded yet, load it now.
2943
if (!document.querySelector('script[src="' + templateLocation + '"]')) {

tensorflow_model_analysis/static/extension.js

+3-17
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,3 @@
1-
/**
2-
* Copyright 2018 Google LLC
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
7-
*
8-
* https://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
15-
*/
161
define(function() { return /******/ (function(modules) { // webpackBootstrap
172
/******/ // The module cache
183
/******/ var installedModules = {};
@@ -105,7 +90,8 @@ if (window.require) {
10590
window.require.config({
10691
map: {
10792
'*': {
108-
'tensorflow_model_analysis': 'nbextensions/tensorflow_model_analysis/index',
93+
'tensorflow_model_analysis':
94+
'nbextensions/tensorflow_model_analysis/index',
10995
}
11096
}
11197
});
@@ -118,4 +104,4 @@ module.exports = {
118104

119105

120106
/***/ })
121-
/******/ ])});;
107+
/******/ ])});;

0 commit comments

Comments
 (0)