easyh commited on
Commit
642fbe6
·
1 Parent(s): ad0b044

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -20
app.py CHANGED
@@ -2,9 +2,11 @@
2
  #------------------------------------------------------------------------------
3
  #------------------------------------------------------------------------------
4
 
 
5
  import streamlit as st
6
  import spacy
7
  import spacy_streamlit
 
8
  from io import StringIO
9
  import pandas as pd
10
 
@@ -132,33 +134,64 @@ with st.spinner("Text wird eingelesen..."):
132
  text = st.text_area(" ", DEFAULT_TEXT, height=200)
133
  st.success("Text ist eingelesen!")
134
 
 
135
  #------------------------------------------------------------------------------
136
  #------------------------------------------------------------------------------
137
 
 
138
  #Farben für die verschiedenen Entitäten
139
  colors = {"PER": "#fdec3e", "PERSON": "#fdec3e", "LOC": "#7e56c2", "ORT": "#7e56c2", "ORG": "#209485" , "ORGANISATION": "#209485" , "MISC": "#eb4034", "ZEIT": "#4c9c4b", "OBJEKT": "#7e56c2"}
140
 
141
  #Spacy-Streamlit NER Visualizer
142
-
143
  #NER-Prozess wird gestartet, je nach Model werden hier die entsprechenden Entitäten gewechselt.
144
  with st.spinner('Named Entities werden gesucht...'):
145
  doc = nlp(text)
146
  if model == "de_fnhd_nerdh":
147
- spacy_streamlit.visualize_ner(doc, labels = ["PERSON", "ORT", "ORGANISATION", "OBJEKT", "ZEIT",], show_table=False, colors = colors)
 
 
 
 
 
 
 
148
  else:
149
- spacy_streamlit.visualize_ner(doc, labels = ["PER", "LOC", "ORG", "MISC"], show_table=False, colors = colors)
 
 
 
 
 
 
 
 
150
  st.success('Suchprozess ist abgeschlossen!')
151
 
152
  #------------------------------------------------------------------------------
153
  #------------------------------------------------------------------------------
 
 
 
 
 
 
154
 
155
  #Um die NER-Ergebnisse downloaden zu können, werden die Entitäten in einer csv gespeichert
156
  results = []
157
  for ent in doc.ents:
158
- results.append([ent.text,ent.label_])
 
159
  df_results = pd.DataFrame(results, columns = ['text', 'label'])
160
  csv = convert_df(df_results)
161
 
 
 
 
 
 
 
 
 
162
 
163
  #------------------------------------------------------------------------------
164
  #------------------------------------------------------------------------------
@@ -177,22 +210,6 @@ if model == "de_fnhd_nerdh":
177
  ```
178
  ''')
179
 
180
- #------------------------------------------------------------------------------
181
- #------------------------------------------------------------------------------
182
-
183
- #Download-Button
184
- st.sidebar.markdown('\n\n')
185
- st.sidebar.markdown('''
186
- ### NER-Ergebnnisse in einer .csv-Datei downloaden.
187
- Die Datei enthält alle Entitäts-Typen.
188
- ''')
189
- st.sidebar.download_button(
190
- "Ergebnisse downloaden",
191
- csv,
192
- "ner_results_" + model + ".csv",
193
- "text/csv",
194
- key='download-csv'
195
- )
196
 
197
  #------------------------------------------------------------------------------
198
  #------------------------------------------------------------------------------
 
2
  #------------------------------------------------------------------------------
3
  #------------------------------------------------------------------------------
4
 
5
+ from aem import customroot
6
  import streamlit as st
7
  import spacy
8
  import spacy_streamlit
9
+ from spacy import displacy
10
  from io import StringIO
11
  import pandas as pd
12
 
 
134
  text = st.text_area(" ", DEFAULT_TEXT, height=200)
135
  st.success("Text ist eingelesen!")
136
 
137
+ st.markdown("---")
138
  #------------------------------------------------------------------------------
139
  #------------------------------------------------------------------------------
140
 
141
+ st.markdown("### Named Entities")
142
  #Farben für die verschiedenen Entitäten
143
  colors = {"PER": "#fdec3e", "PERSON": "#fdec3e", "LOC": "#7e56c2", "ORT": "#7e56c2", "ORG": "#209485" , "ORGANISATION": "#209485" , "MISC": "#eb4034", "ZEIT": "#4c9c4b", "OBJEKT": "#7e56c2"}
144
 
145
  #Spacy-Streamlit NER Visualizer
 
146
  #NER-Prozess wird gestartet, je nach Model werden hier die entsprechenden Entitäten gewechselt.
147
  with st.spinner('Named Entities werden gesucht...'):
148
  doc = nlp(text)
149
  if model == "de_fnhd_nerdh":
150
+ entities = st.multiselect('Entitäten auswählen', ['PERSON', 'ORT', 'ORGANISATION', 'OBJEKT', 'ZEIT', 'Alle Entitäten'], default= ['Alle Entitäten'])
151
+ if 'Alle Entitäten' in entities:
152
+ entities = ['PERSON', 'ORT', 'ORGANISATION', 'OBJEKT', 'ZEIT']
153
+
154
+ options = {"ents": entities,"colors": colors}
155
+ ent_html = displacy.render(doc, style="ent", options=options, jupyter=False)
156
+ st.markdown(ent_html, unsafe_allow_html=True)
157
+ #spacy_streamlit.visualize_ner(doc, labels = ["PERSON", "ORT", "ORGANISATION", "OBJEKT", "ZEIT",], show_table=False, colors = colors)
158
  else:
159
+ entities = st.multiselect('Entitäten auswählen', ["PER", "LOC", "ORG", "MISC", 'Alle Entitäten'], default= ['Alle Entitäten'])
160
+ if 'Alle Entitäten' in entities:
161
+ entities = ["PER", "LOC", "ORG", "MISC"]
162
+
163
+ options = {"ents": entities,"colors": colors}
164
+ ent_html = displacy.render(doc, style="ent", options=options, jupyter=False)
165
+ st.markdown(ent_html, unsafe_allow_html=True)
166
+ #spacy_streamlit.visualize_ner(doc, labels = ["PER", "LOC", "ORG", "MISC"], show_table=False, colors = colors)
167
+ st.markdown(' ')
168
  st.success('Suchprozess ist abgeschlossen!')
169
 
170
  #------------------------------------------------------------------------------
171
  #------------------------------------------------------------------------------
172
+ #Download-Funktion der Entitäten
173
+ st.sidebar.markdown('\n\n')
174
+ st.sidebar.markdown('''
175
+ ### NER-Ergebnnisse in einer .csv-Datei downloaden.
176
+ Die Datei enthält die ausgewählten Entitäten.
177
+ ''')
178
 
179
  #Um die NER-Ergebnisse downloaden zu können, werden die Entitäten in einer csv gespeichert
180
  results = []
181
  for ent in doc.ents:
182
+ if ent.label_ in entities:
183
+ results.append([ent.text,ent.label_])
184
  df_results = pd.DataFrame(results, columns = ['text', 'label'])
185
  csv = convert_df(df_results)
186
 
187
+ st.sidebar.download_button(
188
+ "Ergebnisse downloaden",
189
+ csv,
190
+ "ner_results_" + model + ".csv",
191
+ "text/csv",
192
+ key='download-csv'
193
+ )
194
+
195
 
196
  #------------------------------------------------------------------------------
197
  #------------------------------------------------------------------------------
 
210
  ```
211
  ''')
212
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
213
 
214
  #------------------------------------------------------------------------------
215
  #------------------------------------------------------------------------------