Skip to content

Commit 476688b

Browse files
committed
Merge branch 'docs'
Redesigns the AI notebook for clarity and simplification. Adds supporting documentation for the new notebook.
2 parents 3f1fc90 + b9cc0d0 commit 476688b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+2382
-492
lines changed

.github/scripts/update_notebook.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ def main():
271271
# Setup paths
272272
script_dir = Path(__file__).parent
273273
repo_root = script_dir.parent.parent
274-
notebook_path = repo_root / "doc" / "llms" / "pyimagej-ai-guide.ipynb"
274+
notebook_path = repo_root / "doc" / "llms" / "custom-pyimagej-ai-guide.ipynb"
275275
personas_dir = repo_root / "doc" / "llms" / "personas"
276276
rulesets_dir = repo_root / "doc" / "llms" / "rulesets"
277277
templates_dir = script_dir.parent / "templates" # .github/templates, not .github/scripts/templates

.github/templates/personalize_gemini_cell.py.j2

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ experience_mapping = {
2929
}
3030

3131
# Activity file mapping for different experience categories
32-
activity_dir = 'activities/'
32+
activity_dir = 'activities'
3333

3434
{% for category, mapping in category_mappings.items() %}
3535
{{ category }}_activities = {
3636
{% for level, filename in mapping.items() %}
37-
{{ level }}: activity_dir + '{{ filename }}',
37+
{{ level }}: activity_dir / '{{ filename }}',
3838
{% endfor %}
3939
}
4040

@@ -70,6 +70,7 @@ def load_persona_file(filename):
7070

7171
# Load base persona with section markers
7272
persona_text = load_persona_file('base_persona.md')
73+
persona_text += load_persona_file(activity_dir / 'base_persona.md')
7374

7475
# Get experience levels
7576
{% for category in categories.keys() %}

.github/workflows/update-notebook.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: Update PyImageJ AI Guide Notebook
22

33
on:
44
push:
5-
branches: [ main ] # Only auto-run on main
5+
branches: [ none ] # Turn off auto-runs for now
66
paths:
77
- 'doc/llms/personas/**'
88
- 'doc/llms/rulesets/**'

doc/AI-Tutorial-Notebook.md

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
# Google Colab Notebook
2+
3+
This document is designed to supplement your use of our PyImageJ + Large Language Model (LLM) Google Colab Notebook:
4+
5+
<!-- UPDATE: pin to particular commit -->
6+
<a href="https://colab.research.google.com/github/imagej/pyimagej/blob/main/doc/llms/pyimagej-ai-guide.ipynb" target="_parent"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/></a>
7+
8+
## Background Knowledge
9+
10+
If any of these topics are new to you:
11+
* Colab → check out [our overview](Google-Colab-Basics.md)
12+
* LLMs → read through [prompt engineering basics](Prompt-Engineering.md)
13+
* Python → browse an overview, like [W3 schools](https://www.w3schools.com/python/)
14+
15+
## Learning Goals
16+
17+
For doing science, ultimately we want to code in a **reproducible** environment (*which Colab is not*). We imagine the progression of a new learner might proceed as:
18+
19+
- First, use our AI Notebook to experiment with PyImageJ until you are comfortable with the concepts and syntax.
20+
- From there, you can transition to the creating Python workflows in the [Fiji Script Editor](https://imagej.net/scripting/script-editor).
21+
- Alternatively, you *can* run Jupyter Notebooks locally. If this interests you, look at tools like [uv](https://docs.astral.sh/uv/) to [set up](Install.md) PyImageJ environments.
22+
- If you find that you love programming, you could also explore the [developer ecosystem](https://imagej.net/develop/)! Tools like GitHub Copilot, Claude Code and cursor bring exceptional new directions to ImageJ plugin development.
23+
24+
💡**Tip**: LLMs can provide guidance in all of these tasks! But so can humans - please reach out on the [Image.sc forum](https://forum.image.sc/) if you need support!
25+
26+
Also note that if you enjoy Gemini and Colab, you can certainly use the environment to *create* Python code that will run in the Script Editor (for example). Requirements and syntax may change a bit between environments though, so typically it is easiest to develop code in the environment where it will run.
27+
28+
Fundamentally, **the goal of this Notebook** is to support you in building the skills and confidence that you can adapt to any of these environments, based on your own analysis needs.
29+
30+
## Navigating the Notebook
31+
32+
### Initialization
33+
34+
All that's needed to start up the notebook is to click the `Run All` button in the toolbar:
35+
36+
![Run All](doc-images/nb-run-all.jpg)
37+
38+
This will do several things, which unfortunately can take a few minutes. You'll see a progress bar with status indicators as the set up functions are running:
39+
40+
![Progress](doc-images/nb-progress.jpg)
41+
42+
Here's an overview of key steps:
43+
44+
* **Downloading PyImageJ source** from the [GitHub repository](https://github.com/imagej/pyimagej) is necessary because it contains the [rules and persona files](https://github.com/imagej/pyimagej/tree/main/doc/llms) to teach Gemini.
45+
* **Customizing Gemini** this way allows the notebook to grow over time: we can revise these support files to bring new behavior to Gemini.
46+
* **Downloading a Fiji bundle** provides PyImageJ access to all the plugins in a base Fiji download.
47+
* **Initializing PyImageJ** starts up a running instance of Fiji, which you can then access through the `ij` variable.
48+
* ⚠️**Warning:** The only verified method of [initialization](Initialization.md) in Google Colab are using local bundles from [fiji-builds](https://github.com/fiji/fiji-builds/releases) ⚠️
49+
50+
Once the progress bar status shows `✅ Setup complete!`, your notebook is ready to go! You can start coding in the blank code cell at the bottom of the notebook, or start a conversation with Gemini and describe what you'd like to accomplish or learn.
51+
52+
![Start Coding](doc-images/nb-start-coding.jpg)
53+
54+
### Making space
55+
56+
The AI Notebook is big. We've tried to keep it concise, but for example the `🤖 Customize Gemini` step **must** print all of its output text (which is a lot!) so that Gemini can actually read it.
57+
58+
However, if you want to make things cleaner, you *can* collapse the `⚙️ Notebook Configuration` and/or `🔍 Utilities` section(s):
59+
60+
![Collapsed](doc-images/nb-collapsed.jpg)
61+
62+
Additionally, you can safely hide the output of individual cells using the `Output actions` button (which appears after running code cells):
63+
64+
![Hiding output](doc-images/nb-hide-output.jpg)
65+
66+
### Modifying the Notebook Itself
67+
68+
In this notebook we make extensive use of [Colab's forms](https://colab.research.google.com/notebooks/forms.ipynb), in large part to keep the code hidden.
69+
70+
If you want to dig into the internals of the notebook itself, any cell with a `Show code` button at the bottom can be toggled with the `>` at the top-left of that cell:
71+
72+
![Show/Hide Code](doc-images/nb-show-code.png)
73+
74+
The following cells have <span style="color: green;"># --UPDATE</span> comments marking areas with simple edits to influence Notebook reproducibility:
75+
76+
* `📦 Download PyImageJ Source`: specify [the commit](https://github.com/imagej/pyimagej) for the LLM instruction files.
77+
* `🏝️ Setup Fiji Bundle`: specify [the bundle ID](https://github.com/fiji/fiji-builds/releases) for the Fiji download.
78+
79+
## Troubleshooting
80+
81+
### Failures during setup
82+
83+
The setup generates *a lot* of output, which we hide by default to avoid overwhelming new users and cluttering the notebook.
84+
85+
If something goes wrong, the `⚙️ Utilities` section has tools to help.
86+
87+
First, you can check the `✅ Verify Setup` step to see if there are PyImageJ problems.
88+
89+
If you need more information, you can use the `🛠️ Troubleshooting` cell to view a step's hidden output:
90+
91+
![Troubleshooting](doc-images/nb-troubleshoot.jpg)
92+
93+
94+
### Gemini didn't pick up the personality text
95+
96+
![Colab Persona](doc-images/colab-persona.jpg)
97+
98+
If you start communicating with Gemini *before loading* the the instructional + personality text, Gemini may not see it properly.
99+
100+
The easiest thing to do is reload the page and re-run the notebook.
101+
102+
## FAQ
103+
104+
### Why a Colab Notebook?
105+
106+
This came from a desire to build image analysis workflows using ImageJ in an environment where a LLM assistant has direct contextual access.
107+
108+
Although a first-party LLM assistant in Fiji itself would be ideal, that requires significantly more development and maintenance time.
109+
110+
With Colab + PyImageJ we take advantage of existing tools, and have the added benefit of access to the Python scientific software stack (e.g. [Cellpose](https://www.cellpose.org/)).
111+
112+
### But this notebook looks complicated!
113+
114+
Setting up PyImageJ previously required understanding of developer-focused tools. This notebook removes any configuration and installation barriers, allowing you to get right into image analysis.
115+
116+
There were also some tricky setup challenges due to the fact that notebooks are running on Google's remote computers, and not your local system. Luckily, we've already solved them for you!
117+
118+
Because of the general scope of this notebook, there is a lot of explanatory text. If something is still confusing or overwhelming or just not useful, that is important for us to know! Please [get in touch](https://forum.image.sc/tag/pyimagej) and let us know what we can do better.
119+
120+
### Are there any other reasons to use this notebook?
121+
122+
We are developing instruction sets for LLMs to help them produce better code. Ideally these should be tailored to the environment where the code will be running (e.g. in a notebook, or the Fiji script editor). These are targeted rules that general LLMs wouldn't have access to.
123+
124+
Using the AI Notebook gives you access to these instruction sets. We are also relying on users like you to provide feedback when things go wrong! That is the only way for these rulesets to grow.
125+
126+
### How do I use these instructions with other LLMs?
127+
128+
After running the notebook, there is a `📋 Copy AI Instructions` cell in the `⚙️ Utilities` section. Just click that button! Then you can paste the instructions at the start of a conversation with any other LLM.
129+
130+
![Copy Instructions](doc-images/copy-ai-text.jpg)
131+
132+
### I thought an "AI Notebook" would use more... AI
133+
134+
While AI-based analysis techniques are very exciting, they are massively overpowered for most image analysis needs.
135+
136+
The goal of using an integrated "AI assistant" is precisely to **find** the appropriate technique for your needs. Maybe that will require another AI tool, but often it won't!
137+
138+
### Aren't Colab notebooks "headless"?
139+
140+
Technically yes - as they are running on remote (not local) computers, we don't have access to a display/monitor (and are thus "headless").
141+
142+
This is relevant because many ImageJ 1.x plugins were developed with an implicit assumption of an active display.
143+
144+
However, the AI notebook is set up to "fake" a display: this allows many ImageJ 1.x functions to work correctly, when they otherwise would have failed. (you may still run into some things that simply can't work, though)
145+
146+
Note that this requirement was specifically decoupled from ImageJ2 plugins, which should work as intended.

0 commit comments

Comments
 (0)