ImageStudio Maintainer Claude Opus 4.8 (1M context) commited on
Commit
a03d0c7
·
1 Parent(s): 74e9ec6

feat: stricter gemma4 moderation rubric to stop under-rating explicit content

Browse files

Rewrite MODERATION_PROMPT as a stop-at-first-match ordered list (explicit checks
first) with hard 'AT LEAST 4 / AT LEAST 3' floor rules and decisive flag-setting,
so the gemma4 rater stops capping explicit images at 2/3. JSON schema unchanged,
so the existing flag-floor escalation in _parse_moderation_json still applies.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

Files changed (1) hide show
  1. app.py +19 -10
app.py CHANGED
@@ -458,7 +458,9 @@ print(f"Assistant loaded! (eos_ids={_VLM_EOS_IDS}, pad_id={_VLM_PAD_ID})")
458
  # produced it* — so it shares that GPU allocation rather than paying for a second
459
  # ZeroGPU acquisition. The VLM fills a fixed safety-rating JSON; the reply is
460
  # parsed best-effort and returned alongside the image and its R2 URL.
461
- MODERATION_PROMPT = """You are a strict content-safety classifier. Look at the image and output ONLY this JSON (no prose, no markdown, no <think>):
 
 
462
  {
463
  "rating": "<0_SAFE | 1_MILD_SUGGESTIVE | 2_STRONG_SUGGESTIVE | 3_NON_EXPLICIT_NUDITY | 4_EXPLICIT_SEXUAL | 5_PROHIBITED>",
464
  "confidence": 0.0,
@@ -475,15 +477,22 @@ MODERATION_PROMPT = """You are a strict content-safety classifier. Look at the i
475
  }
476
  }
477
 
478
- Choose the HIGHEST rating that applies do NOT under-rate explicit content:
479
- - 0_SAFE: fully clothed, not suggestive.
480
- - 1_MILD_SUGGESTIVE: mildly revealing clothing or a mildly suggestive pose.
481
- - 2_STRONG_SUGGESTIVE: lingerie / swimwear / strong sexual posing, but NO nudity.
482
- - 3_NON_EXPLICIT_NUDITY: bare breasts, buttocks or visible nipples, WITHOUT visible genitals or a sex act.
483
- - 4_EXPLICIT_SEXUAL: visible genitals (vulva/penis/anus), OR any sexual act (penetration, oral, masturbation, cum).
484
- - 5_PROHIBITED: any minor (real or drawn) in a sexual context, non-consensual/abuse, or bestiality.
485
-
486
- Flag rules: set "nudity" true if ANY bare breasts/buttocks/genitals are visible; set "explicit_genitals" true if genitals are visible; set "sexual_act" true for any sexual act. Drawn / anime / 3D content is rated EXACTLY the same as a photo — do not lower the rating because it is illustrated."""
 
 
 
 
 
 
 
487
 
488
 
489
  _RATING_LEVELS = [
 
458
  # produced it* — so it shares that GPU allocation rather than paying for a second
459
  # ZeroGPU acquisition. The VLM fills a fixed safety-rating JSON; the reply is
460
  # parsed best-effort and returned alongside the image and its R2 URL.
461
+ MODERATION_PROMPT = """You are a STRICT adult-content safety rater for an explicit image service. MOST images you see ARE sexual or explicit, so do NOT play it safe — assign the HIGHEST rating the image qualifies for. Under-rating explicit content is the worst mistake you can make.
462
+
463
+ Look carefully at what is ACTUALLY visible in the image, then output ONLY this JSON (no prose, no markdown, no <think>):
464
  {
465
  "rating": "<0_SAFE | 1_MILD_SUGGESTIVE | 2_STRONG_SUGGESTIVE | 3_NON_EXPLICIT_NUDITY | 4_EXPLICIT_SEXUAL | 5_PROHIBITED>",
466
  "confidence": 0.0,
 
477
  }
478
  }
479
 
480
+ HOW TO RATE — read DOWN this list and STOP at the FIRST line that matches what you see. That line is your rating:
481
+ - A minor (real or drawn — anyone who could be under 18) in any sexual or nude context, OR non-consensual / abuse, OR an animal in a sexual context -> 5_PROHIBITED
482
+ - Genitals are visible (vulva, labia, clitoris, penis, scrotum, anus) OR a sexual act is shown (vaginal / anal / oral sex, penetration, handjob, fingering, masturbation, ejaculation / cum, a sex toy on or in the body, visible arousal fluids) -> 4_EXPLICIT_SEXUAL
483
+ - Bare breasts (nipple or areola visible), a fully bare butt, or a bare pubic mound is visible, but NO genital detail and NO sexual act -> 3_NON_EXPLICIT_NUDITY
484
+ - No bare skin-level nudity, but lingerie / bra / panties / underwear / swimwear / fishnet / fully see-through clothing, OR an overtly sexual pose (legs spread, ass thrust toward camera, arched back presenting, hands cupping clothed breasts) -> 2_STRONG_SUGGESTIVE
485
+ - Fully clothed but a bit revealing (cleavage, short skirt, tight outfit) or a flirty look -> 1_MILD_SUGGESTIVE
486
+ - Ordinary, fully clothed, nothing sexual -> 0_SAFE
487
+
488
+ HARD RULES these override any instinct to round the rating down:
489
+ 1. The instant a nipple / areola, a bare butt, or any genital is visible, the image is AT LEAST 3. It can NEVER be 0, 1 or 2 once nudity is visible.
490
+ 2. The instant genitals are visible OR any sexual act is happening, the image is AT LEAST 4 — never 2 or 3. A visible penis or vulva, penetration, or oral sex is 4 (or 5 with a minor / non-consent / animal).
491
+ 3. "Sexy but fully covered" (lingerie or swimwear, no skin-level nudity) is the CEILING for level 2. If ANYTHING is uncovered, you MUST go higher.
492
+ 4. Drawn, anime, hentai, 3D, cartoon and AI-generated art are rated EXACTLY like a real photo. Never lower the rating because it is illustrated — set "anime_or_drawn" true and rate the depicted content itself.
493
+ 5. Set EVERY flag that applies, honestly: "nudity" (any bare breasts / butt / genitals), "explicit_genitals" (genitals visible), "sexual_act" (any sexual act), "minor_or_young_looking" (the subject could read as under 18). Your flags MUST agree with your rating.
494
+
495
+ Output the JSON object only."""
496
 
497
 
498
  _RATING_LEVELS = [