Skip to main content

A Streamlit component for interactive text annotation.

Project description

streamlit-nlp-annotator

PyPI version

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:

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

streamlit_nlp_annotator-1.1.0.tar.gz (65.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

streamlit_nlp_annotator-1.1.0-py3-none-any.whl (64.6 kB view details)

Uploaded Python 3

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

Hashes for streamlit_nlp_annotator-1.1.0.tar.gz
Algorithm Hash digest
SHA256 9fe8796cb01f9e94a1b8ecc650e15db1f55c3d42cdbdf9b979c18ba98df90043
MD5 ab2f4d4e12db34845fb93b5f73d723b9
BLAKE2b-256 042c78f26c4bbb019bea5650361e2d816e0d18be99cfbc74f7d6e840ef91cdc3

See more details on using hashes here.

File details

Details for the file streamlit_nlp_annotator-1.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for streamlit_nlp_annotator-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b33b95fb6ad89893b028e71be180c13f2f5683e172b67f2c296c5a124eaf0881
MD5 290da6f4bce26e6737098f644cbd48e1
BLAKE2b-256 364eff9941a5b63684c51312cc166fa75a4a19082e3f386423d1d315d6241e92

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page