Spaces:
Running
Running
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +8 -32
src/streamlit_app.py
CHANGED
|
@@ -15,35 +15,17 @@ from comet_ml import Experiment
|
|
| 15 |
|
| 16 |
# --- Page Configuration and UI Elements ---
|
| 17 |
st.set_page_config(layout="wide", page_title="Named Entity Recognition App")
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
st.subheader("DataHarvest", divider="violet")
|
| 22 |
st.link_button("by nlpblogs", "https://nlpblogs.com", type="tertiary")
|
| 23 |
st.markdown(':rainbow[**Supported Languages: English**]')
|
| 24 |
-
expander = st.expander("**Important notes**")
|
| 25 |
-
expander.write("""**Named Entities:** This DataHarvest web app predicts nine (9) labels: "person", "country", "city", "organization", "date", "time", "cardinal", "money", "position"
|
| 26 |
-
|
| 27 |
-
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.
|
| 28 |
-
|
| 29 |
-
**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.
|
| 30 |
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
**Technical issues:** If your connection times out, please refresh the page or reopen the app's URL.
|
| 34 |
-
|
| 35 |
-
For any errors or inquiries, please contact us at info@nlpblogs.com""")
|
| 36 |
|
| 37 |
with st.sidebar:
|
| 38 |
st.write("Use the following code to embed the DataHarvest web app on your website. Feel free to adjust the width and height values to fit your page.")
|
| 39 |
code = '''
|
| 40 |
-
<iframe
|
| 41 |
-
src="https://aiecosystem-dataharvest.hf.space"
|
| 42 |
-
frameborder="0"
|
| 43 |
-
width="850"
|
| 44 |
-
height="450"
|
| 45 |
-
></iframe>
|
| 46 |
-
|
| 47 |
'''
|
| 48 |
st.code(code, language="html")
|
| 49 |
st.text("")
|
|
@@ -79,7 +61,6 @@ def load_ner_model():
|
|
| 79 |
except Exception as e:
|
| 80 |
st.error(f"Failed to load NER model. Please check your internet connection or model availability: {e}")
|
| 81 |
st.stop()
|
| 82 |
-
|
| 83 |
model = load_ner_model()
|
| 84 |
reverse_category_mapping = {label: category for category, label_list in category_mapping.items() for label in label_list}
|
| 85 |
|
|
@@ -142,7 +123,8 @@ if st.button("Results"):
|
|
| 142 |
experiment.end()
|
| 143 |
end_time = time.time()
|
| 144 |
st.session_state.elapsed_time = end_time - start_time
|
| 145 |
-
|
|
|
|
| 146 |
# If the text is the same, do nothing but keep results displayed
|
| 147 |
else:
|
| 148 |
st.session_state.show_results = True
|
|
@@ -164,7 +146,7 @@ if st.session_state.show_results:
|
|
| 164 |
st.dataframe(df_category_filtered.drop(columns=['category']), use_container_width=True)
|
| 165 |
else:
|
| 166 |
st.info(f"No entities found for the '{category_name}' category.")
|
| 167 |
-
|
| 168 |
with st.expander("See Glossary of tags"):
|
| 169 |
st.write('''
|
| 170 |
- **text**: ['entity extracted from your text data']
|
|
@@ -175,7 +157,6 @@ if st.session_state.show_results:
|
|
| 175 |
''')
|
| 176 |
|
| 177 |
st.divider()
|
| 178 |
-
|
| 179 |
# Tree map
|
| 180 |
st.subheader("Tree map", divider="violet")
|
| 181 |
fig_treemap = px.treemap(df, path=[px.Constant("all"), 'category', 'label', 'text'], values='score', color='category')
|
|
@@ -184,7 +165,7 @@ if st.session_state.show_results:
|
|
| 184 |
expander.write("""You can easily download the tree map by hovering over it. Look for the download icon that appears in the top right corner.
|
| 185 |
""")
|
| 186 |
st.plotly_chart(fig_treemap)
|
| 187 |
-
|
| 188 |
# Pie and Bar charts
|
| 189 |
grouped_counts = df['category'].value_counts().reset_index()
|
| 190 |
grouped_counts.columns = ['category', 'count']
|
|
@@ -206,7 +187,7 @@ if st.session_state.show_results:
|
|
| 206 |
expander.write("""You can easily download the bar chart by hovering over it. Look for the download icon that appears in the top right corner.
|
| 207 |
""")
|
| 208 |
st.plotly_chart(fig_bar)
|
| 209 |
-
|
| 210 |
# Most Frequent Entities
|
| 211 |
st.subheader("Most Frequent Entities", divider="violet")
|
| 212 |
word_counts = df['text'].value_counts().reset_index()
|
|
@@ -237,8 +218,6 @@ if st.session_state.show_results:
|
|
| 237 |
|
| 238 |
with stylable_container(
|
| 239 |
key="download_button",
|
| 240 |
-
|
| 241 |
-
|
| 242 |
css_styles="""button { background-color: #8A2BE2; border: 1px solid black; padding: 5px; color: white; }""",
|
| 243 |
):
|
| 244 |
st.download_button(
|
|
@@ -247,10 +226,7 @@ if st.session_state.show_results:
|
|
| 247 |
file_name="nlpblogs_results.zip",
|
| 248 |
mime="application/zip"
|
| 249 |
)
|
| 250 |
-
|
| 251 |
st.text("")
|
| 252 |
st.text("")
|
| 253 |
-
st.info(f"Results processed in **{st.session_state.elapsed_time:.2f} seconds**.")
|
| 254 |
-
|
| 255 |
else:
|
| 256 |
st.warning("No entities were found in the provided text.")
|
|
|
|
| 15 |
|
| 16 |
# --- Page Configuration and UI Elements ---
|
| 17 |
st.set_page_config(layout="wide", page_title="Named Entity Recognition App")
|
|
|
|
|
|
|
|
|
|
| 18 |
st.subheader("DataHarvest", divider="violet")
|
| 19 |
st.link_button("by nlpblogs", "https://nlpblogs.com", type="tertiary")
|
| 20 |
st.markdown(':rainbow[**Supported Languages: English**]')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
+
expander = st.expander("**Important notes**")
|
| 23 |
+
expander.write("""**Named Entities:** This DataHarvest web app predicts nine (9) labels: "person", "country", "city", "organization", "date", "time", "cardinal", "money", "position"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.**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.**Usage Limits:** You can request results unlimited times for one (1) month.**Technical issues:** If your connection times out, please refresh the page or reopen the app's URL. For any errors or inquiries, please contact us at info@nlpblogs.com""")
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
with st.sidebar:
|
| 26 |
st.write("Use the following code to embed the DataHarvest web app on your website. Feel free to adjust the width and height values to fit your page.")
|
| 27 |
code = '''
|
| 28 |
+
<iframe src="https://aiecosystem-dataharvest.hf.space" frameborder="0" width="850" height="450" ></iframe>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
'''
|
| 30 |
st.code(code, language="html")
|
| 31 |
st.text("")
|
|
|
|
| 61 |
except Exception as e:
|
| 62 |
st.error(f"Failed to load NER model. Please check your internet connection or model availability: {e}")
|
| 63 |
st.stop()
|
|
|
|
| 64 |
model = load_ner_model()
|
| 65 |
reverse_category_mapping = {label: category for category, label_list in category_mapping.items() for label in label_list}
|
| 66 |
|
|
|
|
| 123 |
experiment.end()
|
| 124 |
end_time = time.time()
|
| 125 |
st.session_state.elapsed_time = end_time - start_time
|
| 126 |
+
# Place the message here, so it only runs once per button click
|
| 127 |
+
st.info(f"Results processed in **{st.session_state.elapsed_time:.2f} seconds**.")
|
| 128 |
# If the text is the same, do nothing but keep results displayed
|
| 129 |
else:
|
| 130 |
st.session_state.show_results = True
|
|
|
|
| 146 |
st.dataframe(df_category_filtered.drop(columns=['category']), use_container_width=True)
|
| 147 |
else:
|
| 148 |
st.info(f"No entities found for the '{category_name}' category.")
|
| 149 |
+
|
| 150 |
with st.expander("See Glossary of tags"):
|
| 151 |
st.write('''
|
| 152 |
- **text**: ['entity extracted from your text data']
|
|
|
|
| 157 |
''')
|
| 158 |
|
| 159 |
st.divider()
|
|
|
|
| 160 |
# Tree map
|
| 161 |
st.subheader("Tree map", divider="violet")
|
| 162 |
fig_treemap = px.treemap(df, path=[px.Constant("all"), 'category', 'label', 'text'], values='score', color='category')
|
|
|
|
| 165 |
expander.write("""You can easily download the tree map by hovering over it. Look for the download icon that appears in the top right corner.
|
| 166 |
""")
|
| 167 |
st.plotly_chart(fig_treemap)
|
| 168 |
+
|
| 169 |
# Pie and Bar charts
|
| 170 |
grouped_counts = df['category'].value_counts().reset_index()
|
| 171 |
grouped_counts.columns = ['category', 'count']
|
|
|
|
| 187 |
expander.write("""You can easily download the bar chart by hovering over it. Look for the download icon that appears in the top right corner.
|
| 188 |
""")
|
| 189 |
st.plotly_chart(fig_bar)
|
| 190 |
+
|
| 191 |
# Most Frequent Entities
|
| 192 |
st.subheader("Most Frequent Entities", divider="violet")
|
| 193 |
word_counts = df['text'].value_counts().reset_index()
|
|
|
|
| 218 |
|
| 219 |
with stylable_container(
|
| 220 |
key="download_button",
|
|
|
|
|
|
|
| 221 |
css_styles="""button { background-color: #8A2BE2; border: 1px solid black; padding: 5px; color: white; }""",
|
| 222 |
):
|
| 223 |
st.download_button(
|
|
|
|
| 226 |
file_name="nlpblogs_results.zip",
|
| 227 |
mime="application/zip"
|
| 228 |
)
|
|
|
|
| 229 |
st.text("")
|
| 230 |
st.text("")
|
|
|
|
|
|
|
| 231 |
else:
|
| 232 |
st.warning("No entities were found in the provided text.")
|