mrfakename commited on
Commit
74744eb
1 Parent(s): 29e6773

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -1
app.py CHANGED
@@ -11,7 +11,8 @@ import uuid
11
  from pathlib import Path
12
  from huggingface_hub import CommitScheduler, delete_file, hf_hub_download
13
  from gradio_client import Client
14
-
 
15
  ####################################
16
  # Constants
17
  ####################################
@@ -26,6 +27,7 @@ AVAILABLE_MODELS = {
26
 
27
  SPACE_ID = os.getenv('HF_ID')
28
  MAX_SAMPLE_TXT_LENGTH = 150
 
29
  DB_DATASET_ID = os.getenv('DATASET_ID')
30
  DB_NAME = "database.db"
31
 
@@ -444,6 +446,10 @@ def synthandreturn(text):
444
  text = text.strip()
445
  if len(text) > MAX_SAMPLE_TXT_LENGTH:
446
  raise gr.Error(f'You exceeded the limit of {MAX_SAMPLE_TXT_LENGTH} characters')
 
 
 
 
447
  if not text:
448
  raise gr.Error(f'You did not enter any text')
449
  # Get two random models
 
11
  from pathlib import Path
12
  from huggingface_hub import CommitScheduler, delete_file, hf_hub_download
13
  from gradio_client import Client
14
+ from detoxify import Detoxify
15
+ toxicity = Detoxify('original')
16
  ####################################
17
  # Constants
18
  ####################################
 
27
 
28
  SPACE_ID = os.getenv('HF_ID')
29
  MAX_SAMPLE_TXT_LENGTH = 150
30
+ MIN_SAMPLE_TXT_LENGTH = 10
31
  DB_DATASET_ID = os.getenv('DATASET_ID')
32
  DB_NAME = "database.db"
33
 
 
446
  text = text.strip()
447
  if len(text) > MAX_SAMPLE_TXT_LENGTH:
448
  raise gr.Error(f'You exceeded the limit of {MAX_SAMPLE_TXT_LENGTH} characters')
449
+ if len(text) < MIN_SAMPLE_TXT_LENGTH:
450
+ raise gr.Error(f'Not enough text')
451
+ if (toxicity.predict(text)['toxicity'] > 0.5):
452
+ raise gr.Error('Your text failed the toxicity test!')
453
  if not text:
454
  raise gr.Error(f'You did not enter any text')
455
  # Get two random models