Spaces:
Running on Zero
Running on Zero
Download safety.py from INTERNETCON/AI-KING-Studio: direct link, hf CLI and curl.
- Browser
- Download file 1.2 kB
-
https://huggingface.co/spaces/INTERNETCON/AI-KING-Studio/resolve/main/safety.py
- Command line
-
hf download hf://spaces/INTERNETCON/AI-KING-Studio/safety.py
-
curl -L -o safety.py https://huggingface.co/spaces/INTERNETCON/AI-KING-Studio/resolve/main/safety.py
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 | |