Skip to content

Commit

Permalink
Jupyter IFrame support (#1324)
Browse files Browse the repository at this point in the history
  • Loading branch information
lutzroeder committed Sep 10, 2024
1 parent c5868fe commit 04f3aa2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions source/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from .server import status
from .server import wait
from .server import serve
from .server import widget
from .server import __version__

def main():
Expand Down
17 changes: 16 additions & 1 deletion source/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ def wait():
_log(True, '\n')
stop()

def serve(file, data, address=None, browse=False, verbosity=1):
def serve(file, data=None, address=None, browse=False, verbosity=1):
'''Start serving model from file or data buffer at address and open in web browser.
Args:
Expand Down Expand Up @@ -324,3 +324,18 @@ def start(file=None, address=None, browse=True, verbosity=1):
A (host, port) address tuple.
'''
return serve(file, None, browse=browse, address=address, verbosity=verbosity)

def widget(address, height=800):
''' Open address as Jupyter Notebook IFrame.
Args:
address (tuple, optional): A (host, port) tuple, or a port number.
height (int, optional): Height of the IFrame, Default: 800
Returns:
A Jupyter Notebook IFrame.
'''
address = _make_address(address)
url = f"http://{address[0]}:{address[1]}"
IPython = __import__('IPython') # pylint: disable=invalid-name
return IPython.display.IFrame(url, width="100%", height=height)

0 comments on commit 04f3aa2

Please sign in to comment.