Spaces:
Runtime error
Runtime error
added custom words for profanity check
Browse files
app.py
CHANGED
@@ -1,3 +1,4 @@
|
|
|
|
1 |
import torch
|
2 |
import spaces
|
3 |
from PIL import Image
|
@@ -20,6 +21,16 @@ models = preload_models_from_standard_weights(model_file, Device)
|
|
20 |
## profanity check on input prompt
|
21 |
profanity.load_censor_words()
|
22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
|
24 |
def filter_prompt(prompt):
|
25 |
if profanity.contains_profanity(prompt):
|
|
|
1 |
+
import json #to load json file for custom words for profanity check
|
2 |
import torch
|
3 |
import spaces
|
4 |
from PIL import Image
|
|
|
21 |
## profanity check on input prompt
|
22 |
profanity.load_censor_words()
|
23 |
|
24 |
+
##fFunction to load custom words from json file
|
25 |
+
def load_custom_words(file_path):
|
26 |
+
with open(file_path, 'r') as file:
|
27 |
+
data = json.load(file)
|
28 |
+
return data["custom_words"]
|
29 |
+
|
30 |
+
#3 load and add custom words from the json file
|
31 |
+
custom_words = load_custom_words("profane.json")
|
32 |
+
profanity.add_censor_words(custom_words)
|
33 |
+
|
34 |
|
35 |
def filter_prompt(prompt):
|
36 |
if profanity.contains_profanity(prompt):
|