Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +37 -32
src/streamlit_app.py
CHANGED
|
@@ -19,40 +19,40 @@ st.markdown(
|
|
| 19 |
<style>
|
| 20 |
/* Main app background and text color */
|
| 21 |
.stApp {
|
| 22 |
-
background-color: #
|
| 23 |
-
color: #
|
| 24 |
}
|
| 25 |
/* Sidebar background color */
|
| 26 |
.css-1d36184 {
|
| 27 |
-
background-color: #
|
| 28 |
-
secondary-background-color: #
|
| 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: #
|
| 42 |
}
|
| 43 |
/* Button background and text color */
|
| 44 |
.stButton > button {
|
| 45 |
-
background-color: #
|
| 46 |
-
color: #
|
| 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>
|
|
@@ -61,26 +61,31 @@ st.markdown(
|
|
| 61 |
)
|
| 62 |
|
| 63 |
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
# --- Page Configuration and UI Elements ---
|
| 70 |
st.set_page_config(layout="wide", page_title="Named Entity Recognition App")
|
| 71 |
-
st.subheader("Multilingual", divider="
|
| 72 |
st.link_button("by nlpblogs", "https://nlpblogs.com", type="tertiary")
|
| 73 |
expander = st.expander("**Important notes**")
|
| 74 |
-
|
|
|
|
|
|
|
|
|
|
| 75 |
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.
|
|
|
|
| 76 |
**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.
|
|
|
|
| 77 |
**Usage Limits:** You can request results unlimited times for one (1) month.
|
| 78 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
**Technical issues:** If your connection times out, please refresh the page or reopen the app's URL.
|
|
|
|
| 80 |
For any errors or inquiries, please contact us at info@nlpblogs.com""")
|
| 81 |
|
| 82 |
with st.sidebar:
|
| 83 |
-
st.write("Use the following code to embed the
|
| 84 |
code = '''
|
| 85 |
<iframe
|
| 86 |
src="https://aiecosystem-business-core.hf.space"
|
|
@@ -207,7 +212,7 @@ if st.button("Results"):
|
|
| 207 |
experiment.log_parameter("input_text", text)
|
| 208 |
experiment.log_table("predicted_entities", df)
|
| 209 |
|
| 210 |
-
st.subheader("Grouped Entities by Category", divider = "
|
| 211 |
|
| 212 |
# Create tabs for each category
|
| 213 |
category_names = sorted(list(category_mapping.keys()))
|
|
@@ -235,7 +240,7 @@ if st.button("Results"):
|
|
| 235 |
st.divider()
|
| 236 |
|
| 237 |
# Tree map
|
| 238 |
-
st.subheader("Tree map", divider = "
|
| 239 |
fig_treemap = px.treemap(df, path=[px.Constant("all"), 'category', 'label', 'text'], values='score', color='category')
|
| 240 |
fig_treemap.update_layout(margin=dict(t=50, l=25, r=25, b=25), paper_bgcolor='#FFF8F0', plot_bgcolor='#FFF8F0')
|
| 241 |
st.plotly_chart(fig_treemap)
|
|
@@ -246,26 +251,26 @@ if st.button("Results"):
|
|
| 246 |
col1, col2 = st.columns(2)
|
| 247 |
|
| 248 |
with col1:
|
| 249 |
-
st.subheader("Pie chart", divider = "
|
| 250 |
fig_pie = px.pie(grouped_counts, values='count', names='category', hover_data=['count'], labels={'count': 'count'}, title='Percentage of predicted categories')
|
| 251 |
fig_pie.update_traces(textposition='inside', textinfo='percent+label')
|
| 252 |
fig_pie.update_layout(
|
| 253 |
-
paper_bgcolor='#
|
| 254 |
-
plot_bgcolor='#
|
| 255 |
)
|
| 256 |
st.plotly_chart(fig_pie)
|
| 257 |
|
| 258 |
with col2:
|
| 259 |
-
st.subheader("Bar chart", divider = "
|
| 260 |
fig_bar = px.bar(grouped_counts, x="count", y="category", color="category", text_auto=True, title='Occurrences of predicted categories')
|
| 261 |
fig_bar.update_layout(
|
| 262 |
-
paper_bgcolor='#
|
| 263 |
-
plot_bgcolor='#
|
| 264 |
)
|
| 265 |
st.plotly_chart(fig_bar)
|
| 266 |
|
| 267 |
# Most Frequent Entities
|
| 268 |
-
st.subheader("Most Frequent Entities", divider="
|
| 269 |
word_counts = df['text'].value_counts().reset_index()
|
| 270 |
word_counts.columns = ['Entity', 'Count']
|
| 271 |
repeating_entities = word_counts[word_counts['Count'] > 1]
|
|
@@ -273,8 +278,8 @@ if st.button("Results"):
|
|
| 273 |
st.dataframe(repeating_entities, use_container_width=True)
|
| 274 |
fig_repeating_bar = px.bar(repeating_entities, x='Entity', y='Count', color='Entity')
|
| 275 |
fig_repeating_bar.update_layout(xaxis={'categoryorder': 'total descending'},
|
| 276 |
-
paper_bgcolor='#
|
| 277 |
-
plot_bgcolor='#
|
| 278 |
st.plotly_chart(fig_repeating_bar)
|
| 279 |
else:
|
| 280 |
st.warning("No entities were found that occur more than once.")
|
|
|
|
| 19 |
<style>
|
| 20 |
/* Main app background and text color */
|
| 21 |
.stApp {
|
| 22 |
+
background-color: #F0F2F5; /* A very light gray */
|
| 23 |
+
color: #333333; /* Dark gray for text */
|
| 24 |
}
|
| 25 |
/* Sidebar background color */
|
| 26 |
.css-1d36184 {
|
| 27 |
+
background-color: #B0C4DE; /* A soft, slate blue for the sidebar */
|
| 28 |
+
secondary-background-color: #B0C4DE;
|
| 29 |
}
|
| 30 |
/* Expander background color */
|
| 31 |
.streamlit-expanderContent {
|
| 32 |
+
background-color: #F0F2F5;
|
| 33 |
}
|
| 34 |
/* Expander header background color */
|
| 35 |
.streamlit-expanderHeader {
|
| 36 |
+
background-color: #F0F2F5;
|
| 37 |
}
|
| 38 |
/* Text Area background and text color */
|
| 39 |
.stTextArea textarea {
|
| 40 |
+
background-color: #FFFFFF; /* White background */
|
| 41 |
+
color: #333333; /* Dark gray for text */
|
| 42 |
}
|
| 43 |
/* Button background and text color */
|
| 44 |
.stButton > button {
|
| 45 |
+
background-color: #6495ED; /* A bright, cornflower blue */
|
| 46 |
+
color: #FFFFFF; /* White text */
|
| 47 |
}
|
| 48 |
/* Warning box background and text color */
|
| 49 |
.stAlert.st-warning {
|
| 50 |
+
background-color: #FFD700; /* A gold color for warnings */
|
| 51 |
color: #000000;
|
| 52 |
}
|
| 53 |
/* Success box background and text color */
|
| 54 |
.stAlert.st-success {
|
| 55 |
+
background-color: #90EE90; /* A light green for success */
|
| 56 |
color: #000000;
|
| 57 |
}
|
| 58 |
</style>
|
|
|
|
| 61 |
)
|
| 62 |
|
| 63 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
# --- Page Configuration and UI Elements ---
|
| 65 |
st.set_page_config(layout="wide", page_title="Named Entity Recognition App")
|
| 66 |
+
st.subheader("Multilingual", divider="green")
|
| 67 |
st.link_button("by nlpblogs", "https://nlpblogs.com", type="tertiary")
|
| 68 |
expander = st.expander("**Important notes**")
|
| 69 |
+
|
| 70 |
+
expander.write("""**Named Entities:** This Multilingual predicts twenty-six (26) labels:
|
| 71 |
+
"Person","First_name","Last_name","Title","Job_title","Affiliation","Gender","Age","Date","Nationality","Location","City","Country", "Role","Relationship"
|
| 72 |
+
|
| 73 |
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.
|
| 74 |
+
|
| 75 |
**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.
|
| 76 |
+
|
| 77 |
**Usage Limits:** You can request results unlimited times for one (1) month.
|
| 78 |
+
|
| 79 |
+
**Supported Languages:** English
|
| 80 |
+
|
| 81 |
+
**Language settings:** Please check and adjust the language settings in your computer, so the characters of your chosen language are handled properly in your downloaded file.
|
| 82 |
+
|
| 83 |
**Technical issues:** If your connection times out, please refresh the page or reopen the app's URL.
|
| 84 |
+
|
| 85 |
For any errors or inquiries, please contact us at info@nlpblogs.com""")
|
| 86 |
|
| 87 |
with st.sidebar:
|
| 88 |
+
st.write("Use the following code to embed the Multilingual web app on your website. Feel free to adjust the width and height values to fit your page.")
|
| 89 |
code = '''
|
| 90 |
<iframe
|
| 91 |
src="https://aiecosystem-business-core.hf.space"
|
|
|
|
| 212 |
experiment.log_parameter("input_text", text)
|
| 213 |
experiment.log_table("predicted_entities", df)
|
| 214 |
|
| 215 |
+
st.subheader("Grouped Entities by Category", divider = "green")
|
| 216 |
|
| 217 |
# Create tabs for each category
|
| 218 |
category_names = sorted(list(category_mapping.keys()))
|
|
|
|
| 240 |
st.divider()
|
| 241 |
|
| 242 |
# Tree map
|
| 243 |
+
st.subheader("Tree map", divider = "green")
|
| 244 |
fig_treemap = px.treemap(df, path=[px.Constant("all"), 'category', 'label', 'text'], values='score', color='category')
|
| 245 |
fig_treemap.update_layout(margin=dict(t=50, l=25, r=25, b=25), paper_bgcolor='#FFF8F0', plot_bgcolor='#FFF8F0')
|
| 246 |
st.plotly_chart(fig_treemap)
|
|
|
|
| 251 |
col1, col2 = st.columns(2)
|
| 252 |
|
| 253 |
with col1:
|
| 254 |
+
st.subheader("Pie chart", divider = "green")
|
| 255 |
fig_pie = px.pie(grouped_counts, values='count', names='category', hover_data=['count'], labels={'count': 'count'}, title='Percentage of predicted categories')
|
| 256 |
fig_pie.update_traces(textposition='inside', textinfo='percent+label')
|
| 257 |
fig_pie.update_layout(
|
| 258 |
+
paper_bgcolor='#F0F2F5',
|
| 259 |
+
plot_bgcolor='#F0F2F5'
|
| 260 |
)
|
| 261 |
st.plotly_chart(fig_pie)
|
| 262 |
|
| 263 |
with col2:
|
| 264 |
+
st.subheader("Bar chart", divider = "green")
|
| 265 |
fig_bar = px.bar(grouped_counts, x="count", y="category", color="category", text_auto=True, title='Occurrences of predicted categories')
|
| 266 |
fig_bar.update_layout(
|
| 267 |
+
paper_bgcolor='#F0F2F5',
|
| 268 |
+
plot_bgcolor='#F0F2F5'
|
| 269 |
)
|
| 270 |
st.plotly_chart(fig_bar)
|
| 271 |
|
| 272 |
# Most Frequent Entities
|
| 273 |
+
st.subheader("Most Frequent Entities", divider="green")
|
| 274 |
word_counts = df['text'].value_counts().reset_index()
|
| 275 |
word_counts.columns = ['Entity', 'Count']
|
| 276 |
repeating_entities = word_counts[word_counts['Count'] > 1]
|
|
|
|
| 278 |
st.dataframe(repeating_entities, use_container_width=True)
|
| 279 |
fig_repeating_bar = px.bar(repeating_entities, x='Entity', y='Count', color='Entity')
|
| 280 |
fig_repeating_bar.update_layout(xaxis={'categoryorder': 'total descending'},
|
| 281 |
+
paper_bgcolor='#F0F2F5',
|
| 282 |
+
plot_bgcolor='#F0F2F5')
|
| 283 |
st.plotly_chart(fig_repeating_bar)
|
| 284 |
else:
|
| 285 |
st.warning("No entities were found that occur more than once.")
|