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
    themeMode: str = "light",               # "light" or "dark"
    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.0.2.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.0.2-py3-none-any.whl (64.6 kB view details)

Uploaded Python 3

File details

Details for the file streamlit_nlp_annotator-1.0.2.tar.gz.

File metadata

  • Download URL: streamlit_nlp_annotator-1.0.2.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.0.2.tar.gz
Algorithm Hash digest
SHA256 a5d54757d1af543f4d52b98256727d2971d058e8e6aab9563c889789b2a5808a
MD5 3f6f6883c2dfec7cef8b1e58c90de85c
BLAKE2b-256 910a5c28edba750e403d0b2349c8a0914e9372570d73d9f9bbb4584170cbd823

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for streamlit_nlp_annotator-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 d5622399e4783dd6cf7dc5c66a99cddfd2c073c30caa40e1c86ee2ea053245f6
MD5 bc57aaed691db243e30aa887d6fc399c
BLAKE2b-256 b7013096aedbd0bca03c1f7ed370f6c8cdb68bc79c35bb8bba2f8b3b5371f51e

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