FoxLoverAI commited on
Commit
a788fe5
·
verified ·
1 Parent(s): 0cdbe83

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -4
app.py CHANGED
@@ -20,7 +20,7 @@ except ImportError:
20
  HF_TOKEN = os.environ.get("HF_TOKEN", "").strip()
21
  BUCKET_ID = os.environ.get("BUCKET_ID", "").strip()
22
 
23
- GUARD_MODEL = "hfmlsoc/ncii-guard-v02"
24
  NCII_THRESHOLD = 0.70
25
 
26
  # Cosmetic dropdown only — the sole backend is the ncii-guard classifier.
@@ -125,6 +125,7 @@ def log_submission(session_id: str, image: Image.Image, prompt: str,
125
 
126
 
127
  # --- Main pipeline ---------------------------------------------------------------
 
128
  BACKEND_FAILURE_MSG = "⚠️ Backend failure. Please try again later."
129
 
130
 
@@ -156,7 +157,6 @@ def edit_image(image, prompt, model_choice, request: gr.Request,
156
  try:
157
  progress(0.05, desc="Analyzing image…")
158
  score = ncii_score(prompt)
159
- _credible_progress(progress) # pad the instant check to ~18s
160
  status = "blocked" if score > NCII_THRESHOLD else "allowed"
161
  except Exception as err:
162
  error_detail = str(err)
@@ -164,8 +164,13 @@ def edit_image(image, prompt, model_choice, request: gr.Request,
164
  finally:
165
  log_submission(session_id, image, prompt, status, score, error_detail)
166
 
167
- # Honeypot: no image is ever produced or shown — the study is how users try
168
- # to get around the guard, so every outcome looks identical.
 
 
 
 
 
169
  raise gr.Error(BACKEND_FAILURE_MSG)
170
 
171
 
 
20
  HF_TOKEN = os.environ.get("HF_TOKEN", "").strip()
21
  BUCKET_ID = os.environ.get("BUCKET_ID", "").strip()
22
 
23
+ GUARD_MODEL = "hfmlsoc/ncii-light-guard-v01"
24
  NCII_THRESHOLD = 0.70
25
 
26
  # Cosmetic dropdown only — the sole backend is the ncii-guard classifier.
 
125
 
126
 
127
  # --- Main pipeline ---------------------------------------------------------------
128
+ BLOCKED_MSG = "🚫 Prompt blocked."
129
  BACKEND_FAILURE_MSG = "⚠️ Backend failure. Please try again later."
130
 
131
 
 
157
  try:
158
  progress(0.05, desc="Analyzing image…")
159
  score = ncii_score(prompt)
 
160
  status = "blocked" if score > NCII_THRESHOLD else "allowed"
161
  except Exception as err:
162
  error_detail = str(err)
 
164
  finally:
165
  log_submission(session_id, image, prompt, status, score, error_detail)
166
 
167
+ # Guard caught it: tell the user right away.
168
+ if status == "blocked":
169
+ raise gr.Error(BLOCKED_MSG)
170
+
171
+ # Passed (or guard errored): no image is ever produced, so wait a bit to look
172
+ # like real work, then fail. The study is how users retry to get past the guard.
173
+ _credible_progress(progress)
174
  raise gr.Error(BACKEND_FAILURE_MSG)
175
 
176