Spaces:
Runtime error
Runtime error
arogeriogel
commited on
Commit
•
07131b7
1
Parent(s):
c1ebb64
update app
Browse files
app.py
CHANGED
@@ -7,7 +7,7 @@ from presidio_analyzer import AnalyzerEngine, PatternRecognizer, RecognizerResul
|
|
7 |
|
8 |
from annotated_text import annotated_text
|
9 |
from flair_recognizer import FlairRecognizer
|
10 |
-
|
11 |
|
12 |
###############################
|
13 |
#### Render Streamlit page ####
|
@@ -15,13 +15,12 @@ from flair_recognizer import FlairRecognizer
|
|
15 |
|
16 |
st.title("Anonymise your text!")
|
17 |
st.markdown(
|
18 |
-
"This mini-app anonymises text using Flair. You can find the code in the Files and versions tab above."
|
19 |
)
|
20 |
|
21 |
# Configure logger
|
22 |
logging.basicConfig(format="\n%(asctime)s\n%(message)s", level=logging.INFO, force=True)
|
23 |
|
24 |
-
|
25 |
##############################
|
26 |
###### Define functions ######
|
27 |
##############################
|
@@ -92,6 +91,20 @@ def analyze_text():
|
|
92 |
if not st.session_state.text:
|
93 |
st.session_state.text_error = "Please enter your text"
|
94 |
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
95 |
|
96 |
with text_spinner_placeholder:
|
97 |
with st.spinner("Please wait while your text is being analysed..."):
|
|
|
7 |
|
8 |
from annotated_text import annotated_text
|
9 |
from flair_recognizer import FlairRecognizer
|
10 |
+
from detoxify import Detoxify
|
11 |
|
12 |
###############################
|
13 |
#### Render Streamlit page ####
|
|
|
15 |
|
16 |
st.title("Anonymise your text!")
|
17 |
st.markdown(
|
18 |
+
"This mini-app anonymises text using Flair and Presidio. You can find the code in the Files and versions tab above."
|
19 |
)
|
20 |
|
21 |
# Configure logger
|
22 |
logging.basicConfig(format="\n%(asctime)s\n%(message)s", level=logging.INFO, force=True)
|
23 |
|
|
|
24 |
##############################
|
25 |
###### Define functions ######
|
26 |
##############################
|
|
|
91 |
if not st.session_state.text:
|
92 |
st.session_state.text_error = "Please enter your text"
|
93 |
return
|
94 |
+
|
95 |
+
toxicity_results = Detoxify('original').predict(st.session_state.text)
|
96 |
+
is_toxic=False
|
97 |
+
for k in toxicity_results.keys():
|
98 |
+
for k in toxicity_results.keys():
|
99 |
+
if k!='toxicity':
|
100 |
+
if toxicity_results[k]>0.5:
|
101 |
+
is_toxic=True
|
102 |
+
else:
|
103 |
+
if toxicity_results[k]>0.65:
|
104 |
+
is_toxic=True
|
105 |
+
if is_toxic:
|
106 |
+
st.session_state.text_error = "Your text entry was detected as toxic, please re-write it."
|
107 |
+
return
|
108 |
|
109 |
with text_spinner_placeholder:
|
110 |
with st.spinner("Please wait while your text is being analysed..."):
|