Skip to content

A simple component to display annotated text in Streamlit apps.

Notifications You must be signed in to change notification settings

mart1nro/st-annotated-text

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Annotated Text Component for Streamlit

A simple component to display annotated text in Streamlit apps. For example:

Example image

Installation

First install Streamlit (of course!) then pip-install this library:

pip install streamlit
pip install st-annotated-text

Example

import streamlit as st
from annotated_text import annotated_text

"""
# Annotated text example

Below is an example of how to use the annotated_text function:
"""

annotated_text(
    "This ",
    ("is", "verb", "#8ef"),
    " some ",
    ("annotated", "adj", "#faa"),
    ("text", "noun", "#afa"),
    " for those of ",
    ("you", "pronoun", "#fea"),
    " who ",
    ("like", "verb", "#8ef"),
    " this sort of ",
    ("thing", "noun", "#afa"),
)

Parameters

The annotated_text() function accepts any of the following arguments:

  • strings, to draw the string as-is on the screen.
  • tuples of the form (main_text, annotation_text, background, color) where background and foreground colors are optional and should be an CSS-valid string such as "#aabbcc" or "rgb(10, 20, 30)"
  • htbuilder.HtmlElement objects in case you want to customize the annotations further. In particular, you can import the annotation() function from this module to easily produce annotations whose CSS you can customize via keyword arguments.

To-do

Just one to-do:

  • Write tests! Contributions accepted 😉

About

A simple component to display annotated text in Streamlit apps.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 86.6%
  • Makefile 13.4%