GuiAworld commited on
Commit
880157f
·
verified ·
1 Parent(s): ab69576

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +1 -29
app.py CHANGED
@@ -227,11 +227,7 @@ def _editing_output_size(input_img: Image.Image, target_pixels: int) -> tuple[in
227
 
228
  # Start the guard subprocess before the main model is loaded: Popen forks this
229
  # process, and forking it after 35GB of weights are resident is far costlier.
230
- import ncii_guard
231
 
232
- print("[startup] starting NCII prompt guard subprocess...")
233
- ncii_guard.start()
234
- print(f"[startup] guard ready (threshold {GUARD_THRESHOLD}, edits only)")
235
 
236
  print("[startup] loading SenseNova-U1.5-8B-MoT (this may take a few minutes)...")
237
  sensenova_u1.set_attn_backend("auto")
@@ -254,29 +250,6 @@ import sn_aoti
254
  print(f"[startup] {sn_aoti.status()}")
255
  sn_aoti.maybe_load(model)
256
 
257
- def _guard_score(prompt: str) -> float | None:
258
- """P(ncii) for a prompt, or None if the guard is unavailable."""
259
- try:
260
- return float(ncii_guard.classify(prompt)["p_ncii"])
261
- except Exception as exc: # pragma: no cover - demo must survive an outage
262
- print(f"[guard] scoring failed ({exc!r}); allowing prompt")
263
- return None
264
-
265
-
266
- def _screen_prompt(prompt: str, editing: bool) -> None:
267
- """Reject NCII edit requests before a GPU worker is allocated."""
268
- if not editing and not GUARD_SCREEN_TEXT_TO_IMAGE:
269
- return
270
- score = _guard_score(prompt)
271
- if score is None:
272
- return
273
- if score >= GUARD_THRESHOLD:
274
- print(f"[guard] blocked prompt (p_ncii={score:.3f})")
275
- raise gr.Error(
276
- "This prompt was flagged by a content filter and wasn't run."
277
- )
278
- if score >= 0.3:
279
- print(f"[guard] allowed borderline prompt (p_ncii={score:.3f})")
280
 
281
 
282
 
@@ -468,8 +441,7 @@ def generate(
468
  img_cfg_scale = _clamp(img_cfg_scale, 1.0, 4.0, DEFAULT_IMG_CFG_SCALE)
469
 
470
  pil_images = _normalize_images(images)
471
- # Screen on CPU, before any GPU worker is allocated.
472
- _screen_prompt(prompt, editing=bool(pil_images))
473
  budget = _input_pixel_budget(len(pil_images))
474
  pil_inputs = [_prep_input_image(img, budget) for img in pil_images]
475
  if pil_inputs:
 
227
 
228
  # Start the guard subprocess before the main model is loaded: Popen forks this
229
  # process, and forking it after 35GB of weights are resident is far costlier.
 
230
 
 
 
 
231
 
232
  print("[startup] loading SenseNova-U1.5-8B-MoT (this may take a few minutes)...")
233
  sensenova_u1.set_attn_backend("auto")
 
250
  print(f"[startup] {sn_aoti.status()}")
251
  sn_aoti.maybe_load(model)
252
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
253
 
254
 
255
 
 
441
  img_cfg_scale = _clamp(img_cfg_scale, 1.0, 4.0, DEFAULT_IMG_CFG_SCALE)
442
 
443
  pil_images = _normalize_images(images)
444
+ # Screen on CPU, before any GPU worker is allocated
 
445
  budget = _input_pixel_budget(len(pil_images))
446
  pil_inputs = [_prep_input_image(img, budget) for img in pil_images]
447
  if pil_inputs: