1- """%tensorboard line magic that patches TensorBoard's implementation to make use of Jupyter
1+ """%tensorboard line magic that patches TensorBoard's implementation to make use of Jupyter
22TensorBoard server extension providing built-in proxying.
33Use:
4- %load_ext tensorboard.notebook
4+ %load_ext tensorboard
55 %tensorboard --logdir /logs
66"""
77
88import argparse
99import uuid
1010
11- from IPython .display import display , HTML , Javascript
11+ from IPython .display import HTML , display
12+
1213
1314def _tensorboard_magic (line ):
1415 """Line magic function.
16+
1517 Makes an AJAX call to the Jupyter TensorBoard server extension and outputs
1618 an IFrame displaying the TensorBoard instance.
1719 """
1820 parser = argparse .ArgumentParser ()
19- parser .add_argument (' --logdir' , default = ' /workspace/environment/' )
21+ parser .add_argument (" --logdir" , default = " /workspace/" )
2022 args = parser .parse_args (line .split ())
21-
22- iframe_id = ' tensorboard-' + str (uuid .uuid4 ())
23-
23+
24+ iframe_id = " tensorboard-" + str (uuid .uuid4 ())
25+
2426 html = """
2527<!-- JUPYTER_TENSORBOARD_TEST_MARKER -->
2628<script>
@@ -42,23 +44,37 @@ def _tensorboard_magic(line):
4244 style="width: 100%%; height: 620px; display: none;"
4345 frameBorder="0">
4446</iframe>
45- """ % (args .logdir , iframe_id , iframe_id )
46-
47+ """ % (
48+ args .logdir ,
49+ iframe_id ,
50+ iframe_id ,
51+ )
52+
4753 display (HTML (html ))
48-
54+
55+
4956def load_ipython_extension (ipython ):
50- """IPython extension entry point."""
51- ipython .register_magic_function (
52- _tensorboard_magic ,
53- magic_kind = 'line' ,
54- magic_name = 'tensorboard' ,
57+ """Deprecated: use `%load_ext tensorboard` instead.
58+
59+ Raises:
60+ RuntimeError: Always.
61+ """
62+ raise RuntimeError (
63+ "Use '%load_ext tensorboard' instead of '%load_ext tensorboard.notebook'."
5564 )
5665
66+
5767def _load_ipython_extension (ipython ):
5868 """Load the TensorBoard notebook extension.
69+
5970 Intended to be called from `%load_ext tensorboard`. Do not invoke this
6071 directly.
72+
6173 Args:
6274 ipython: An `IPython.InteractiveShell` instance.
6375 """
64- load_ipython_extension (ipython )
76+ ipython .register_magic_function (
77+ _tensorboard_magic ,
78+ magic_kind = "line" ,
79+ magic_name = "tensorboard" ,
80+ )
0 commit comments