Build an app¶
An app is a notebook that Voici renders as a page: the code is hidden, the widgets are shown, and the kernel runs in the browser, as in the Lab sites. lmLite has two, in the apps/ directory:
camera-objects: the camera shows its picture; Take a shot finds the objects in it withdetr-resnet-50(43 MB) and shows them, with Retry to go back to the camera.speak-french: Record an English sentence, Stop, and the browser transcribes it (whisper-tiny.en), translates it (opus-mt-en-fr) and says the translation in French (mms-tts-fra, non-commercial licence), with Retry for the next one.
They are published at https://decitre.github.io/lmlite/apps/voici/render/camera-objects.html and .../speak-french.html.
Build them¶
scripts/lite-build.sh builds the apps as a site of their own, workspace/public/apps, with a xeus-python kernel and jl-forge. They are not part of the Lab site because voici-core holds jupyterlite-core at 0.7, and the Lab sites use 0.8 (see jl-forge’s Voici guide). To build only the apps while you work on one:
LITE_SITES=voici bash scripts/lite-build.sh
The voici-smoke task opens both apps in Chromium with a fake camera and a fake microphone and goes through the buttons.
Write one¶
A notebook in apps/ is a Markdown cell for the title and the instructions, and a code cell that builds the widgets. The pattern of both apps is one button, top left, whose label follows the state (Take a shot, Retry; Record, Stop, Working..., Retry):
The widgets in app mode.
CameraCapture(controls=False, autostart=True, show_photo=False)shows only the live picture and starts it;camera.take()takes the photo, andcamera.switch()goes round the cameras of the device (camera.devicenames the one in use).AudioRecorder(controls=False)shows only a status line;recorder.record()andrecorder.stop()drive it, and itsrawtrait is the Raw input box. Therunningtrait of the camera and theactivetrait of the recorder say when the picture plays and when the microphone records, so the button can follow them.No progress bars.
quiet=Trueinpipeline(...)shows no progress bar and no loading messages, which would appear under the app.Show results with
widgets.Imageandwidgets.HTML. On xeus-python in Voici, anOutputwidget stays empty when it is written from a callback (voici#127).A smaller input for detection.
camera-objectsloads DETR withimage_size=480, the size of the photo, instead of the model’s 800 pixels on the shorter side, which would scale a 640 x 480 photo up first. On WASM in Chromium that took 2.0 s for the two-cats photo instead of 5.6 s, with the same objects found (the second remote at 0.97 instead of 1.00). On a Galaxy S20 FE on WASM a photo took about 25.7 s at the default and 8.9 s in Chrome (9.4 s in Firefox) with the option, on different scenes, one photo each, so that ratio is approximate. Seeimage_size.One model at a time on a phone.
speak-frenchloads each pipeline when it needs it and disposes it as soon as it has answered, so three models are never in memory together.A browser can refuse to autoplay audio, so the voice has controls to tap.