AI-KING-Studio / safety.py
INTERNETCON's picture
Deploy AI KING Studio (CPU basic, MiniMax-H3 excluded, content filter on)
3249e1b verified
Raw History Blame Contribute Delete
1.2 kB
"""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