Spaces:
Runtime error
Runtime error
Mask profanity based on characters
Browse files
app.py
CHANGED
@@ -122,7 +122,7 @@ def predict(text):
|
|
122 |
try:
|
123 |
output = query(preprocess(text))[0]
|
124 |
except Exception:
|
125 |
-
|
126 |
|
127 |
output = [tuple(i.values()) for i in output]
|
128 |
output = dict((x, y) for x, y in output)
|
@@ -131,9 +131,12 @@ def predict(text):
|
|
131 |
|
132 |
if predicted_label == 'Abusive':
|
133 |
output_text = text
|
134 |
-
for
|
135 |
-
compiled = re.compile(re.escape(
|
136 |
-
|
|
|
|
|
|
|
137 |
return output, output_text
|
138 |
else:
|
139 |
return output, text
|
|
|
122 |
try:
|
123 |
output = query(preprocess(text))[0]
|
124 |
except Exception:
|
125 |
+
return "Loading", "The model is loading please try again later."
|
126 |
|
127 |
output = [tuple(i.values()) for i in output]
|
128 |
output = dict((x, y) for x, y in output)
|
|
|
131 |
|
132 |
if predicted_label == 'Abusive':
|
133 |
output_text = text
|
134 |
+
for profanity in profanities:
|
135 |
+
compiled = re.compile(re.escape(profanity), re.IGNORECASE)
|
136 |
+
mask = ""
|
137 |
+
for i in profanity:
|
138 |
+
mask += "*" if i != " " else " "
|
139 |
+
output_text = compiled.sub(mask, output_text)
|
140 |
return output, output_text
|
141 |
else:
|
142 |
return output, text
|