mginoben commited on
Commit
f6a75a8
1 Parent(s): 1371b6f

Mask profanity based on characters

Browse files
Files changed (1) hide show
  1. app.py +7 -4
app.py CHANGED
@@ -122,7 +122,7 @@ def predict(text):
122
  try:
123
  output = query(preprocess(text))[0]
124
  except Exception:
125
- print(output)
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 i in profanities:
135
- compiled = re.compile(re.escape(i), re.IGNORECASE)
136
- output_text = compiled.sub('****', output_text)
 
 
 
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