Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +22 -20
src/streamlit_app.py
CHANGED
|
@@ -75,15 +75,21 @@ st.markdown(
|
|
| 75 |
|
| 76 |
# --- Page Configuration and UI Elements ---
|
| 77 |
st.set_page_config(layout="wide", page_title="Named Entity Recognition App")
|
| 78 |
-
st.subheader("Business Core", divider="
|
| 79 |
st.link_button("by nlpblogs", "https://nlpblogs.com", type="tertiary")
|
| 80 |
expander = st.expander("**Important notes**")
|
| 81 |
-
expander.write("""**Named Entities:** This
|
|
|
|
| 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 |
**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.
|
|
|
|
| 84 |
**Usage Limits:** You can request results unlimited times for one (1) month.
|
|
|
|
| 85 |
**Supported Languages:** English
|
| 86 |
-
|
|
|
|
|
|
|
| 87 |
For any errors or inquiries, please contact us at info@nlpblogs.com""")
|
| 88 |
|
| 89 |
with st.sidebar:
|
|
@@ -100,7 +106,7 @@ with st.sidebar:
|
|
| 100 |
st.text("")
|
| 101 |
st.text("")
|
| 102 |
st.divider()
|
| 103 |
-
st.subheader("🚀 Ready to build your own NER Web App?", divider="
|
| 104 |
st.link_button("NER Builder", "https://nlpblogs.com", type="primary")
|
| 105 |
|
| 106 |
# --- Comet ML Setup ---
|
|
@@ -163,10 +169,6 @@ category_mapping = {
|
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
# --- Model Loading ---
|
| 171 |
@st.cache_resource
|
| 172 |
def load_ner_model():
|
|
@@ -212,7 +214,7 @@ if st.button("Results"):
|
|
| 212 |
experiment.log_parameter("input_text", text)
|
| 213 |
experiment.log_table("predicted_entities", df)
|
| 214 |
|
| 215 |
-
st.subheader("Grouped Entities by Category", divider = "
|
| 216 |
|
| 217 |
# Create tabs for each category
|
| 218 |
category_names = sorted(list(category_mapping.keys()))
|
|
@@ -240,9 +242,9 @@ if st.button("Results"):
|
|
| 240 |
st.divider()
|
| 241 |
|
| 242 |
# Tree map
|
| 243 |
-
st.subheader("Tree map", divider = "
|
| 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='#
|
| 246 |
st.plotly_chart(fig_treemap)
|
| 247 |
|
| 248 |
# Pie and Bar charts
|
|
@@ -251,26 +253,26 @@ if st.button("Results"):
|
|
| 251 |
col1, col2 = st.columns(2)
|
| 252 |
|
| 253 |
with col1:
|
| 254 |
-
st.subheader("Pie chart", divider = "
|
| 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='#
|
| 259 |
-
plot_bgcolor='#
|
| 260 |
)
|
| 261 |
st.plotly_chart(fig_pie)
|
| 262 |
|
| 263 |
with col2:
|
| 264 |
-
st.subheader("Bar chart", divider = "
|
| 265 |
fig_bar = px.bar(grouped_counts, x="count", y="category", color="category", text_auto=True, title='Occurrences of predicted categories')
|
| 266 |
fig_pie.update_layout(
|
| 267 |
-
paper_bgcolor='#
|
| 268 |
-
plot_bgcolor='#
|
| 269 |
)
|
| 270 |
st.plotly_chart(fig_bar)
|
| 271 |
|
| 272 |
# Most Frequent Entities
|
| 273 |
-
st.subheader("Most Frequent Entities", divider="
|
| 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,8 +280,8 @@ if st.button("Results"):
|
|
| 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='#
|
| 282 |
-
plot_bgcolor='#
|
| 283 |
st.plotly_chart(fig_repeating_bar)
|
| 284 |
else:
|
| 285 |
st.warning("No entities were found that occur more than once.")
|
|
|
|
| 75 |
|
| 76 |
# --- Page Configuration and UI Elements ---
|
| 77 |
st.set_page_config(layout="wide", page_title="Named Entity Recognition App")
|
| 78 |
+
st.subheader("Business Core", divider="orange")
|
| 79 |
st.link_button("by nlpblogs", "https://nlpblogs.com", type="tertiary")
|
| 80 |
expander = st.expander("**Important notes**")
|
| 81 |
+
expander.write("""**Named Entities:** This Business Core predicts twenty-six (26) labels: "Person", "Contact", "Company", "Department", "Vendor", "Client", "Office", "Warehouse", "Address", "City", "State", "Country", "Date", "Time", "Time Period", "Revenue", "Cost", "Budget", "Invoice Number", "Product", "Service", "Task", "Project", "Status", "Asset", "Transaction"
|
| 82 |
+
|
| 83 |
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.
|
| 84 |
+
|
| 85 |
**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.
|
| 86 |
+
|
| 87 |
**Usage Limits:** You can request results unlimited times for one (1) month.
|
| 88 |
+
|
| 89 |
**Supported Languages:** English
|
| 90 |
+
|
| 91 |
+
*Technical issues:** If your connection times out, please refresh the page or reopen the app's URL.
|
| 92 |
+
|
| 93 |
For any errors or inquiries, please contact us at info@nlpblogs.com""")
|
| 94 |
|
| 95 |
with st.sidebar:
|
|
|
|
| 106 |
st.text("")
|
| 107 |
st.text("")
|
| 108 |
st.divider()
|
| 109 |
+
st.subheader("🚀 Ready to build your own NER Web App?", divider="orange")
|
| 110 |
st.link_button("NER Builder", "https://nlpblogs.com", type="primary")
|
| 111 |
|
| 112 |
# --- Comet ML Setup ---
|
|
|
|
| 169 |
|
| 170 |
|
| 171 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 172 |
# --- Model Loading ---
|
| 173 |
@st.cache_resource
|
| 174 |
def load_ner_model():
|
|
|
|
| 214 |
experiment.log_parameter("input_text", text)
|
| 215 |
experiment.log_table("predicted_entities", df)
|
| 216 |
|
| 217 |
+
st.subheader("Grouped Entities by Category", divider = "orange")
|
| 218 |
|
| 219 |
# Create tabs for each category
|
| 220 |
category_names = sorted(list(category_mapping.keys()))
|
|
|
|
| 242 |
st.divider()
|
| 243 |
|
| 244 |
# Tree map
|
| 245 |
+
st.subheader("Tree map", divider = "orange")
|
| 246 |
fig_treemap = px.treemap(df, path=[px.Constant("all"), 'category', 'label', 'text'], values='score', color='category')
|
| 247 |
+
fig_treemap.update_layout(margin=dict(t=50, l=25, r=25, b=25), paper_bgcolor='#FFF8F0', plot_bgcolor='#FFF8F0')
|
| 248 |
st.plotly_chart(fig_treemap)
|
| 249 |
|
| 250 |
# Pie and Bar charts
|
|
|
|
| 253 |
col1, col2 = st.columns(2)
|
| 254 |
|
| 255 |
with col1:
|
| 256 |
+
st.subheader("Pie chart", divider = "orange")
|
| 257 |
fig_pie = px.pie(grouped_counts, values='count', names='category', hover_data=['count'], labels={'count': 'count'}, title='Percentage of predicted categories')
|
| 258 |
fig_pie.update_traces(textposition='inside', textinfo='percent+label')
|
| 259 |
fig_pie.update_layout(
|
| 260 |
+
paper_bgcolor='#FFF8F0',
|
| 261 |
+
plot_bgcolor='#FFF8F0'
|
| 262 |
)
|
| 263 |
st.plotly_chart(fig_pie)
|
| 264 |
|
| 265 |
with col2:
|
| 266 |
+
st.subheader("Bar chart", divider = "orange")
|
| 267 |
fig_bar = px.bar(grouped_counts, x="count", y="category", color="category", text_auto=True, title='Occurrences of predicted categories')
|
| 268 |
fig_pie.update_layout(
|
| 269 |
+
paper_bgcolor='#FFF8F0',
|
| 270 |
+
plot_bgcolor='#FFF8F0'
|
| 271 |
)
|
| 272 |
st.plotly_chart(fig_bar)
|
| 273 |
|
| 274 |
# Most Frequent Entities
|
| 275 |
+
st.subheader("Most Frequent Entities", divider="orange")
|
| 276 |
word_counts = df['text'].value_counts().reset_index()
|
| 277 |
word_counts.columns = ['Entity', 'Count']
|
| 278 |
repeating_entities = word_counts[word_counts['Count'] > 1]
|
|
|
|
| 280 |
st.dataframe(repeating_entities, use_container_width=True)
|
| 281 |
fig_repeating_bar = px.bar(repeating_entities, x='Entity', y='Count', color='Entity')
|
| 282 |
fig_repeating_bar.update_layout(xaxis={'categoryorder': 'total descending'},
|
| 283 |
+
paper_bgcolor='#FFF8F0',
|
| 284 |
+
plot_bgcolor='#FFF8F0')
|
| 285 |
st.plotly_chart(fig_repeating_bar)
|
| 286 |
else:
|
| 287 |
st.warning("No entities were found that occur more than once.")
|