Spaces:
Running
Running
File size: 1,423 Bytes
e6404d0 | 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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | """Safety / rating policy — the single source of truth for rating conversions.
Historically three separate mappings lived in this module and tag_warehouse
(UI order, tag order, UI->tag ceiling). They are unified here; tag_warehouse
re-exports the canonical constants for backwards compatibility.
"""
SAFETY_TAG_MAP = {
"pg": "safe",
"pg13": "safe",
"pg16": "sensitive",
"r": "nsfw",
"r+": "explicit",
}
# UI-facing rating levels (what the user picks in the rating dropdown).
UI_RATING_ORDER = {"pg": 0, "pg13": 1, "pg16": 2, "r": 3, "r+": 4}
# Pool / tag entry rating levels (the "rating" field of every pool entry).
TAG_RATING_ORDER = {"sfw": 0, "suggestive": 1, "nsfw": 2, "explicit": 3}
# The highest tag-pool rating allowed under a given UI rating.
UI_TO_TAG_CEILING = {
"pg": "sfw",
"pg13": "sfw",
"pg16": "suggestive",
"r": "nsfw",
"r+": "explicit",
}
def get_safety_tag(rating: str) -> str:
return SAFETY_TAG_MAP.get(rating, "safe")
def ui_rating_to_tag_ceiling(user_rating: str) -> str:
"""Map a UI rating (pg/pg13/pg16/r/r+) to the max tag-pool rating allowed."""
return UI_TO_TAG_CEILING.get(user_rating, "sfw")
def is_tag_allowed(tag_rating: str, user_rating: str) -> bool:
tag_level = TAG_RATING_ORDER.get(tag_rating, 0)
ceiling_level = TAG_RATING_ORDER.get(ui_rating_to_tag_ceiling(user_rating), 0)
return tag_level <= ceiling_level
|