AIEcosystem commited on
Commit
ff19b43
·
verified ·
1 Parent(s): 3593a58

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +18 -24
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>
@@ -20,37 +21,31 @@ st.markdown(
20
  background-color: #E8F5E9; /* A very light green */
21
  color: #1B5E20; /* Dark green for the text */
22
  }
23
-
24
- /* Sidebar background color */
25
  .css-1d36184 {
26
  background-color: #A5D6A7; /* A medium light green */
27
  secondary-background-color: #A5D6A7;
28
  }
29
-
30
- /* Expander background color and header */
31
  .streamlit-expanderContent, .streamlit-expanderHeader {
32
  background-color: #E8F5E9;
33
  }
34
-
35
- /* Text Area background and text color */
36
  .stTextArea textarea {
37
  background-color: #81C784; /* A slightly darker medium green */
38
  color: #1B5E20; /* Dark green for text */
39
  }
40
-
41
- /* Button background and text color */
42
  .stButton > button {
43
  background-color: #81C784;
44
  color: #1B5E20;
45
  }
46
-
47
- /* Warning box background and text color */
48
  .stAlert.st-warning {
49
  background-color: #66BB6A; /* A medium-dark green for the warning box */
50
  color: #1B5E20;
51
  }
52
-
53
- /* Success box background and text color */
54
  .stAlert.st-success {
55
  background-color: #66BB6A; /* A medium-dark green for the success box */
56
  color: #1B5E20;
@@ -77,12 +72,10 @@ Results are presented in easy-to-read tables, visualized in an interactive tree
77
 
78
  For any errors or inquiries, please contact us at info@nlpblogs.com""")
79
 
80
-
81
-
82
  with st.sidebar:
83
  st.write("Use the following code to embed the ChainSense web app on your website. Feel free to adjust the width and height values to fit your page.")
84
  code = '''
85
- <iframe
86
  src="https://aiecosystem-chainsense.hf.space"
87
  frameborder="0"
88
  width="850"
@@ -121,8 +114,7 @@ category_mapping = {
121
  "Temporal & Events": ["Date", "Transportation_Mode"],
122
  "Locations": ["Location"]}
123
  # --- Model Loading ---
124
- @st.cache_resource
125
- def load_ner_model():
126
  """Loads the GLiNER model and caches it."""
127
  try:
128
  return GLiNER.from_pretrained("gliner-community/gliner_large-v2.5", nested_ner=True, num_gen_sequences=2, gen_constraints= labels)
@@ -146,13 +138,13 @@ def clear_text():
146
  st.button("Clear text", on_click=clear_text)
147
  # --- Results Section ---
148
  if st.button("Results"):
149
- start_time = time.time()
150
  # Check for word limit and empty text first
151
  if not text.strip():
152
  st.warning("Please enter some text to extract entities.")
153
  elif word_count > word_limit:
154
  st.warning(f"Your text exceeds the {word_limit} word limit. Please shorten it to continue.")
155
  else:
 
156
  with st.spinner("Extracting entities...", show_time=True):
157
  entities = model.predict_entities(text, labels)
158
  df = pd.DataFrame(entities)
@@ -257,10 +249,12 @@ if st.button("Results"):
257
  if comet_initialized:
258
  experiment.log_figure(figure=fig_treemap, figure_name="entity_treemap_categories")
259
  experiment.end()
 
 
 
 
 
 
 
260
  else: # If df is empty
261
- st.warning("No entities were found in the provided text.")
262
- end_time = time.time()
263
- elapsed_time = end_time - start_time
264
- st.text("")
265
- st.text("")
266
- 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>
 
21
  background-color: #E8F5E9; /* A very light green */
22
  color: #1B5E20; /* Dark green for the text */
23
  }
24
+ /* Sidebar background color */
 
25
  .css-1d36184 {
26
  background-color: #A5D6A7; /* A medium light green */
27
  secondary-background-color: #A5D6A7;
28
  }
29
+ /* Expander background color and header */
 
30
  .streamlit-expanderContent, .streamlit-expanderHeader {
31
  background-color: #E8F5E9;
32
  }
33
+ /* Text Area background and text color */
 
34
  .stTextArea textarea {
35
  background-color: #81C784; /* A slightly darker medium green */
36
  color: #1B5E20; /* Dark green for text */
37
  }
38
+ /* Button background and text color */
 
39
  .stButton > button {
40
  background-color: #81C784;
41
  color: #1B5E20;
42
  }
43
+ /* Warning box background and text color */
 
44
  .stAlert.st-warning {
45
  background-color: #66BB6A; /* A medium-dark green for the warning box */
46
  color: #1B5E20;
47
  }
48
+ /* Success box background and text color */
 
49
  .stAlert.st-success {
50
  background-color: #66BB6A; /* A medium-dark green for the success box */
51
  color: #1B5E20;
 
72
 
73
  For any errors or inquiries, please contact us at info@nlpblogs.com""")
74
 
 
 
75
  with st.sidebar:
76
  st.write("Use the following code to embed the ChainSense web app on your website. Feel free to adjust the width and height values to fit your page.")
77
  code = '''
78
+ <iframe
79
  src="https://aiecosystem-chainsense.hf.space"
80
  frameborder="0"
81
  width="850"
 
114
  "Temporal & Events": ["Date", "Transportation_Mode"],
115
  "Locations": ["Location"]}
116
  # --- Model Loading ---
117
+ @st.cache_resourcedef load_ner_model():
 
118
  """Loads the GLiNER model and caches it."""
119
  try:
120
  return GLiNER.from_pretrained("gliner-community/gliner_large-v2.5", nested_ner=True, num_gen_sequences=2, gen_constraints= labels)
 
138
  st.button("Clear text", on_click=clear_text)
139
  # --- Results Section ---
140
  if st.button("Results"):
 
141
  # Check for word limit and empty text first
142
  if not text.strip():
143
  st.warning("Please enter some text to extract entities.")
144
  elif word_count > word_limit:
145
  st.warning(f"Your text exceeds the {word_limit} word limit. Please shorten it to continue.")
146
  else:
147
+ start_time = time.time()
148
  with st.spinner("Extracting entities...", show_time=True):
149
  entities = model.predict_entities(text, labels)
150
  df = pd.DataFrame(entities)
 
249
  if comet_initialized:
250
  experiment.log_figure(figure=fig_treemap, figure_name="entity_treemap_categories")
251
  experiment.end()
252
+
253
+ # Corrected placement for time calculation and display
254
+ end_time = time.time()
255
+ elapsed_time = end_time - start_time
256
+ st.text("")
257
+ st.text("")
258
+ st.info(f"Results processed in **{elapsed_time:.2f} seconds**.")
259
  else: # If df is empty
260
+ st.warning("No entities were found in the provided text.")