Introduction

[1]:
# handle launching on colab
if "google.colab" in str(get_ipython()):
    # running on CoLab
    %pip install -U "ipylabel>=0.1.7"

    from google.colab import output

    output.enable_custom_widget_manager()
[2]:
from __future__ import annotations

import ipylabel
[3]:
text_widget = ipylabel.TextWidget(
    text="Мама мыла раму",
    labels=["protein", "DNA", "RNA", "Also NO"],
    colors=["#ff0000", "#00ff00", "#0000ff", "#f0f0ff"],
    result=[{"start": 0, "end": 5, "label": "DNA"}],
)

text_widget.observe(lambda c: print(c), ["result", "finished"])
text_widget
[4]:
widgets = [
    ipylabel.TextWidget(
        text="Мама мыла раму",
        labels=["protein", "DNA", "RNA"],
        colors=["#ff0000", "#00ff00", "#0000ff"],
        result=[{"start": 0, "end": 5, "label": "DNA"}],
    )
    for _ in range(10)
]
display(*widgets)
[ ]: