Spaces:
Sleeping
Sleeping
Added safety mechanisms for generation
Browse files
app.py
CHANGED
|
@@ -5,6 +5,7 @@ import sentencepiece as spm
|
|
| 5 |
import numpy as np
|
| 6 |
import pandas as pd
|
| 7 |
import tensorflow as tf
|
|
|
|
| 8 |
|
| 9 |
def custom_pad_sequences(sequences, maxlen, padding='pre', value=0):
|
| 10 |
"""
|
|
@@ -96,7 +97,22 @@ def generate_random_name(interpreter, vocab_size, sp, max_length=10, temperature
|
|
| 96 |
if parts and len(parts[-1]) < 3:
|
| 97 |
generated_name = " ".join(parts[:-1])
|
| 98 |
|
| 99 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
|
| 101 |
def generateNames(type, amount, max_length=30, temperature=0.5, seed_text=""):
|
| 102 |
if type == "Terraria":
|
|
|
|
| 5 |
import numpy as np
|
| 6 |
import pandas as pd
|
| 7 |
import tensorflow as tf
|
| 8 |
+
from valx import detect_profanity, detect_hate_speech
|
| 9 |
|
| 10 |
def custom_pad_sequences(sequences, maxlen, padding='pre', value=0):
|
| 11 |
"""
|
|
|
|
| 97 |
if parts and len(parts[-1]) < 3:
|
| 98 |
generated_name = " ".join(parts[:-1])
|
| 99 |
|
| 100 |
+
stripped = generated_name.strip()
|
| 101 |
+
hate_speech = detect_hate_speech(stripped)
|
| 102 |
+
profanity = detect_profanity([stripped], language='All')
|
| 103 |
+
output = ''
|
| 104 |
+
|
| 105 |
+
if profanity > 0:
|
| 106 |
+
output = "Profanity Detected"
|
| 107 |
+
else:
|
| 108 |
+
if hate_speech == ['Hate Speech']:
|
| 109 |
+
output = 'Hate Speech Detected'
|
| 110 |
+
elif hate_speech == ['Offensive Speech']:
|
| 111 |
+
output = 'Offensive Speech Detected'
|
| 112 |
+
elif hate_speech == ['No Hate and Offensive Speech']:
|
| 113 |
+
output = stripped
|
| 114 |
+
|
| 115 |
+
return output
|
| 116 |
|
| 117 |
def generateNames(type, amount, max_length=30, temperature=0.5, seed_text=""):
|
| 118 |
if type == "Terraria":
|