Speedup process by skipping toxicity check of Harvard sentences

#32
Files changed (1) hide show
  1. app.py +5 -1
app.py CHANGED
@@ -543,7 +543,11 @@ def synthandreturn(text):
543
  raise gr.Error(f'You exceeded the limit of {MAX_SAMPLE_TXT_LENGTH} characters')
544
  if len(text) < MIN_SAMPLE_TXT_LENGTH:
545
  raise gr.Error(f'Please input a text longer than {MIN_SAMPLE_TXT_LENGTH} characters')
546
- if (toxicity.predict(text)['toxicity'] > 0.8):
 
 
 
 
547
  print(f'Detected toxic content! "{text}"')
548
  raise gr.Error('Your text failed the toxicity test')
549
  if not text:
 
543
  raise gr.Error(f'You exceeded the limit of {MAX_SAMPLE_TXT_LENGTH} characters')
544
  if len(text) < MIN_SAMPLE_TXT_LENGTH:
545
  raise gr.Error(f'Please input a text longer than {MIN_SAMPLE_TXT_LENGTH} characters')
546
+ if (
547
+ # test toxicity if not prepared text
548
+ text not in sents
549
+ and toxicity.predict(text)['toxicity'] > 0.8
550
+ ):
551
  print(f'Detected toxic content! "{text}"')
552
  raise gr.Error('Your text failed the toxicity test')
553
  if not text: