A Streamlit component for interactive text annotation.
Project description
streamlit-nlp-annotator
streamlit-nlp-annotator is a Streamlit component for interactive text annotation. This is especially useful for Natural Language Processing (NLP) tasks.
This component was inspired by the following works:
- st-annotated-text by @tvst
- streamlit-annotator by @EttoreCaputo
- streamlit-annotation-tools by @rmarquet21
Unlike existing tools, streamlit-nlp-annotator allows a clean inline visualization of annotations.
👀 Features
- Inline annotations with visible labels
- Span selection with mouse
- Label assignment via popup
- Editable and removable annotations
- Deterministic color mapping
- JSON-compatible output format
- Supports controlled label sets
- Optional runtime label creation
- Light/dark theme support
🎬 Demo
Live App
👉 Test it here
Preview
🛠️ Installation
pip install streamlit-nlp-annotator
🚀 Quick Start
import streamlit as st
from streamlit_nlp_annotator import annotate_text
text = "John McCarthy was born on September 4, 1927."
result = annotate_text(
text=text,
labels=["Name", "Date"],
allow_runtime_labels=True,
key="example",
)
st.write(result)
💾 Output Format
The component returns a dictionary-like structure:
{
"annotations": [
{
"id": "...",
"start": 0,
"end": 3,
"label": "Name",
"text": "John"
}
],
"labels": ["Name", "Date"],
"selection": {
"start": 26,
"end": 42,
"text": "September 4, 1927"
}
}
The above example shows the output when one part of the text has already been annotated, and another text portion has only been selected. The list of available labels is also provided.
⚙️ API
annotate_text(
text: str, # Source text to annotate
labels: list[str] | None = None, # Initial list of labels
annotations: list[dict] | None = None, # Initial annotations
allow_runtime_labels: bool = True, # Allow users to add/remove labels
readonly: bool = False, # Disable editing
colorPalette: dict | None = None, # Optional custom color palette
key: str | None = None, # Streamlit key for persistence
)
✅ Example App
streamlit run example.py
License
MIT License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file streamlit_nlp_annotator-1.1.0.tar.gz.
File metadata
- Download URL: streamlit_nlp_annotator-1.1.0.tar.gz
- Upload date:
- Size: 65.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9fe8796cb01f9e94a1b8ecc650e15db1f55c3d42cdbdf9b979c18ba98df90043
|
|
| MD5 |
ab2f4d4e12db34845fb93b5f73d723b9
|
|
| BLAKE2b-256 |
042c78f26c4bbb019bea5650361e2d816e0d18be99cfbc74f7d6e840ef91cdc3
|
File details
Details for the file streamlit_nlp_annotator-1.1.0-py3-none-any.whl.
File metadata
- Download URL: streamlit_nlp_annotator-1.1.0-py3-none-any.whl
- Upload date:
- Size: 64.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b33b95fb6ad89893b028e71be180c13f2f5683e172b67f2c296c5a124eaf0881
|
|
| MD5 |
290da6f4bce26e6737098f644cbd48e1
|
|
| BLAKE2b-256 |
364eff9941a5b63684c51312cc166fa75a4a19082e3f386423d1d315d6241e92
|