-
Notifications
You must be signed in to change notification settings - Fork 41
/
example.py
137 lines (104 loc) · 2.64 KB
/
example.py
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import streamlit as st
from annotated_text import annotated_text
st.set_page_config(page_title="Annotated Text", page_icon="📝")
"""
# 📝 Annotated Text
This app shows off the [Annotated Text component](https://github.com/tvst/st-annotated-text) for
Streamlit.
If you want to try this at home, you'll first need to install it:
```python
pip install st-annotated-text
```
## Basic example
Annotations are just tuples:
"""
with st.echo():
from annotated_text import annotated_text
annotated_text(
"This ",
("is", "Verb"),
" some ",
("annotated", "Adj"),
("text", "Noun"),
" for those of ",
("you", "Pronoun"),
" who ",
("like", "Verb"),
" this sort of ",
("thing", "Noun"),
". ",
"And here's a ",
("word", ""),
" with a fancy background but no label.",
)
""
"""
## Nested arguments
You can also pass lists (and lists within lists!) as an argument:
"""
with st.echo():
my_list = [
"Hello ",
[
"my ",
("dear", "Adj"),
" ",
],
("world", "Noun"),
".",
]
annotated_text(my_list)
""
""
"""
## Customization
"""
"""
### Custom colors
If the annotation tuple has more than 2 items, the 3rd will be used as the background color and the 4th as the foreground color:
"""
with st.echo():
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"),
". "
"And here's a ",
("word", "", "#faf"),
" with a fancy background but no label.",
)
""
""
"""
### Custom styles
You can customize a bunch of different styles by overriding the variables
set in the `annotated_text.parameters` module. For example:
```python
from annotated_text import annotated_text, parameters
parameters.SHOW_LABEL_SEPARATOR = False
parameters.BORDER_RADIUS = 0
parameters.PADDING = "0 0.25rem"
```
For more configurable parameters, see the
[parameters.py source file](https://github.com/tvst/st-annotated-text/blob/master/annotated_text/parameters.py).
"""
""
""
"""
### Even more customization
If you want to go beyond the customizations above, you can bring your own CSS!
"""
with st.echo():
from annotated_text import annotated_text, annotation
annotated_text(
"Hello ",
annotation("world!", "noun", font_family="Comic Sans MS", border="2px dashed red"),
)