AIEcosystem commited on
Commit
42f4f4d
·
verified ·
1 Parent(s): 782c774

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +20 -18
src/streamlit_app.py CHANGED
@@ -12,6 +12,7 @@ from streamlit_extras.stylable_container import stylable_container
12
  from typing import Optional
13
  from gliner import GLiNER
14
  from comet_ml import Experiment
 
15
  st.markdown(
16
  """
17
  <style>
@@ -58,13 +59,14 @@ st.markdown(
58
  }
59
  </style>
60
  """,
61
- unsafe_allow_html=True)
 
62
  # --- Page Configuration and UI Elements ---
63
  st.set_page_config(layout="wide", page_title="Named Entity Recognition App")
64
  st.subheader("Legal Lens", divider="grey")
65
  st.link_button("by nlpblogs", "https://nlpblogs.com", type="tertiary")
66
  expander = st.expander("**Important notes**")
67
- expander.write("""**Named Entities:** This Legal Lens web app predicts twenty-eight (28) labels: "Plaintiff", "Defendant", "Appellant", "Appellee", "Debtor", "Creditor", "Signer", "Witness", "Courts", "Judges", "Lawyers", "Attorneys", "Statutes", "Laws", "Provisions", "Case_citations", "Legal_documents", "Effective_dates", "Execution_dates", "Expiration_dates", "Money", "Amounts", "Contract_terms", "Case_number", "Witnesses", "Crimes", "Offenses", "Victims"
68
 
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
 
@@ -103,7 +105,7 @@ comet_initialized = bool(COMET_API_KEY and COMET_WORKSPACE and COMET_PROJECT_NAM
103
  if not comet_initialized:
104
  st.warning("Comet ML not initialized. Check environment variables.")
105
  # --- Label Definitions ---
106
- labels = ["Plaintiff","Defendant","Appellant","Appellee","Debtor","Creditor","Signer","Witness","Courts","Judges","Lawyers","Attorneys","Statutes","Laws","Provisions","Case_citations","Legal_documents","Effective_dates","Execution_dates","Expiration_dates","Money","Amounts","Contract_terms","Case_number","Witnesses","Crimes","Offenses","Victims"]
107
  category_mapping = {
108
  "Parties": [
109
  "Plaintiff",
@@ -142,14 +144,12 @@ category_mapping = {
142
  ],
143
  "Court Judgments": [
144
  "Case_number",
145
- "Witnesses",
146
  ],
147
  "Criminal Law": [
148
  "Crimes",
149
  "Offenses",
150
  "Victims"
151
- ]
152
- }
153
  # --- Model Loading ---
154
  @st.cache_resource
155
  def load_ner_model():
@@ -192,7 +192,7 @@ if st.button("Results"):
192
  )
193
  experiment.log_parameter("input_text", text)
194
  experiment.log_table("predicted_entities", df)
195
- st.subheader("Grouped Entities by Category", divider = "grey")
196
  # Create tabs for each category
197
  category_names = sorted(list(category_mapping.keys()))
198
  category_tabs = st.tabs(category_names)
@@ -213,7 +213,7 @@ if st.button("Results"):
213
  ''')
214
  st.divider()
215
  # Tree map
216
- st.subheader("Tree map", divider = "grey")
217
  fig_treemap = px.treemap(df, path=[px.Constant("all"), 'category', 'label', 'text'], values='score', color='category')
218
  fig_treemap.update_layout(margin=dict(t=50, l=25, r=25, b=25), paper_bgcolor='#F5F5F5', plot_bgcolor='#F5F5F5')
219
  st.plotly_chart(fig_treemap)
@@ -222,7 +222,7 @@ if st.button("Results"):
222
  grouped_counts.columns = ['category', 'count']
223
  col1, col2 = st.columns(2)
224
  with col1:
225
- st.subheader("Pie chart", divider = "grey")
226
  fig_pie = px.pie(grouped_counts, values='count', names='category', hover_data=['count'], labels={'count': 'count'}, title='Percentage of predicted categories')
227
  fig_pie.update_traces(textposition='inside', textinfo='percent+label')
228
  fig_pie.update_layout(
@@ -231,9 +231,9 @@ if st.button("Results"):
231
  )
232
  st.plotly_chart(fig_pie)
233
  with col2:
234
- st.subheader("Bar chart", divider = "grey")
235
  fig_bar = px.bar(grouped_counts, x="count", y="category", color="category", text_auto=True, title='Occurrences of predicted categories')
236
- fig_bar.update_layout( # Changed from fig_pie to fig_bar
237
  paper_bgcolor='#F5F5F5',
238
  plot_bgcolor='#F5F5F5'
239
  )
@@ -272,7 +272,7 @@ if st.button("Results"):
272
  myzip.writestr("Glossary of tags.csv", dfa.to_csv(index=False))
273
  with stylable_container(
274
  key="download_button",
275
- css_styles="""button { background-color: red; border: 1px solid black; padding: 5px; color: white; }""",
276
  ):
277
  st.download_button(
278
  label="Download results and glossary (zip)",
@@ -283,10 +283,12 @@ if st.button("Results"):
283
  if comet_initialized:
284
  experiment.log_figure(figure=fig_treemap, figure_name="entity_treemap_categories")
285
  experiment.end()
 
 
 
 
 
 
 
286
  else: # If df is empty
287
- st.warning("No entities were found in the provided text.")
288
- end_time = time.time()
289
- elapsed_time = end_time - start_time
290
- st.text("")
291
- st.text("")
292
- st.info(f"Results processed in **{elapsed_time:.2f} seconds**.")
 
12
  from typing import Optional
13
  from gliner import GLiNER
14
  from comet_ml import Experiment
15
+
16
  st.markdown(
17
  """
18
  <style>
 
59
  }
60
  </style>
61
  """,
62
+ unsafe_allow_html=True
63
+ )
64
  # --- Page Configuration and UI Elements ---
65
  st.set_page_config(layout="wide", page_title="Named Entity Recognition App")
66
  st.subheader("Legal Lens", divider="grey")
67
  st.link_button("by nlpblogs", "https://nlpblogs.com", type="tertiary")
68
  expander = st.expander("**Important notes**")
69
+ expander.write("""**Named Entities:** This Legal Lens web app predicts twenty-eight (28) labels: "Plaintiff", "Defendant", "Appellant", "Appellee", "Debtor", "Creditor", "Signer", "Witness", "Courts", "Judges", "Lawyers", "Attorneys", "Statutes", "Laws", "Provisions", "Case_citations", "Legal_documents", "Effective_dates", "Execution_dates", "Expiration_dates", "Money", "Amounts", "Contract_terms", "Case_number", "Crimes", "Offenses", "Victims"
70
 
71
  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.
72
 
 
105
  if not comet_initialized:
106
  st.warning("Comet ML not initialized. Check environment variables.")
107
  # --- Label Definitions ---
108
+ labels = ["Plaintiff","Defendant","Appellant","Appellee","Debtor","Creditor","Signer","Witness","Courts","Judges","Lawyers","Attorneys","Statutes","Laws","Provisions","Case_citations","Legal_documents","Effective_dates","Execution_dates","Expiration_dates","Money","Amounts","Contract_terms","Case_number","Crimes","Offenses","Victims"]
109
  category_mapping = {
110
  "Parties": [
111
  "Plaintiff",
 
144
  ],
145
  "Court Judgments": [
146
  "Case_number",
 
147
  ],
148
  "Criminal Law": [
149
  "Crimes",
150
  "Offenses",
151
  "Victims"
152
+ ]}
 
153
  # --- Model Loading ---
154
  @st.cache_resource
155
  def load_ner_model():
 
192
  )
193
  experiment.log_parameter("input_text", text)
194
  experiment.log_table("predicted_entities", df)
195
+ st.subheader("Grouped Entities by Category", divider="grey")
196
  # Create tabs for each category
197
  category_names = sorted(list(category_mapping.keys()))
198
  category_tabs = st.tabs(category_names)
 
213
  ''')
214
  st.divider()
215
  # Tree map
216
+ st.subheader("Tree map", divider="grey")
217
  fig_treemap = px.treemap(df, path=[px.Constant("all"), 'category', 'label', 'text'], values='score', color='category')
218
  fig_treemap.update_layout(margin=dict(t=50, l=25, r=25, b=25), paper_bgcolor='#F5F5F5', plot_bgcolor='#F5F5F5')
219
  st.plotly_chart(fig_treemap)
 
222
  grouped_counts.columns = ['category', 'count']
223
  col1, col2 = st.columns(2)
224
  with col1:
225
+ st.subheader("Pie chart", divider="grey")
226
  fig_pie = px.pie(grouped_counts, values='count', names='category', hover_data=['count'], labels={'count': 'count'}, title='Percentage of predicted categories')
227
  fig_pie.update_traces(textposition='inside', textinfo='percent+label')
228
  fig_pie.update_layout(
 
231
  )
232
  st.plotly_chart(fig_pie)
233
  with col2:
234
+ st.subheader("Bar chart", divider="grey")
235
  fig_bar = px.bar(grouped_counts, x="count", y="category", color="category", text_auto=True, title='Occurrences of predicted categories')
236
+ fig_bar.update_layout(
237
  paper_bgcolor='#F5F5F5',
238
  plot_bgcolor='#F5F5F5'
239
  )
 
272
  myzip.writestr("Glossary of tags.csv", dfa.to_csv(index=False))
273
  with stylable_container(
274
  key="download_button",
275
+ css_styles="""button { background-color: #8C8C8C; border: 1px solid black; padding: 5px; color: white; }""",
276
  ):
277
  st.download_button(
278
  label="Download results and glossary (zip)",
 
283
  if comet_initialized:
284
  experiment.log_figure(figure=fig_treemap, figure_name="entity_treemap_categories")
285
  experiment.end()
286
+
287
+ # Correct placement of timing information
288
+ end_time = time.time()
289
+ elapsed_time = end_time - start_time
290
+ st.text("")
291
+ st.text("")
292
+ st.info(f"Results processed in **{elapsed_time:.2f} seconds**.")
293
  else: # If df is empty
294
+ st.warning("No entities were found in the provided text.")