Skip to content

Commit

Permalink
[DOCS] Updating Interactive Tutorials (openvinotoolkit#18504)
Browse files Browse the repository at this point in the history
* update-notebooks

* Update docs/nbdoc/nbdoc.py

Co-authored-by: bstankix <[email protected]>

* Update docs/nbdoc/nbdoc.py

Co-authored-by: bstankix <[email protected]>

---------

Co-authored-by: bstankix <[email protected]>
  • Loading branch information
sgolebiewski-intel and bstankix authored Jul 14, 2023
1 parent 92ecccc commit 6761a29
Show file tree
Hide file tree
Showing 273 changed files with 8,972 additions and 3,472 deletions.
50 changes: 48 additions & 2 deletions docs/nbdoc/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

repo_name = "openvino_notebooks"

artifacts_link = "http://repository.toolbox.iotg.sclab.intel.com/projects/ov-notebook/0.1.0-latest/20230621220808/dist/rst_files/"
artifacts_link = "http://repository.toolbox.iotg.sclab.intel.com/projects/ov-notebook/0.1.0-latest/20230711220806/dist/rst_files/"

blacklisted_extensions = ['.xml', '.bin']

Expand All @@ -20,7 +20,7 @@
binder_template = """
This tutorial is also available as a Jupyter notebook that can be cloned directly from GitHub.
See the |installation_link| for instructions to run this tutorial locally on Windows, Linux or macOS.
To run without installing anything, click the launch binder button.
To run without installing anything, click the "launch binder" button.
|binder_link| |github_link|
Expand All @@ -36,6 +36,52 @@
<a href="https://github.com/{{ owner }}/{{ repo }}" target="_blank"><img src="https://badgen.net/badge/icon/github?icon=github&label" alt="Github"></a>
\n
"""
colab_template = """
This tutorial is also available as a Jupyter notebook that can be cloned directly from GitHub.
See the |installation_link| for instructions to run this tutorial locally on Windows, Linux or macOS.
To run without installing anything, click the "Open in Colab" button.
|colab_link| |github_link|
.. |installation_link| raw:: html
<a href="https://github.com/{{ owner }}/{{ repo }}#-installation-guide" target="_blank">installation guide</a>
.. |colab_link| raw:: html
<a href="https://colab.research.google.com/github/{{ owner }}/{{ repo }}/blob/main/{{ folder }}/{{ notebook }}/{{ notebook }}.ipynb" target="_blank"><img src="https://camo.githubusercontent.com/84f0493939e0c4de4e6dbe113251b4bfb5353e57134ffd9fcab6b8714514d4d1/68747470733a2f2f636f6c61622e72657365617263682e676f6f676c652e636f6d2f6173736574732f636f6c61622d62616467652e737667" alt="Google Colab"></a>
.. |github_link| raw:: html
<a href="https://github.com/{{ owner }}/{{ repo }}" target="_blank"><img src="https://badgen.net/badge/icon/github?icon=github&label" alt="Github"></a>
\n
"""
binder_colab_template = """
This tutorial is also available as a Jupyter notebook that can be cloned directly from GitHub.
See the |installation_link| for instructions to run this tutorial locally on Windows, Linux or macOS.
To run without installing anything, click the "launch binder" or "Open in Colab" button.
|binder_link| |colab_link| |github_link|
.. |installation_link| raw:: html
<a href="https://github.com/{{ owner }}/{{ repo }}#-installation-guide" target="_blank">installation guide</a>
.. |binder_link| raw:: html
<a href="https://mybinder.org/v2/gh/{{ owner }}/{{ repo }}/HEAD?filepath={{ folder }}%2F{{ notebook }}%2F{{ notebook }}.ipynb" target="_blank"><img src="https://mybinder.org/badge_logo.svg" alt="Binder"></a>
.. |colab_link| raw:: html
<a href="https://colab.research.google.com/github/{{ owner }}/{{ repo }}/blob/main/{{ folder }}/{{ notebook }}/{{ notebook }}.ipynb" target="_blank"><img src="https://camo.githubusercontent.com/84f0493939e0c4de4e6dbe113251b4bfb5353e57134ffd9fcab6b8714514d4d1/68747470733a2f2f636f6c61622e72657365617263682e676f6f676c652e636f6d2f6173736574732f636f6c61622d62616467652e737667" alt="Google Colab"></a>
.. |github_link| raw:: html
<a href="https://github.com/{{ owner }}/{{ repo }}" target="_blank"><img src="https://badgen.net/badge/icon/github?icon=github&label" alt="Github"></a>
\n
"""
no_binder_template = """
Expand Down
58 changes: 41 additions & 17 deletions docs/nbdoc/nbdoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
from consts import (
artifacts_link,
binder_template,
colab_template,
binder_colab_template,
blacklisted_extensions,
notebooks_docs,
notebooks_path,
Expand Down Expand Up @@ -98,24 +100,44 @@ def __init__(self, nb_path: str = notebooks_path):
"repo": repo_name,
"folder": repo_directory,
}
self.colab_data = {
"owner": repo_owner,
"repo": repo_name,
"folder": repo_directory,
}

def fetch_binder_list(self, file_format: str = 'txt') -> list:
def fetch_binder_list(self, file) -> list:
"""Function that fetches list of notebooks with binder buttons
:param file_format: Format of file containing list of notebooks with button. Defaults to 'txt'
:type file_format: str
:return: List of notebooks conaining binder buttons
:return: List of notebooks containing binder buttons
:rtype: list
"""
list_of_buttons = glob(f"{self.nb_path}/*.{file_format}")
list_of_buttons = glob(f"{self.nb_path}/{file}")
if list_of_buttons:
with open(list_of_buttons[0]) as file:
list_of_buttons = file.read().splitlines()
return list_of_buttons
else:
return []
return []

def add_binder(self, buttons_list: list, template_with_binder: str = binder_template, template_without_binder: str = no_binder_template):
def fetch_colab_list(self, file) -> list:
"""Function that fetches list of notebooks with colab buttons
:param file_format: Format of file containing list of notebooks with button. Defaults to 'lst'
:type file_format: str
:return: List of notebooks containing colab buttons
:rtype: list
"""
list_of_cbuttons = glob(f"{self.nb_path}/{file}")
if list_of_cbuttons:
with open(list_of_cbuttons[0]) as file:
list_of_cbuttons = file.read().splitlines()
return list_of_cbuttons
return []


def add_binder(self, buttons_list: list, cbuttons_list: list, template_with_colab_and_binder: str = binder_colab_template, template_with_binder: str = binder_template, template_with_colab: str = colab_template, template_without_binder: str = no_binder_template):
"""Function working as an example how to add binder button to existing rst files
:param buttons_list: List of notebooks that work on Binder.
Expand All @@ -127,19 +149,20 @@ def add_binder(self, buttons_list: list, template_with_binder: str = binder_tem
:raises FileNotFoundError: In case of failure of adding content, error will appear
"""

for notebook in [
nb for nb in os.listdir(self.nb_path) if verify_notebook_name(nb)
]:
if '-'.join(notebook.split('-')[:-2]) in buttons_list:
button_text = create_content(
template_with_binder, self.binder_data, notebook)
if not add_content_below(button_text, f"{self.nb_path}/{notebook}"):
raise FileNotFoundError("Unable to modify file")
notebook_item = '-'.join(notebook.split('-')[:-2])

if notebook_item in buttons_list:
template = template_with_colab_and_binder if notebook_item in cbuttons_list else template_with_binder
else:
button_text = create_content(
template_without_binder, self.binder_data, notebook)
if not add_content_below(button_text, f"{self.nb_path}/{notebook}"):
raise FileNotFoundError("Unable to modify file")
template = template_with_colab if notebook_item in cbuttons_list else template_without_binder

button_text = create_content(template, self.binder_data, notebook)
if not add_content_below(button_text, f"{self.nb_path}/{notebook}"):
raise FileNotFoundError("Unable to modify file")

def render_rst(self, path: str = notebooks_docs, template: str = rst_template):
"""Rendering rst file for all notebooks
Expand Down Expand Up @@ -170,8 +193,9 @@ def main():
shutil.copytree(sourcedir, outdir)
# Step 3. Run processing on downloaded file
nbp = NbProcessor(outdir)
buttons_list = nbp.fetch_binder_list('txt')
nbp.add_binder(buttons_list)
buttons_list = nbp.fetch_binder_list('notebooks_with_binder_buttons.txt')
cbuttons_list = nbp.fetch_colab_list('notebooks_with_colab_buttons.txt')
nbp.add_binder(buttons_list, cbuttons_list)
nbp.render_rst(outdir.joinpath(notebooks_docs))


Expand Down
39 changes: 33 additions & 6 deletions docs/notebooks/001-hello-world-with-output.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ from `Open Model
Zoo <https://github.com/openvinotoolkit/open_model_zoo/>`__ is used in
this tutorial. For more information about how OpenVINO IR models are
created, refer to the `TensorFlow to
OpenVINO <101-tensorflow-to-openvino-with-output.html>`__
OpenVINO <101-tensorflow-classification-to-openvino-with-output.html>`__
tutorial.

Imports
Expand Down Expand Up @@ -52,7 +52,6 @@ Download the Model and data samples
.. parsed-literal::
artifacts/v3-small_224_1.0_float.xml: 0%| | 0.00/294k [00:00<?, ?B/s]
Expand All @@ -64,14 +63,42 @@ Download the Model and data samples
artifacts/v3-small_224_1.0_float.bin: 0%| | 0.00/4.84M [00:00<?, ?B/s]
Select inference device
-----------------------

select device from dropdown list for running inference using OpenVINO

.. code:: ipython3
import ipywidgets as widgets
core = Core()
device = widgets.Dropdown(
options=core.available_devices + ["AUTO"],
value='AUTO',
description='Device:',
disabled=False,
)
device
.. parsed-literal::
Dropdown(description='Device:', index=1, options=('CPU', 'AUTO'), value='AUTO')
Load the Model
--------------

.. code:: ipython3
ie = Core()
model = ie.read_model(model=model_xml_path)
compiled_model = ie.compile_model(model=model, device_name="CPU")
core = Core()
model = core.read_model(model=model_xml_path)
compiled_model = core.compile_model(model=model, device_name=device.value)
output_layer = compiled_model.output(0)
Expand All @@ -92,7 +119,7 @@ Load an Image
.. image:: 001-hello-world-with-output_files/001-hello-world-with-output_8_0.png
.. image:: 001-hello-world-with-output_files/001-hello-world-with-output_10_0.png


Do Inference
Expand Down
6 changes: 3 additions & 3 deletions docs/notebooks/001-hello-world-with-output_files/index.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<html>
<head><title>Index of /projects/ov-notebook/0.1.0-latest/20230621220808/dist/rst_files/001-hello-world-with-output_files/</title></head>
<head><title>Index of /projects/ov-notebook/0.1.0-latest/20230711220806/dist/rst_files/001-hello-world-with-output_files/</title></head>
<body bgcolor="white">
<h1>Index of /projects/ov-notebook/0.1.0-latest/20230621220808/dist/rst_files/001-hello-world-with-output_files/</h1><hr><pre><a href="../">../</a>
<a href="001-hello-world-with-output_8_0.png">001-hello-world-with-output_8_0.png</a> 22-Jun-2023 00:06 387941
<h1>Index of /projects/ov-notebook/0.1.0-latest/20230711220806/dist/rst_files/001-hello-world-with-output_files/</h1><hr><pre><a href="../">../</a>
<a href="001-hello-world-with-output_10_0.png">001-hello-world-with-output_10_0.png</a> 12-Jul-2023 00:11 387941
</pre><hr></body>
</html>
Loading

0 comments on commit 6761a29

Please sign in to comment.