Spaces:
Sleeping
Sleeping
Upload streamlit_app.py
Browse files- src/streamlit_app.py +39 -10
src/streamlit_app.py
CHANGED
@@ -9,15 +9,15 @@ from transformers import AutoTokenizer, AutoModelForTokenClassification
|
|
9 |
|
10 |
# Mapping of label to color
|
11 |
LABEL_COLORS = {
|
12 |
-
'LABEL-0': '#
|
13 |
-
'LABEL-1': '#
|
14 |
-
'LABEL-2': '#
|
15 |
-
'LABEL-3': '#
|
16 |
-
'LABEL-4': '#
|
17 |
-
'LABEL-5': '#
|
18 |
-
'LABEL-6': '#
|
19 |
-
'LABEL-7': '#
|
20 |
-
'LABEL-8': '#
|
21 |
}
|
22 |
|
23 |
LABEL_MEANINGS = {
|
@@ -76,7 +76,10 @@ def colorize_entities(ner_result: List[Tuple[str, str]]) -> str:
|
|
76 |
if norm_label != 'LABEL-0':
|
77 |
color = LABEL_COLORS.get(norm_label, '#eeeeee')
|
78 |
label_meaning = LABEL_MEANINGS.get(norm_label, norm_label)
|
79 |
-
html +=
|
|
|
|
|
|
|
80 |
else:
|
81 |
html += f'{token} '
|
82 |
return html
|
@@ -116,6 +119,32 @@ def legend_html() -> str:
|
|
116 |
|
117 |
st.title('LLM-powered Named Entity Recognition (NER)')
|
118 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
119 |
st.markdown('**Legend:**')
|
120 |
st.markdown(legend_html(), unsafe_allow_html=True)
|
121 |
|
|
|
9 |
|
10 |
# Mapping of label to color
|
11 |
LABEL_COLORS = {
|
12 |
+
'LABEL-0': '#cccccc', # NONE
|
13 |
+
'LABEL-1': '#ffadad', # B-DATE
|
14 |
+
'LABEL-2': '#ffd6a5', # I-DATE
|
15 |
+
'LABEL-3': '#fdffb6', # B-TIME
|
16 |
+
'LABEL-4': '#caffbf', # I-TIME
|
17 |
+
'LABEL-5': '#9bf6ff', # B-DURATION
|
18 |
+
'LABEL-6': '#a0c4ff', # I-DURATION
|
19 |
+
'LABEL-7': '#bdb2ff', # B-SET
|
20 |
+
'LABEL-8': '#ffc6ff', # I-SET
|
21 |
}
|
22 |
|
23 |
LABEL_MEANINGS = {
|
|
|
76 |
if norm_label != 'LABEL-0':
|
77 |
color = LABEL_COLORS.get(norm_label, '#eeeeee')
|
78 |
label_meaning = LABEL_MEANINGS.get(norm_label, norm_label)
|
79 |
+
html += (
|
80 |
+
f'<span class="ner-entity" style="background-color:{color};padding:2px 4px;border-radius:4px;margin:1px;" '
|
81 |
+
f'data-tooltip="{label_meaning}">{token}</span> '
|
82 |
+
)
|
83 |
else:
|
84 |
html += f'{token} '
|
85 |
return html
|
|
|
119 |
|
120 |
st.title('LLM-powered Named Entity Recognition (NER)')
|
121 |
|
122 |
+
st.markdown(
|
123 |
+
'''
|
124 |
+
<style>
|
125 |
+
.ner-entity {
|
126 |
+
position: relative;
|
127 |
+
cursor: pointer;
|
128 |
+
}
|
129 |
+
.ner-entity[data-tooltip]:hover:after {
|
130 |
+
content: attr(data-tooltip);
|
131 |
+
position: absolute;
|
132 |
+
left: 0;
|
133 |
+
top: 100%;
|
134 |
+
background: #222;
|
135 |
+
color: #fff;
|
136 |
+
padding: 2px 8px;
|
137 |
+
border-radius: 4px;
|
138 |
+
white-space: nowrap;
|
139 |
+
z-index: 10;
|
140 |
+
font-size: 0.9em;
|
141 |
+
margin-top: 2px;
|
142 |
+
}
|
143 |
+
</style>
|
144 |
+
''',
|
145 |
+
unsafe_allow_html=True
|
146 |
+
)
|
147 |
+
|
148 |
st.markdown('**Legend:**')
|
149 |
st.markdown(legend_html(), unsafe_allow_html=True)
|
150 |
|