# streamlit-text-annotation
streamlit-text-annotation is a simple streamlit component for displaying and editing text annotations.
Its display functions are similar to [st-annotated-text](https://github.com/tvst/st-annotated-text), with the following added functions:
- support for multiple labels on the same token
- optional CSS style customization for each label
- automatic distinct color assignment (can be overridden with CSS styles)
- horizonal and vertical label layouts
Its (optional) editing functions allow users to easily add or delete multi-label annotations.
This component is built on [streamlit-component-template-vue](https://github.com/andfanilo/streamlit-component-template-vue).
# Installation
```
pip install streamlit-text-annotation
```
## Parameters
The text_annotation function accepts the following parameters:
- tokens (required): an array of token objects whose properties include 'text' (required) and 'labels' (optional), in the following format:
```
[
{ text: "Text1"},
{ text: "Text2", labels: ["Label1", "Label2"] },
]
```
- labels (optional, default=[]): an array of label objects whose properties include 'text' (required) and 'style' (optional), in the following format:
```
[
{"text": "Pronoun"},
{"text": "Verb", "style": {
"color": "green",
"background-color": "white",
"font-size": "8px",
"font-weight": "900",
}}
]
```
- allowEditing (optional, default=false): boolean; set to true to allow editing (edit mode) or false to disallow (display mode)
- labelOrientation (optional, default="vertical"): whether to display the labels vertically ("vertical") or horizontally ("horizontal")
- collectLabelsFromTokens (optional, default=true): whether to add labels from existing token labels (defined in the tokens array) to the labels array if not found
## Examples
```
import streamlit as st
from streamlit_text_annotation import text_annotation
data1 = {
"tokens": [
{"text": "He", "labels": ["Person"]},
{"text": "loves"},
{"text": "his"},
{"text": "dog", "labels": ["Animal", "Pet"]},
],
"labels": [
{"text": "Person"},
{"text": "Action"},
{"text": "Animal"},
]
}
st.subheader("Display Mode:")
left, right = st.columns(2)
with left:
st.text("Vertical labels:")
text_annotation(data1)
with right:
st.text("Horizontal labels:")
data1["labelOrientation"] = "horizontal"
text_annotation(data1)
data2 = {
"allowEditing": True,
"tokens": [
{"text": "He", "labels": ["Pronoun", "Person"]},
{"text": "loves", "labels": ["Action"]},
{"text": "his"},
{"text": "dog", "labels": ["Animal"]},
],
"labels": [
{"text": "Pronoun", "style": {
"color": "red",
"background-color": "white",
"font-size": "8px",
"border": "3px dashed red",
}},
{"text": "Verb", "style": {
"color": "green",
"background-color": "white",
"font-size": "8px",
"font-weight": "900",
}},
{"text": "Noun", "style": {
"color": "blue",
"background-color": "white",
"font-size": "8px",
}},
{"text": "Person"},
{"text": "Animal"},
]
}
st.subheader("Edit Mode:")
data = text_annotation(data2)
if data:
"Returned data:", data
```
Metadata
Release files for streamlit-text-annotation 0.1.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| streamlit-text-annotation-0.1.5.tar.gz | 518.6 kB | Without provenance | Details for streamlit-text-annotation-0.1.5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| streamlit_text_annotation-0.1.5-py3-none-any.whl | Python 3 | none | any | Details for streamlit_text_annotation-0.1.5-py3-none-any.whl |
Total release size: 1.0 MB
Release files / streamlit-text-annotation-0.1.5.tar.gz
| Download URL | streamlit-text-annotation-0.1.5.tar.gz |
|---|---|
| Size | 518.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4cb982d76db14c96041c1cfd2cf71349407efbb85594ab159ee0b3347b6b129d
|
|
BLAKE2b-256 checksum How to use checksums |
e3b1385e2a4ddb2c863968dd603ff7fda8753fe5ad407f7d5bf810e6caaa9202
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.3
|
Release files / streamlit_text_annotation-0.1.5-py3-none-any.whl
| Download URL | streamlit_text_annotation-0.1.5-py3-none-any.whl |
|---|---|
| Size | 523.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3f49d7e7d023c71e698f59c8ad8139814c47536e66d1267be43f41c6e99ccaf0
|
|
BLAKE2b-256 checksum How to use checksums |
ed94cc38822f5f7bd67576a922f0a57ee44fa607c4068ff1ba66cd324b4af446
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.3
|
Security for streamlit-text-annotation 0.1.5
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.