-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstreamlit_central.py
68 lines (53 loc) · 2.19 KB
/
streamlit_central.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
'''
Boeing Proprietary.
Developed by Daniel Whyatt, Boeing AI & ML
'''
import streamlit as st
from run_newnerzero import NERTagging
# to run from command line: streamlit run streamlit_central
# tasklist | findstr streamlit
# taskkill /PID 26564 /F
# TODO: refactor to make the input path as optional, if model path is not passed in use Huggingface
@st.cache_resource
def load_model():
model_path = r"\NERStreamlit\models\nunerzero_bio"
tagger = NERTagging(model_path)
return tagger
tagger = load_model()
label_colors = {
"prod": "#CB4335", # Dark Salmon
"loc": "#33cc33", # Green
"pcon": "#33ccff", # Light Blue
"sit": "#FFD700", # Gold
"act": "#FF69B4", # Hot Pink
"bird": "#FF5733", # Orange Red
"flt": "#9370DB" # Medium Purple
}
# Function to create HTML-styled text with colors based on labels
def style_text(tokens_with_labels):
styled_sentence = ""
for token, label in tokens_with_labels:
if label in label_colors:
color = label_colors[label]
styled_sentence += f"<span style='color: {color}; font-weight: bold; font-size:20px;'>{token}</span> "
else:
styled_sentence += f"{token} "
return styled_sentence.strip()
text = st.text_input("Enter a sentence:")
if text:
labeled_text = tagger.ner_label_main(text, strip_bi=True)
styled_text = style_text(labeled_text)
st.markdown(styled_text, unsafe_allow_html=True)
st.session_state.text = ""
st.markdown("<div style='padding-top: 60px;'></div>", unsafe_allow_html=True)
# st.markdown("<h3 style='font-size:16px;'>Entity Label Colors</h3>", unsafe_allow_html=True)
st.markdown("<div style='text-align: center; font-weight: bold; font-size:20px;'>Entity Color Legend</div>", unsafe_allow_html=True)
st.markdown("<div style='text-align: center;'>", unsafe_allow_html=True)
for label, color in label_colors.items():
st.markdown(
f"<div style='text-align: center;'>"
f"<span style='color:{color}; font-weight:bold; font-size:16px;'>{label}:</span> "
f"<span style='background-color:{color}; color:white; padding:2px 8px; border-radius:3px;'>{label}</span>"
f"</div>",
unsafe_allow_html=True
)