File size: 1,852 Bytes
4b75840
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import streamlit as st
from text_annotation_utils import *

def annotated_text(*args, type=None):
    """Writes text with annotations into your Streamlit app.
    Parameters
    ----------
    *args : str, tuple or htbuilder.HtmlElement
        Arguments can be:
        - 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)"
        - 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.
    Examples
    --------
    # >>> 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"),
    # ... )
    # >>> annotated_text(
    # ...     "Hello ",
    # ...     annotation("world!", "noun", color="#8ef", border="1px dashed red"),
    # ... )
    """
    if type == 'title':
        st.markdown(
            '<p class="big-font">' + get_annotated_html(*args)+ '</p>',
            unsafe_allow_html=True,
        )
    if type == 'description':
        st.markdown(
            '<p class="medium-font">' + get_annotated_html(*args) + '</p>',
            unsafe_allow_html=True,
        )
    else:
        st.markdown(
            get_annotated_html(*args),
            unsafe_allow_html=True,
        )