HARRY07979 commited on
Commit
f8e02fa
·
verified ·
1 Parent(s): 6cdba71

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +54 -0
app.py CHANGED
@@ -48,9 +48,60 @@ pipeline.to("cpu")
48
  pipeline.compile() # Biên dịch mô hình nếu hỗ trợ
49
 
50
  # Tối ưu hóa từ điển NSFW - sử dụng set để tìm kiếm nhanh hơn
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51
 
 
 
 
 
 
 
 
 
 
 
 
 
 
52
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53
  # Kiểm tra từ khóa trung bình + ngữ cảnh nhạy cảm
 
 
 
 
 
 
54
  def infer(
55
  prompt: str,
56
  negative_prompt: str,
@@ -70,6 +121,9 @@ def infer(
70
  print(f"🚫 Negative Prompt: {negative_prompt or '[None]'}")
71
 
72
  # Tối ưu hóa kiểm tra NSFW
 
 
 
73
  if randomize_seed:
74
  seed = random.randint(0, np.iinfo(np.int32).max)
75
  print(f"🎲 Random Seed generated: {seed}")
 
48
  pipeline.compile() # Biên dịch mô hình nếu hỗ trợ
49
 
50
  # Tối ưu hóa từ điển NSFW - sử dụng set để tìm kiếm nhanh hơn
51
+ NSFW_HIGH = {
52
+ "nude", "naked", "sex", "porn", "xxx", "fuck", "dick", "cock", "pussy", "vagina", "penis",
53
+ "boobs", "tits", "breasts", "bra", "panties", "underwear", "lingerie", "orgasm", "cum",
54
+ "blowjob", "handjob", "masturbate", "rape", "gangbang", "incest", "hentai", "lewd",
55
+ "erotic", "kinky", "bondage", "bdsm", "squirt", "creampie", "threesome", "orgy", "yaoi",
56
+ "yuri", "futanari", "cunnilingus", "fellatio", "anal", "paizuri", "bukkake", "guro",
57
+ "vore", "tentacle", "netorare", "cuckold", "exhibitionism", "voyeurism", "poop", "pee",
58
+ "poo", "shit", "piss", "scat", "diarrhea", "vomit", "gore", "blood", "murder",
59
+ "torture", "suicide", "decapitation", "mutilation", "drugs", "cocaine", "heroin",
60
+ "lsd", "ecstasy", "vlxx"
61
+ }
62
+
63
+ NSFW_MEDIUM = {
64
+ "bikini", "swimwear", "sexy", "succubus", "leather", "latex", "stockings", "miniskirt",
65
+ "cleavage", "thighs", "ass", "butt", "skirt", "dress", "topless", "wet", "moaning",
66
+ "spread", "legs apart", "tight", "revealing", "provocative", "suggestive", "flirty"
67
+ }
68
 
69
+ NSFW_PHRASES = {
70
+ "spreading legs", "removing bra", "pulling panties", "sucking dick", "licking pussy",
71
+ "penetrating", "fucking scene", "hard cock", "wet pussy", "big tits", "exposed breasts",
72
+ "nipples visible", "ass spread", "thigh gap", "camel toe", "pussy lips", "cum on face",
73
+ "blowjob scene", "anal sex", "titty fuck", "gang rape", "group sex", "public sex",
74
+ "hidden camera", "peeing girl", "pooping girl", "covered in blood", "cutting flesh",
75
+ "snorting cocaine", "injecting heroin", "hallucinating", "smoking weed"
76
+ }
77
+
78
+ SENSITIVE_CONTEXT = {
79
+ "spread", "removing", "pulling", "sucking", "licking", "penetrating",
80
+ "fucking", "hard", "wet", "exposed", "visible", "ass", "tight", "revealing"
81
+ }
82
 
83
+ # Tối ưu hóa hàm NSFW detection
84
+ @lru_cache(maxsize=1024)
85
+ def detect_nsfw(prompt: str):
86
+ prompt_lower = prompt.lower()
87
+
88
+ # Kiểm tra từ khóa cao
89
+ words = set(re.findall(r'\b\w+\b', prompt_lower))
90
+ if words & NSFW_HIGH:
91
+ return True
92
+
93
+ # Kiểm tra cụm từ NSFW
94
+ for phrase in NSFW_PHRASES:
95
+ if phrase in prompt_lower:
96
+ return True
97
+
98
  # Kiểm tra từ khóa trung bình + ngữ cảnh nhạy cảm
99
+ medium_matches = words & NSFW_MEDIUM
100
+ if medium_matches and (words & SENSITIVE_CONTEXT):
101
+ return True
102
+
103
+ return False
104
+
105
  def infer(
106
  prompt: str,
107
  negative_prompt: str,
 
121
  print(f"🚫 Negative Prompt: {negative_prompt or '[None]'}")
122
 
123
  # Tối ưu hóa kiểm tra NSFW
124
+ if detect_nsfw(prompt):
125
+ raise gr.Error("⚠️ Prompt contains NSFW content. Please use a safe prompt.")
126
+
127
  if randomize_seed:
128
  seed = random.randint(0, np.iinfo(np.int32).max)
129
  print(f"🎲 Random Seed generated: {seed}")