Skip to content

Commit

Permalink
Use relative paths for Insights (#312)
Browse files Browse the repository at this point in the history
Summary:
This change allows Insights to work with [Jupyter server proxy](https://github.com/jupyterhub/jupyter-server-proxy).

However, Sagemaker is broken due to https://forums.aws.amazon.com/message.jspa?messageID=914445#914445.
Pull Request resolved: #312

Reviewed By: vivekmig

Differential Revision: D20252333

Pulled By: edward-io

fbshipit-source-id: f90cfd9dab46a479319774dbf6263d75e92a9be1
  • Loading branch information
edward-io authored and facebook-github-bot committed Mar 4, 2020
1 parent 37555ab commit 465dbaf
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 7 deletions.
6 changes: 3 additions & 3 deletions captum/insights/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,14 +256,14 @@ def render(self, debug=True):
def serve(self, blocking=False, debug=False, port=None):
context = _get_context()
if context == _CONTEXT_COLAB:
self._serve_colab(blocking=blocking, debug=debug, port=port)
return self._serve_colab(blocking=blocking, debug=debug, port=port)
else:
self._serve(blocking=blocking, debug=debug, port=port)
return self._serve(blocking=blocking, debug=debug, port=port)

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)
return start_server(self, blocking=blocking, debug=debug, _port=port)

def _serve_colab(self, blocking=False, debug=False, port=None):
from IPython.display import display, HTML
Expand Down
1 change: 1 addition & 0 deletions captum/insights/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "frontend",
"version": "0.2.0",
"private": true,
"homepage": ".",
"dependencies": {
"@babel/plugin-proposal-class-properties": "^7.5.5",
"babel-loader": "^8.0.6",
Expand Down
6 changes: 3 additions & 3 deletions captum/insights/frontend/src/WebApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ class WebApp extends React.Component {
}

_fetchInit = () => {
fetch("/init")
fetch("init")
.then(r => r.json())
.then(r => this.setState({ config: r }));
};

fetchData = filter_config => {
this.setState({ loading: true });
fetch("/fetch", {
fetch("fetch", {
method: "POST",
headers: {
"Content-Type": "application/json"
Expand All @@ -36,7 +36,7 @@ class WebApp extends React.Component {
};

onTargetClick = (labelIndex, instance, callback) => {
fetch("/attribute", {
fetch("attribute", {
method: "POST",
headers: {
"Content-Type": "application/json"
Expand Down
2 changes: 1 addition & 1 deletion captum/insights/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,12 @@ def start_server(
app.logger.disabled = True

port = _port or get_free_tcp_port()
print(f"\nFetch data and view Captum Insights at http://localhost:{port}/\n")
# Start in a new thread to not block notebook execution
t = threading.Thread(target=run_app, kwargs={"debug": debug})
t.start()
sleep(0.01) # add a short delay to allow server to start up
if blocking:
t.join()

print(f"\nFetch data and view Captum Insights at http://localhost:{port}/\n")
return port

0 comments on commit 465dbaf

Please sign in to comment.