File size: 1,198 Bytes
3249e1b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
"""Lightweight prompt guard for AI KING Studio (non-explicit only).

This is a first-line filter. Upstream Spaces keep their own safety checks.
"""
import re

BLOCKED_TERMS = [
    "nsfw", "nude", "nudity", "naked", "topless", "undress", "undressed", "lingerie",
    "explicit", "porn", "pornographic", "erotic", "sexual", "sexy", "fetish", "hentai",
    "uncensored", "see-through", "bikini", "onlyfans", "striptease",
    "gore", "beheading", "dismember",
    "teen", "minor", "child", "underage", "loli", "schoolgirl",
    "deepfake", "face swap onto", "remove clothes", "remove her clothes", "remove his clothes",
]
_PATTERN = re.compile(r"\b(" + "|".join(re.escape(t) for t in BLOCKED_TERMS) + r")\b", re.IGNORECASE)

CONSENT_NOTE = (
    "Only upload faces you own or have written permission to use. "
    "AI KING Studio is for non-explicit creative work only."
)


def check_prompt(text: str) -> str | None:
    """Return an error message if the prompt is blocked, else None."""
    if not text:
        return None
    m = _PATTERN.search(text)
    if m:
        return f"This prompt was blocked by AI KING's content rules (matched: '{m.group(0)}'). Keep it non-explicit."
    return None