struggle-annotator 0.2.4__tar.gz → 0.3.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {struggle_annotator-0.2.4/struggle_annotator.egg-info → struggle_annotator-0.3.1}/PKG-INFO +1 -1
- {struggle_annotator-0.2.4 → struggle_annotator-0.3.1}/pyproject.toml +1 -1
- {struggle_annotator-0.2.4 → struggle_annotator-0.3.1}/struggle_annotator/__init__.py +28 -3
- struggle_annotator-0.3.1/struggle_annotator/frontend/build/assets/index-Ow0uhd4Z.js +39 -0
- {struggle_annotator-0.2.4 → struggle_annotator-0.3.1}/struggle_annotator/frontend/build/index.html +1 -1
- {struggle_annotator-0.2.4 → struggle_annotator-0.3.1/struggle_annotator.egg-info}/PKG-INFO +1 -1
- {struggle_annotator-0.2.4 → struggle_annotator-0.3.1}/struggle_annotator.egg-info/SOURCES.txt +1 -1
- struggle_annotator-0.2.4/struggle_annotator/frontend/build/assets/index-LtXtvZ4l.js +0 -39
- {struggle_annotator-0.2.4 → struggle_annotator-0.3.1}/LICENSE +0 -0
- {struggle_annotator-0.2.4 → struggle_annotator-0.3.1}/MANIFEST.in +0 -0
- {struggle_annotator-0.2.4 → struggle_annotator-0.3.1}/README.md +0 -0
- {struggle_annotator-0.2.4 → struggle_annotator-0.3.1}/setup.cfg +0 -0
- {struggle_annotator-0.2.4 → struggle_annotator-0.3.1}/struggle_annotator.egg-info/dependency_links.txt +0 -0
- {struggle_annotator-0.2.4 → struggle_annotator-0.3.1}/struggle_annotator.egg-info/requires.txt +0 -0
- {struggle_annotator-0.2.4 → struggle_annotator-0.3.1}/struggle_annotator.egg-info/top_level.txt +0 -0
|
@@ -4,7 +4,7 @@ import os
|
|
|
4
4
|
import streamlit.components.v1 as components
|
|
5
5
|
|
|
6
6
|
# Set to False during local frontend development (points at Vite dev server).
|
|
7
|
-
_RELEASE =
|
|
7
|
+
_RELEASE = False
|
|
8
8
|
|
|
9
9
|
if not _RELEASE:
|
|
10
10
|
_component_func = components.declare_component(
|
|
@@ -18,7 +18,14 @@ else:
|
|
|
18
18
|
_component_func = components.declare_component("txt_annotator", path=_build_dir)
|
|
19
19
|
|
|
20
20
|
|
|
21
|
-
def txt_annotator(
|
|
21
|
+
def txt_annotator(
|
|
22
|
+
text: str,
|
|
23
|
+
label_dict: dict,
|
|
24
|
+
spacing: float = 1.9,
|
|
25
|
+
label_position: str = "top",
|
|
26
|
+
auto_expand: bool = True,
|
|
27
|
+
key: str | None = None,
|
|
28
|
+
) -> dict:
|
|
22
29
|
"""Interactive NER-style text annotation component.
|
|
23
30
|
|
|
24
31
|
Parameters
|
|
@@ -29,6 +36,13 @@ def txt_annotator(text: str, label_dict: dict, key: str | None = None) -> dict:
|
|
|
29
36
|
Entity definitions. Keys are label names; values must contain ``color``
|
|
30
37
|
(any valid CSS color) and optionally ``annotation`` (list of
|
|
31
38
|
``{"start": int, "end": int, "value": str}`` dicts).
|
|
39
|
+
spacing:
|
|
40
|
+
Initial line-height of the text area (1.2 – 5.0). Default ``1.9``.
|
|
41
|
+
label_position:
|
|
42
|
+
Where to render the entity buttons — ``"top"``, ``"left"``, or ``"right"``.
|
|
43
|
+
Default ``"top"``.
|
|
44
|
+
auto_expand:
|
|
45
|
+
When ``True`` (default), selections are expanded to full word boundaries.
|
|
32
46
|
key:
|
|
33
47
|
Standard Streamlit component key — required when rendering multiple
|
|
34
48
|
annotators on the same page.
|
|
@@ -39,6 +53,9 @@ def txt_annotator(text: str, label_dict: dict, key: str | None = None) -> dict:
|
|
|
39
53
|
Updated ``label_dict`` with each entity's ``annotation`` list reflecting
|
|
40
54
|
the current UI state. Annotations within each entity are sorted by ``start``.
|
|
41
55
|
"""
|
|
56
|
+
if label_position not in ("top", "left", "right"):
|
|
57
|
+
raise ValueError(f"label_position must be 'top', 'left', or 'right', got {label_position!r}")
|
|
58
|
+
|
|
42
59
|
normalised = {
|
|
43
60
|
label: {
|
|
44
61
|
"color": cfg["color"],
|
|
@@ -46,5 +63,13 @@ def txt_annotator(text: str, label_dict: dict, key: str | None = None) -> dict:
|
|
|
46
63
|
}
|
|
47
64
|
for label, cfg in label_dict.items()
|
|
48
65
|
}
|
|
49
|
-
result = _component_func(
|
|
66
|
+
result = _component_func(
|
|
67
|
+
text=text,
|
|
68
|
+
label_dict=normalised,
|
|
69
|
+
spacing=float(spacing),
|
|
70
|
+
label_position=label_position,
|
|
71
|
+
auto_expand=bool(auto_expand),
|
|
72
|
+
key=key,
|
|
73
|
+
default=normalised,
|
|
74
|
+
)
|
|
50
75
|
return result if result is not None else normalised
|