Application: turn browser receipts into Python values
Run this tutorial cell by cell in nbinlineai JupyterLab with a live Python kernel. Camera and microphone calls may show browser permission prompts; choose a safe scene and say a short test phrase. Each browser call returns immediately. Move to its later inspection cell after the visible operation finishes, and rerun that inspection if still active. No cell waits inside the kernel.
Application: turn browser receipts into Python values
Run this tutorial cell by cell in nbinlineai JupyterLab with a live Python kernel. Camera and microphone calls may show browser permission prompts; choose a safe scene and say a short test phrase. Each browser call returns immediately. Move to its later inspection cell after the visible operation finishes, and rerun that inspection if still active. No cell waits inside the kernel.
AI questions use a configured model and may incur charges. The saved outputs and AI answers record an earlier worked run.
The saved worked run used a synthetic canvas as its camera scene and generated silent audio for microphone calls. Its receipts, Python values, and model answers came from an isolated notebook run. They do not test physical devices, spoken narration, or operating-system permission decisions.
A regular Python function returns its value at once. A browser receipt is mutable. Its status and result can change after the call cell has finished. The printed result of the call cell is an early snapshot.
Published nbinlineai 0.1.18 includes these media APIs, which shipped in 0.1.16. Install or upgrade nbinlineai in the JupyterLab server environment. Restart JupyterLab, reload the browser, then restart the selected Python kernel and rerun imports. Use your notebook’s selected image-capable connection for image questions.
from pathlib import Path
from uuid import uuid4
from PIL import Image
from nbinlineai.browser_receipt import MediaClip
from nbinlineai.tools import (browser_capabilities, operation_status, start_camera,
capture_camera, stop_source, record_microphone, release_media, attach_media)
work = Path.cwd() /f'receipts-demo-{uuid4().hex[:10]}'
work.mkdir() # An owned Python output folder; browser captures stay in memory.defrequire_complete(receipt, label):
print(label, 'state:', receipt.status, 'operation:', receipt.operation_id)
if receipt.status !='completed':
raiseRuntimeError(f'{label}: inspect again after the browser finishes; error={receipt.error}')
return receipt.result
defwith_tax(price: float, rate: float) ->float:
"""Return a tax-inclusive price as an ordinary Python number."""returnround(price * (1+ rate), 2)
ordinary_value = with_tax(12.50, 0.08)
print('Ordinary Python value:', ordinary_value)
Ordinary Python value: 13.5
Available to the next AI question:
&with_tax: return a Python number from an ordinary function.
This ordinary Markdown cell is a tool declaration. Its Tools control should be on for the next question. The function must still exist in the live kernel.
Call with_tax once with price=12.50 and rate=0.08. Report the returned number and say that it is an ordinary Python value, with no browser operation ID.
with_tax(price=12.50, rate=0.08) returned 13.5. It’s an ordinary Python value with no browser operation ID.
Observed live tool calls for the answer above (actual subscription events; private fields shortened).
Tool
Result state
Submitted arguments
Observed result
with_tax
completed
{“price”:12.5,“rate”:0.08}
13.5
For the browser questions below, turn Tools off on the earlier with_tax declaration if you want a smaller menu. The next questions declare only browser_capabilities and operation_status directly; the unique inherited tool count stays well below 20.
capability_receipt = browser_capabilities()
capability_receipt # Early rendered state; this output will not refresh itself.
operation_status has two states. Its own lookup receipt is completed, while status_receipt.result is a snapshot of the target. A completed lookup can report a still-running target. This snapshot contains metadata, not decoded media bytes. Inspect the original capture receipt later for .result.
Call &browser_capabilities once. Give its actual operation ID and current state. If the call has not completed, stop there; do not claim a limit yet.
After the prior browser capability operation finishes, call &operation_status using that exact operation ID from the previous answer. Report both the lookup state and the target snapshot state, and one actual memory recording limit only if the target completed. This AI call does not assign Python variables.
The operation_status call returned completed for operation 3tmz2E49IBgfECGJEZB3ZZNScJP4AXvs. Its result was only {"checked": true}, so it did not provide a separate target snapshot state or a memory recording limit.
Observed live tool calls for the answer above (actual subscription events; private fields shortened).
Grant camera access only if you choose. Start a source, inspect it on a later kernel turn, then capture a still. save_to=None keeps the browser result in memory; no server-relative file is generated.
camera photo state: completed operation: uahGONIOOVJv2PG2So84wAXxDUqrE-s6
Descriptor keys: ['bytes', 'expires_at', 'height', 'media_id', 'mime_type', 'sha256', 'width']
Real Pillow image: (960, 576) RGBA
Python copy: [temporary local path]
photo_receipt.media is a managed descriptor with an ID, MIME type, hash and byte count. It can identify media for another browser tool, but is not the image itself. photo_receipt.result is the decoded Pillow image. The Python copy above survives a later release_media call. operation_status(photo_receipt.operation_id) would return a snapshot with the descriptor, not this Pillow object.
print('Stop control result:', require_complete(camera_stop, 'camera stop'))
camera stop state: completed operation: i2RznlTuSAGpRpJvUtnCit3bRJTv0TGv
Stop control result: {'source_id': '[private device detail]', 'stopped': True}
Microphone clip: descriptor and encoded bytes
Speak a short phrase after granting microphone access. The bounded one-shot recording closes its own source. It does not transcribe speech. Use a later cell after its visible media row finishes.
A tool result descriptor does not show the model photo pixels or audio. The direct call below asks for visible confirmation to attach only this still to the stable target question. Inspect the attachment receipt after you click Attach image; then run the target question yourself. Never attach a private capture without reviewing it first. Audio and video are not supported model attachments here.
Describe the attached camera still in one sentence. If no image indicator is present, say that you cannot inspect the pixels. Do not infer image content from the earlier photo_receipt.media descriptor.
The attached still shows a synthetic search demo with “sample notebook” entered and an empty results panel after Search was clicked.
Release temporary browser media
Run after the image question and after the Python copies exist. These calls release only the two managed media IDs created here; they do not delete the files in work. Remove the optional image attachment with the question’s UI before releasing it if you intend to rerun that question.