Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
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
1,064 changes: 1,064 additions & 0 deletions docs/colab_notebooks/7-nemotron-personas.ipynb

Large diffs are not rendered by default.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
402 changes: 402 additions & 0 deletions docs/devnotes/posts/nemotron-personas.md

Large diffs are not rendered by default.

732 changes: 732 additions & 0 deletions docs/notebook_source/7-nemotron-personas.py

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/notebook_source/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ In this folder you can find all our tutorial notebooks in `.py` format. They can
make convert-execute-notebooks
```

from the root of the repository. This will not only convert but also execute all of the notebooks -- for that to work, make sure you went through our [Quick Start](https://nvidia-nemo.github.io/DataDesigner/quick-start/) and have API keys set. A new folder `docs/notebooks` will be created, including `README.md` and `pyproject.toml` files.
from the root of the repository. This will not only convert but also execute all of the notebooks -- for that to work, make sure you went through our [Quick Start](https://nvidia-nemo.github.io/DataDesigner/latest/quick-start/) and have API keys set. A new folder `docs/notebooks` will be created, including `README.md` and `pyproject.toml` files.

Alternatively, you can use Jupytext directly

Expand Down
42 changes: 39 additions & 3 deletions docs/scripts/generate_colab_notebooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,30 @@ def mark_colab_injected(cell: NotebookNode) -> NotebookNode:
return cell


def create_colab_setup_cells(additional_dependencies: str) -> list[NotebookNode]:
# Per-file try/except snippets appended into the standard NVIDIA_API_KEY cell
# so additional API keys share the same imports rather than producing a
# duplicate-imports cell. The snippets are joined with blank lines.
NGC_API_KEY_BLOCK = """\
try:
Comment thread
3mei marked this conversation as resolved.
os.environ["NGC_API_KEY"] = userdata.get("NGC_API_KEY")
except userdata.SecretNotFoundError:
os.environ["NGC_API_KEY"] = getpass.getpass("Enter your NGC API key: ")"""

# Optional per-file Colab setup cells, injected immediately after the standard
# install + NVIDIA_API_KEY cells. Currently unused; left in place so future
# tutorials can register additional one-shot Colab bootstrap cells.
ADDITIONAL_SETUP_CELLS: dict[str, list[str]] = {}

ADDITIONAL_API_KEY_BLOCKS: dict[str, list[str]] = {
"7-nemotron-personas.py": [NGC_API_KEY_BLOCK],
}


def create_colab_setup_cells(
additional_dependencies: str,
additional_setup_cell_sources: list[str] | None = None,
additional_api_key_blocks: list[str] | None = None,
) -> list[NotebookNode]:
"""Create the Colab-specific setup cells to inject before imports."""
cells = []
cells += [mark_colab_injected(new_markdown_cell(source=COLAB_SETUP_MARKDOWN))]
Expand All @@ -67,7 +90,14 @@ def create_colab_setup_cells(additional_dependencies: str) -> list[NotebookNode]
install_cell += f" {additional_dependencies}"
cells += [mark_colab_injected(new_code_cell(source=install_cell))]

cells += [mark_colab_injected(new_code_cell(source=COLAB_API_KEY_CELL))]
api_key_cell = COLAB_API_KEY_CELL
if additional_api_key_blocks:
api_key_cell = "\n\n".join([api_key_cell, *additional_api_key_blocks])
cells += [mark_colab_injected(new_code_cell(source=api_key_cell))]

if additional_setup_cell_sources:
cells += [mark_colab_injected(new_code_cell(source=src)) for src in additional_setup_cell_sources]

return cells


Expand Down Expand Up @@ -97,6 +127,8 @@ def process_notebook(notebook: NotebookNode, source_path: Path) -> NotebookNode:
cells = notebook.cells

additional_dependencies = ADDITIONAL_DEPENDENCIES.get(source_path.name, "")
additional_setup_cells = ADDITIONAL_SETUP_CELLS.get(source_path.name)
additional_api_key_blocks = ADDITIONAL_API_KEY_BLOCKS.get(source_path.name)

# Find where to insert Colab setup (before "Import the essentials")
import_idx = find_import_section_index(cells)
Expand All @@ -106,7 +138,11 @@ def process_notebook(notebook: NotebookNode, source_path: Path) -> NotebookNode:
import_idx = 1

# Insert Colab setup cells before the import section
colab_cells = create_colab_setup_cells(additional_dependencies)
colab_cells = create_colab_setup_cells(
additional_dependencies,
additional_setup_cells,
additional_api_key_blocks,
)
processed_cells = cells[:import_idx] + colab_cells + cells[import_idx:]

badge_source = COLAB_BADGE_TEMPLATE.format(filename=f"{source_path.stem}.ipynb")
Expand Down
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ nav:
- Providing Images as Context: notebooks/4-providing-images-as-context.ipynb
- Generating Images: notebooks/5-generating-images.ipynb
- Image-to-Image Editing: notebooks/6-editing-images-with-image-context.ipynb
- "Reproducing & Customizing Nemotron-Personas": notebooks/7-nemotron-personas.ipynb
- Recipes:
- Recipe Cards: recipes/cards.md
- Code Generation:
Expand Down
Loading