示例#1
0
    def render(self, blocking=False, debug=False):
        from IPython.display import IFrame, display
        from captum.insights.server import start_server

        port = start_server(self, blocking, debug)

        display(
            IFrame(src=f"http://127.0.0.1:{port}",
                   width="100%",
                   height="500px"))
示例#2
0
文件: api.py 项目: vfdev-5/captum
    def _serve_colab(self, blocking=False, debug=False, port=None):
        from IPython.display import display, HTML
        from captum.insights.server import start_server
        import ipywidgets as widgets

        # TODO: Output widget only captures beginning of server logs. It seems
        # the context manager isn't respected when the web server is run on a
        # separate thread. We should fix to display entirety of the logs
        out = widgets.Output()
        with out:
            port = start_server(self,
                                blocking=blocking,
                                debug=debug,
                                _port=port)
        shell = """
            <div id="root"></div>
            <script>
            (function() {
              document.querySelector("base").href = "http://localhost:%PORT%";
              function reloadScriptsAndCSS(root) {
                // Referencing TensorBoard's method for reloading scripts,
                // we remove and reinsert each script
                for (const script of root.querySelectorAll("script")) {
                  const newScript = document.createElement("script");
                  newScript.type = script.type;
                  if (script.src) {
                    newScript.src = script.src;
                  }
                  if (script.textContent) {
                    newScript.textContent = script.textContent;
                  }
                  root.appendChild(newScript);
                  script.remove();
                }
                // A similar method is used to reload styles
                for (const link of root.querySelectorAll("link")) {
                  const newLink = document.createElement("link");
                  newLink.rel = link.rel;
                  newLink.href = link.href;
                  document.querySelector("head").appendChild(newLink);
                  link.remove();
                }
              }
              const root = document.getElementById("root");
              fetch(".")
                .then(x => x.text())
                .then(html => void (root.innerHTML = html))
                .then(() => reloadScriptsAndCSS(root));
            })();
            </script>
        """.replace("%PORT%", str(port))
        html = HTML(shell)
        display(html)
        display(out)
示例#3
0
文件: api.py 项目: zhangkehua/captum
    def serve(self, blocking=False, debug=False, port=None):
        from captum.insights.server import start_server

        start_server(self, blocking=blocking, debug=debug, _port=port)