Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Jupyter example #667

Merged
merged 2 commits into from
Mar 26, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions 11_notebooks/jupyter_inside_modal.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# ## Overview
#
# Quick snippet showing how to connect to a Jupyter notebook server running inside a Modal container,
# especially useful for exploring the contents of Modal network file systems.
# especially useful for exploring the contents of Modal Volumes.
# This uses [Modal Tunnels](https://modal.com/docs/guide/tunnels#tunnels-beta)
# to create a tunnel between the running Jupyter instance and the internet.
#
Expand All @@ -22,22 +22,21 @@
"jupyter", "bing-image-downloader~=1.1.2"
)
)
# This volume is not persisted, so the data will be deleted when this demo app is stopped.
volume = modal.NetworkFileSystem.ephemeral()
volume = modal.Volume.from_name(
"modal-examples-jupyter-inside-modal-data", create_if_missing=True
)

CACHE_DIR = "/root/cache"
JUPYTER_TOKEN = "1234" # Change me to something non-guessable!


@stub.function(
network_file_systems={CACHE_DIR: volume},
)
@stub.function(volumes={CACHE_DIR: volume})
def seed_volume():
# Bing it!
from bing_image_downloader import downloader

# This will save into the Modal volume and allow you view the images
# from within Jupyter at a path like `/cache/modal labs/Image_1.png`.
# from within Jupyter at a path like `/root/cache/modal labs/Image_1.png`.
downloader.download(
query="modal labs",
limit=10,
Expand All @@ -46,17 +45,16 @@ def seed_volume():
timeout=60,
verbose=True,
)
volume.commit()


# This is all that's needed to create a long-lived Jupyter server process in Modal
# that you can access in your Browser through a secure network tunnel.
# This can be useful when you want to interactively engage with network file system contents
# This can be useful when you want to interactively engage with Volume contents
# without having to download it to your host computer.


@stub.function(
concurrency_limit=1, network_file_systems={CACHE_DIR: volume}, timeout=1_500
)
@stub.function(concurrency_limit=1, volumes={CACHE_DIR: volume}, timeout=1_500)
def run_jupyter(timeout: int):
jupyter_port = 8888
with modal.forward(jupyter_port) as tunnel:
Expand Down
Loading