Documenting code#
Bob can be used to document code. If you put the %%doc
magic at the beginning of a cell…
from dotenv import load_dotenv
load_dotenv()
import os
from bia_bob import bob
bob.initialize(endpoint='https://chat-ai.academiccloud.de/v1', model='openai-gpt-oss-120b', api_key=os.environ.get('KISSKI_API_KEY'))
#bob.initialize(endpoint='https://llm.scads.ai/v1', model='openai/gpt-oss-120b', api_key=os.environ.get('SCADSAI_API_KEY'))
This notebook may contain text, code and images generated by artificial intelligence.
Used model: openai-gpt-oss-120b, vision model: None, endpoint: https://chat-ai.academiccloud.de/v1, bia-bob version: 0.34.3.. Do not enter sensitive or private information and verify generated contents according to good scientific practice. Read more: https://github.com/haesleinhuepf/bia-bob#disclaimer
from bia_bob import bob, doc
bob.__version__
'0.34.3'
%%doc
from skimage.filters import threshold_otsu
from skimage.measure import label
threshold = threshold_otsu(image)
binary = image > threshold
labels = label(binary)
… the cell will get updated when executing it. Note: In case there is %%doc
at the beginning of a cell, the code will not be executed, it will just be replaced. For example the code above could be replaced with this:
from skimage.filters import threshold_otsu # Import threshold_otsu function
from skimage.measure import label # Import label function
# Calculate the Otsu threshold value for the input image
threshold = threshold_otsu(image)
# Binzarize the image at the calculated threshold value,
# resulting in a binary image
binary = image > threshold
# Label connected regions of `True` in the binary image,
# producing a label image where each connected component has a unique integer label
labels = label(binary)
Documenting notebooks#
You can also ask bob to add documentation to a notebook like this:
%%bob
Add documentation to the terribly_documented_analysis.ipynb notebook.
Keep the code as it is and insert a markdown cell explaining every code cell before the corresponding code cell.