Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +47 -28
src/streamlit_app.py
CHANGED
@@ -13,46 +13,54 @@ from typing import Optional
|
|
13 |
from gliner import GLiNER
|
14 |
from comet_ml import Experiment
|
15 |
|
|
|
|
|
16 |
st.markdown(
|
17 |
"""
|
18 |
<style>
|
19 |
/* Main app background and text color */
|
20 |
.stApp {
|
21 |
-
background-color: #
|
22 |
color: #000000; /* Black for the text */
|
23 |
}
|
|
|
24 |
/* Sidebar background color */
|
25 |
.css-1d36184 {
|
26 |
-
background-color: #
|
27 |
-
secondary-background-color: #
|
28 |
}
|
29 |
-
|
30 |
/* Expander background color */
|
31 |
.streamlit-expanderContent {
|
32 |
-
background-color: #
|
33 |
}
|
|
|
34 |
/* Expander header background color */
|
35 |
.streamlit-expanderHeader {
|
36 |
-
background-color: #
|
37 |
}
|
|
|
38 |
/* Text Area background and text color */
|
39 |
.stTextArea textarea {
|
40 |
-
background-color: #
|
41 |
color: #000000; /* Black for text */
|
42 |
}
|
|
|
43 |
/* Button background and text color */
|
44 |
.stButton > button {
|
45 |
-
background-color: #
|
46 |
color: #000000;
|
47 |
}
|
|
|
48 |
/* Warning box background and text color */
|
49 |
.stAlert.st-warning {
|
50 |
-
background-color: #
|
51 |
color: #000000;
|
52 |
}
|
|
|
53 |
/* Success box background and text color */
|
54 |
.stAlert.st-success {
|
55 |
-
background-color: #
|
56 |
color: #000000;
|
57 |
}
|
58 |
</style>
|
@@ -60,34 +68,45 @@ st.markdown(
|
|
60 |
unsafe_allow_html=True
|
61 |
)
|
62 |
|
|
|
|
|
|
|
|
|
63 |
# --- Page Configuration and UI Elements ---
|
64 |
st.set_page_config(layout="wide", page_title="Named Entity Recognition App")
|
65 |
-
st.subheader("StoryCraft", divider="
|
66 |
st.link_button("by nlpblogs", "https://nlpblogs.com", type="tertiary")
|
67 |
expander = st.expander("**Important notes**")
|
68 |
-
expander.write("""**Named Entities:** This HR.ai predicts
|
|
|
69 |
Results are presented in easy-to-read tables, visualized in an interactive tree map, pie chart and bar chart, and are available for download along with a Glossary of tags.
|
|
|
70 |
**How to Use:** Type or paste your text into the text area below, then press Ctrl + Enter. Click the 'Results' button to extract and tag entities in your text data.
|
|
|
71 |
**Usage Limits:** You can request results unlimited times for one (1) month.
|
|
|
72 |
**Supported Languages:** English
|
|
|
73 |
**Technical issues:** If your connection times out, please refresh the page or reopen the app's URL.
|
|
|
74 |
For any errors or inquiries, please contact us at [email protected]""")
|
75 |
|
76 |
with st.sidebar:
|
77 |
-
st.write("Use the following code to embed the
|
78 |
code = '''
|
79 |
-
|
80 |
-
src="https://aiecosystem-
|
81 |
frameborder="0"
|
82 |
width="850"
|
83 |
height="450"
|
84 |
></iframe>
|
|
|
85 |
'''
|
86 |
st.code(code, language="html")
|
87 |
st.text("")
|
88 |
st.text("")
|
89 |
st.divider()
|
90 |
-
st.subheader("🚀 Ready to build your own NER Web App?", divider="
|
91 |
st.link_button("NER Builder", "https://nlpblogs.com", type="primary")
|
92 |
|
93 |
# --- Comet ML Setup ---
|
@@ -156,7 +175,7 @@ if st.button("Results"):
|
|
156 |
experiment.log_parameter("input_text", text)
|
157 |
experiment.log_table("predicted_entities", df)
|
158 |
|
159 |
-
st.subheader("Grouped Entities by Category", divider = "
|
160 |
|
161 |
# Create tabs for each category
|
162 |
category_names = sorted(list(category_mapping.keys()))
|
@@ -184,9 +203,9 @@ if st.button("Results"):
|
|
184 |
st.divider()
|
185 |
|
186 |
# Tree map
|
187 |
-
st.subheader("Tree map", divider = "
|
188 |
fig_treemap = px.treemap(df, path=[px.Constant("all"), 'category', 'label', 'text'], values='score', color='category')
|
189 |
-
fig_treemap.update_layout(margin=dict(t=50, l=25, r=25, b=25), paper_bgcolor='#
|
190 |
st.plotly_chart(fig_treemap)
|
191 |
|
192 |
# Pie and Bar charts
|
@@ -195,26 +214,26 @@ if st.button("Results"):
|
|
195 |
col1, col2 = st.columns(2)
|
196 |
|
197 |
with col1:
|
198 |
-
st.subheader("Pie chart", divider = "
|
199 |
fig_pie = px.pie(grouped_counts, values='count', names='category', hover_data=['count'], labels={'count': 'count'}, title='Percentage of predicted categories')
|
200 |
fig_pie.update_traces(textposition='inside', textinfo='percent+label')
|
201 |
fig_pie.update_layout(
|
202 |
-
paper_bgcolor='#
|
203 |
-
plot_bgcolor='#
|
204 |
)
|
205 |
st.plotly_chart(fig_pie)
|
206 |
|
207 |
with col2:
|
208 |
-
st.subheader("Bar chart", divider = "
|
209 |
fig_bar = px.bar(grouped_counts, x="count", y="category", color="category", text_auto=True, title='Occurrences of predicted categories')
|
210 |
fig_pie.update_layout(
|
211 |
-
paper_bgcolor='#
|
212 |
-
plot_bgcolor='#
|
213 |
)
|
214 |
st.plotly_chart(fig_bar)
|
215 |
|
216 |
# Most Frequent Entities
|
217 |
-
st.subheader("Most Frequent Entities", divider="
|
218 |
word_counts = df['text'].value_counts().reset_index()
|
219 |
word_counts.columns = ['Entity', 'Count']
|
220 |
repeating_entities = word_counts[word_counts['Count'] > 1]
|
@@ -222,8 +241,8 @@ if st.button("Results"):
|
|
222 |
st.dataframe(repeating_entities, use_container_width=True)
|
223 |
fig_repeating_bar = px.bar(repeating_entities, x='Entity', y='Count', color='Entity')
|
224 |
fig_repeating_bar.update_layout(xaxis={'categoryorder': 'total descending'},
|
225 |
-
paper_bgcolor='#
|
226 |
-
plot_bgcolor='#
|
227 |
st.plotly_chart(fig_repeating_bar)
|
228 |
else:
|
229 |
st.warning("No entities were found that occur more than once.")
|
|
|
13 |
from gliner import GLiNER
|
14 |
from comet_ml import Experiment
|
15 |
|
16 |
+
|
17 |
+
|
18 |
st.markdown(
|
19 |
"""
|
20 |
<style>
|
21 |
/* Main app background and text color */
|
22 |
.stApp {
|
23 |
+
background-color: #E0FFFF; /* Light cyan, a very pale blue */
|
24 |
color: #000000; /* Black for the text */
|
25 |
}
|
26 |
+
|
27 |
/* Sidebar background color */
|
28 |
.css-1d36184 {
|
29 |
+
background-color: #ADD8E6; /* Light blue for the sidebar */
|
30 |
+
secondary-background-color: #ADD8E6;
|
31 |
}
|
32 |
+
|
33 |
/* Expander background color */
|
34 |
.streamlit-expanderContent {
|
35 |
+
background-color: #E0FFFF;
|
36 |
}
|
37 |
+
|
38 |
/* Expander header background color */
|
39 |
.streamlit-expanderHeader {
|
40 |
+
background-color: #E0FFFF;
|
41 |
}
|
42 |
+
|
43 |
/* Text Area background and text color */
|
44 |
.stTextArea textarea {
|
45 |
+
background-color: #B0E0E6; /* Powder blue, a light, soft blue */
|
46 |
color: #000000; /* Black for text */
|
47 |
}
|
48 |
+
|
49 |
/* Button background and text color */
|
50 |
.stButton > button {
|
51 |
+
background-color: #B0E0E6;
|
52 |
color: #000000;
|
53 |
}
|
54 |
+
|
55 |
/* Warning box background and text color */
|
56 |
.stAlert.st-warning {
|
57 |
+
background-color: #87CEEB; /* Sky blue for the warning box */
|
58 |
color: #000000;
|
59 |
}
|
60 |
+
|
61 |
/* Success box background and text color */
|
62 |
.stAlert.st-success {
|
63 |
+
background-color: #87CEEB; /* Sky blue for the success box */
|
64 |
color: #000000;
|
65 |
}
|
66 |
</style>
|
|
|
68 |
unsafe_allow_html=True
|
69 |
)
|
70 |
|
71 |
+
|
72 |
+
|
73 |
+
|
74 |
+
|
75 |
# --- Page Configuration and UI Elements ---
|
76 |
st.set_page_config(layout="wide", page_title="Named Entity Recognition App")
|
77 |
+
st.subheader("StoryCraft", divider="blue")
|
78 |
st.link_button("by nlpblogs", "https://nlpblogs.com", type="tertiary")
|
79 |
expander = st.expander("**Important notes**")
|
80 |
+
expander.write("""**Named Entities:** This HR.ai predicts eighteen (18) labels: "Person","Organization","Location","Date","Time","Quantity","Product","Event","Title","Job_title","Artwork","Media", "URL","Website","Hashtag","Email_address","IP_address","File_path"
|
81 |
+
|
82 |
Results are presented in easy-to-read tables, visualized in an interactive tree map, pie chart and bar chart, and are available for download along with a Glossary of tags.
|
83 |
+
|
84 |
**How to Use:** Type or paste your text into the text area below, then press Ctrl + Enter. Click the 'Results' button to extract and tag entities in your text data.
|
85 |
+
|
86 |
**Usage Limits:** You can request results unlimited times for one (1) month.
|
87 |
+
|
88 |
**Supported Languages:** English
|
89 |
+
|
90 |
**Technical issues:** If your connection times out, please refresh the page or reopen the app's URL.
|
91 |
+
|
92 |
For any errors or inquiries, please contact us at [email protected]""")
|
93 |
|
94 |
with st.sidebar:
|
95 |
+
st.write("Use the following code to embed the StoryCraft web app on your website. Feel free to adjust the width and height values to fit your page.")
|
96 |
code = '''
|
97 |
+
<iframe
|
98 |
+
src="https://aiecosystem-storycraft.hf.space"
|
99 |
frameborder="0"
|
100 |
width="850"
|
101 |
height="450"
|
102 |
></iframe>
|
103 |
+
|
104 |
'''
|
105 |
st.code(code, language="html")
|
106 |
st.text("")
|
107 |
st.text("")
|
108 |
st.divider()
|
109 |
+
st.subheader("🚀 Ready to build your own NER Web App?", divider="blue")
|
110 |
st.link_button("NER Builder", "https://nlpblogs.com", type="primary")
|
111 |
|
112 |
# --- Comet ML Setup ---
|
|
|
175 |
experiment.log_parameter("input_text", text)
|
176 |
experiment.log_table("predicted_entities", df)
|
177 |
|
178 |
+
st.subheader("Grouped Entities by Category", divider = "blue")
|
179 |
|
180 |
# Create tabs for each category
|
181 |
category_names = sorted(list(category_mapping.keys()))
|
|
|
203 |
st.divider()
|
204 |
|
205 |
# Tree map
|
206 |
+
st.subheader("Tree map", divider = "blue")
|
207 |
fig_treemap = px.treemap(df, path=[px.Constant("all"), 'category', 'label', 'text'], values='score', color='category')
|
208 |
+
fig_treemap.update_layout(margin=dict(t=50, l=25, r=25, b=25), paper_bgcolor='#E0FFFF', plot_bgcolor='#E0FFFF')
|
209 |
st.plotly_chart(fig_treemap)
|
210 |
|
211 |
# Pie and Bar charts
|
|
|
214 |
col1, col2 = st.columns(2)
|
215 |
|
216 |
with col1:
|
217 |
+
st.subheader("Pie chart", divider = "blue")
|
218 |
fig_pie = px.pie(grouped_counts, values='count', names='category', hover_data=['count'], labels={'count': 'count'}, title='Percentage of predicted categories')
|
219 |
fig_pie.update_traces(textposition='inside', textinfo='percent+label')
|
220 |
fig_pie.update_layout(
|
221 |
+
paper_bgcolor='#E0FFFF',
|
222 |
+
plot_bgcolor='#E0FFFF'
|
223 |
)
|
224 |
st.plotly_chart(fig_pie)
|
225 |
|
226 |
with col2:
|
227 |
+
st.subheader("Bar chart", divider = "blue")
|
228 |
fig_bar = px.bar(grouped_counts, x="count", y="category", color="category", text_auto=True, title='Occurrences of predicted categories')
|
229 |
fig_pie.update_layout(
|
230 |
+
paper_bgcolor='#E0FFFF',
|
231 |
+
plot_bgcolor='#E0FFFF'
|
232 |
)
|
233 |
st.plotly_chart(fig_bar)
|
234 |
|
235 |
# Most Frequent Entities
|
236 |
+
st.subheader("Most Frequent Entities", divider="blue")
|
237 |
word_counts = df['text'].value_counts().reset_index()
|
238 |
word_counts.columns = ['Entity', 'Count']
|
239 |
repeating_entities = word_counts[word_counts['Count'] > 1]
|
|
|
241 |
st.dataframe(repeating_entities, use_container_width=True)
|
242 |
fig_repeating_bar = px.bar(repeating_entities, x='Entity', y='Count', color='Entity')
|
243 |
fig_repeating_bar.update_layout(xaxis={'categoryorder': 'total descending'},
|
244 |
+
paper_bgcolor='#E0FFFF',
|
245 |
+
plot_bgcolor='#E0FFFF')
|
246 |
st.plotly_chart(fig_repeating_bar)
|
247 |
else:
|
248 |
st.warning("No entities were found that occur more than once.")
|