Line magic function. Makes an AJAX call to the Jupyter TensorBoard server extension and outputs an IFrame displaying the TensorBoard instance.
(line)
| 12 | from IPython.display import display, HTML, Javascript |
| 13 | |
| 14 | def _tensorboard_magic(line): |
| 15 | """Line magic function. |
| 16 | |
| 17 | Makes an AJAX call to the Jupyter TensorBoard server extension and outputs |
| 18 | an IFrame displaying the TensorBoard instance. |
| 19 | """ |
| 20 | parser = argparse.ArgumentParser() |
| 21 | parser.add_argument('--logdir', default='/kaggle/working') |
| 22 | args = parser.parse_args(line.split()) |
| 23 | |
| 24 | iframe_id = 'tensorboard-' + str(uuid.uuid4()) |
| 25 | |
| 26 | html = """ |
| 27 | <!-- JUPYTER_TENSORBOARD_TEST_MARKER --> |
| 28 | <script> |
| 29 | const req = { |
| 30 | method: 'POST', |
| 31 | contentType: 'application/json', |
| 32 | body: JSON.stringify({ 'logdir': '%s' }), |
| 33 | headers: { 'Content-Type': 'application/json' } |
| 34 | }; |
| 35 | |
| 36 | const baseUrl = Jupyter.notebook.base_url; |
| 37 | |
| 38 | fetch(baseUrl + 'api/tensorboard', req) |
| 39 | .then(res => res.json()) |
| 40 | .then(res => { |
| 41 | const iframe = document.getElementById('%s'); |
| 42 | iframe.src = baseUrl + 'tensorboard/' + res.name; |
| 43 | iframe.style.display = 'block'; |
| 44 | }); |
| 45 | </script> |
| 46 | |
| 47 | <iframe |
| 48 | id="%s" |
| 49 | style="width: 100%%; height: 620px; display: none;" |
| 50 | frameBorder="0"> |
| 51 | </iframe> |
| 52 | """ % (args.logdir, iframe_id, iframe_id) |
| 53 | |
| 54 | display(HTML(html)) |
| 55 | |
| 56 | def load_ipython_extension(ipython): |
| 57 | """IPython extension entry point.""" |
nothing calls this directly
no outgoing calls
no test coverage detected