arogeriogel commited on
Commit
2631076
1 Parent(s): dd87ecd

including metadata

Browse files
Files changed (1) hide show
  1. app.py +24 -21
app.py CHANGED
@@ -14,7 +14,7 @@ from flair_recognizer import FlairRecognizer
14
 
15
  st.title("Anonymise your text!")
16
  st.markdown(
17
- "This mini-app anonymises text using Flair. You can find the code on [GitHub(WIP)](#)"
18
  )
19
 
20
  # Configure logger
@@ -88,8 +88,8 @@ def analyze_text():
88
  return_decision_process=False,
89
  )
90
 
91
- # if st.session_state.metadata:
92
- # analyze_results = include_manual_input(analyze_results)
93
 
94
  if st.session_state.allowed_words:
95
  analyze_results = exclude_manual_input(analyze_results)
@@ -101,19 +101,22 @@ def analyze_text():
101
  )
102
 
103
 
104
- # def include_manual_input(analyze_results):
105
- # analyze_results_extended=[]
106
- # logging.info(
107
- # f"analyse results before adding extra words: {analyze_results}\n"
108
- # )
109
- # for word in st.session_state.text.split():
110
- # if word in st.session_state.metadata:
111
- # [m.start() for m in re.finditer('test', 'test test test test')]
112
- # analyze_results_extended.append("type: MANUAL, start: 0, end: 3, score: 1.0")
113
- # logging.info(
114
- # f"analyse results after adding allowed words: {analyze_results_extended}\n"
115
- # )
116
- # return analyze_results
 
 
 
117
 
118
  def exclude_manual_input(analyze_results):
119
  analyze_results_fltered=[]
@@ -163,9 +166,9 @@ def clear_results():
163
  st.session_state.anon_results=""
164
  st.session_state.analyze_results=""
165
 
166
- ##############################
167
- #### Initialize variables ####
168
- ##############################
169
 
170
  if "text_error" not in st.session_state:
171
  st.session_state.text_error = ""
@@ -180,7 +183,7 @@ if "n_requests" not in st.session_state:
180
  ####### Page arguments #######
181
  ##############################
182
 
183
- # Every widget with a key is automatically added to Session State
184
 
185
  # In Streamlit, interacting with a widget triggers a rerun and variables defined
186
  # in the code get reinitialized after each rerun.
@@ -198,7 +201,7 @@ st.text_input(
198
  st.text_input(
199
  label="Data to be redacted (optional)",
200
  placeholder="John, Mary, London",
201
- key='metadata',
202
  on_change=clear_results
203
  )
204
  st.text_input(
 
14
 
15
  st.title("Anonymise your text!")
16
  st.markdown(
17
+ "This mini-app anonymises text using Flair. You can find the code in the Files and versions tab above."
18
  )
19
 
20
  # Configure logger
 
88
  return_decision_process=False,
89
  )
90
 
91
+ if st.session_state.excluded_words:
92
+ analyze_results = include_manual_input(analyze_results)
93
 
94
  if st.session_state.allowed_words:
95
  analyze_results = exclude_manual_input(analyze_results)
 
101
  )
102
 
103
 
104
+ def include_manual_input(analyze_results):
105
+ analyze_results_extended=[]
106
+ logging.info(
107
+ f"analyse results before adding extra words: {analyze_results}\n"
108
+ )
109
+ for word in st.session_state.excluded_words:
110
+ if word in st.session_state.text:
111
+ index_entries = [m.start() for m in re.finditer(word, st.session_state.text)]
112
+ for entry in index_entries:
113
+ start=entry
114
+ end=entry+len(word)
115
+ analyze_results_extended.append("type: MANUAL ADD, start: {}, end: {}, score: 1.0".format(start,end))
116
+ logging.info(
117
+ f"analyse results after adding allowed words: {analyze_results_extended}\n"
118
+ )
119
+ return analyze_results_extended
120
 
121
  def exclude_manual_input(analyze_results):
122
  analyze_results_fltered=[]
 
166
  st.session_state.anon_results=""
167
  st.session_state.analyze_results=""
168
 
169
+ #######################################
170
+ #### Initialize "global" variables ####
171
+ #######################################
172
 
173
  if "text_error" not in st.session_state:
174
  st.session_state.text_error = ""
 
183
  ####### Page arguments #######
184
  ##############################
185
 
186
+ # Every widget with a key is automatically added to Session State as a global variable.
187
 
188
  # In Streamlit, interacting with a widget triggers a rerun and variables defined
189
  # in the code get reinitialized after each rerun.
 
201
  st.text_input(
202
  label="Data to be redacted (optional)",
203
  placeholder="John, Mary, London",
204
+ key='excluded_words',
205
  on_change=clear_results
206
  )
207
  st.text_input(