Quentin Bammey
3rd of April, 2022
https://ipolcore.ipol.im/demo/clientApp/demo.html?id=5555531082037
What you will learn today:
At the end of this talk, you will know how to make and preview a local demo.
Tomorrow: Jeremy and Miguel will show you how to put the demo online, and ensure its reproducibility with Docker
We are not making interactive notebooks where the user modifies and runs the code himself.
Much simpler:
What you will need:
jupyter notebook
or jupyter lab
(not vscode
which is incompatible with parameterization features)papermill
: pip install --user papermill
or conda install -c conda-forge papermill
First cell of the notebook, as a Raw cell theme_ipol.scss
: get it from the source code in the last slide and place it in the same directory as the notebook (ensures font and size consistency with IPOL).
(will be important for archiving the demo)
Use IPython.display
to show images, videos, audio, not a plotting library such as matplotlib
. Why?
---
execute:
echo: false
warning: false
format:
html:
theme: "theme_ipol.scss"
self-contained: true
---
quarto render main.ipynb -o main.html
To execute the notebook while rendering:
quarto render main.ipynb -o main.html --execute
Preview mode (re-render as the notebook is saved):
quarto preview main.ipynb -o main.html
IPython.display
: prefer this to plotting librariesmatplotlib
, seaborn
plotly
, altair
, bokeh
matplotlib
and seaborn
)You want to be able to run your code with different inputs and parameters
input_0.png
, input_1.png
, etc)Simplified version of then notebook above
(with their default value)
With the tag parameters
See here to add tags.
quarto render main.ipynb --execute -P n_crop:10
quarto render main.ipynb --execute -P n_crop:100
quarto render main.ipynb --execute -P n_crop:200
If you have more than one parameter: prefix each with -P
, e.g. quarto render main.ipynb --execute -P n_crop:10 -P foo:5 -P bar:8
Warning: For parameters with free text, enclose the parameters in double quotes: -P "param:something else"
. This will still cause a few problems with IPOL: ask us for help.
A few points to fix first
On IPOL, the notebook is moved before execution. To be able to import code or load data (e.g. model weights), use the SRCDIR parameter, with a default value of '.'
And add SRCDIR
to the list of import directories to be able to import local code:
Load your model relative to SRCDIR
:
See here for a complete demo made using a notebook, and here for the source code (and the notebook).
Tweaking the notebook Layout / Interactive visualizations with plotly
Put this with your imports if you use plotly
from bokeh.io import output_notebook
output_notebook(resources=bkh.resources.Resources(mode='cdn'), hide_banner=True)
total_bill | tip | sex | smoker | day | time | size | |
---|---|---|---|---|---|---|---|
0 | 16.99 | 1.01 | Female | No | Sun | Dinner | 2 |
1 | 10.34 | 1.66 | Male | No | Sun | Dinner | 3 |
2 | 21.01 | 3.50 | Male | No | Sun | Dinner | 3 |
3 | 23.68 | 3.31 | Male | No | Sun | Dinner | 2 |
4 | 24.59 | 3.61 | Female | No | Sun | Dinner | 4 |
... | ... | ... | ... | ... | ... | ... | ... |
239 | 29.03 | 5.92 | Male | No | Sat | Dinner | 3 |
240 | 27.18 | 2.00 | Female | Yes | Sat | Dinner | 2 |
241 | 22.67 | 2.00 | Male | Yes | Sat | Dinner | 2 |
242 | 17.82 | 1.75 | Male | No | Sat | Dinner | 2 |
243 | 18.78 | 3.00 | Female | No | Thur | Dinner | 2 |
244 rows × 7 columns