0xcyborg commited on
Commit
0d84d12
1 Parent(s): 36d56b8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -6
app.py CHANGED
@@ -1,6 +1,4 @@
1
  import gradio as gr
2
- from datasets import load_dataset
3
-
4
  import random
5
  import time
6
  import requests
@@ -11,8 +9,7 @@ import traceback
11
  from base64 import b64decode,b64encode
12
  from io import BytesIO
13
 
14
- word_list_dataset = load_dataset("stabilityai/word-list", data_files="list.txt")
15
- word_list = word_list_dataset["train"]['text']
16
 
17
 
18
 
@@ -21,6 +18,27 @@ with gr.Blocks(theme="darkdefault") as demo:
21
  def welcome(name):
22
  return f"Welcome to AIXRPL.com Minter, {name}!"
23
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
  def inference(_prompt,_token):
25
  try:
26
  from PIL import Image
@@ -28,8 +46,7 @@ with gr.Blocks(theme="darkdefault") as demo:
28
  import os
29
  print(_prompt,_token)
30
 
31
- for filter in word_list:
32
- if re.search(rf"\b{filter}\b", _prompt):
33
  return '','unsafe','','',''
34
 
35
  r = requests.post(url='https://xcyborgart-app.herokuapp.com/create',data={"prompt":_prompt,"token":_token})
 
1
  import gradio as gr
 
 
2
  import random
3
  import time
4
  import requests
 
9
  from base64 import b64decode,b64encode
10
  from io import BytesIO
11
 
12
+ from profanity_filter import ProfanityFilter
 
13
 
14
 
15
 
 
18
  def welcome(name):
19
  return f"Welcome to AIXRPL.com Minter, {name}!"
20
 
21
+
22
+ def profanityCheck(prompt):
23
+ prompt = prompt.replace('+',' ').replace('|',' ')
24
+ nlp = spacy.load('en')
25
+ profanity_filter = ProfanityFilter(nlps={'en': nlp}) # reuse spacy Language (optional)
26
+ nlp.add_pipe(profanity_filter.spacy_component, last=True)
27
+ pf = ProfanityFilter()
28
+ pf.censor_whole_words = False
29
+
30
+ doc = nlp(prompt)
31
+ if doc._.is_profane:
32
+ print(doc)
33
+ return True
34
+ for token in doc:
35
+ print(token)
36
+ if token._.is_profane:
37
+ return True
38
+
39
+ return False
40
+
41
+
42
  def inference(_prompt,_token):
43
  try:
44
  from PIL import Image
 
46
  import os
47
  print(_prompt,_token)
48
 
49
+ if profanityCheck(_prompt):
 
50
  return '','unsafe','','',''
51
 
52
  r = requests.post(url='https://xcyborgart-app.herokuapp.com/create',data={"prompt":_prompt,"token":_token})