Spaces:
Running on Zero
Running on Zero
ImageStudio Maintainer commited on
Commit ·
d34aeb0
1
Parent(s): a03d0c7
tmp: add moderate_debug endpoint for rubric tuning (to be removed)
Browse files
app.py
CHANGED
|
@@ -573,13 +573,13 @@ def _parse_moderation_json(text):
|
|
| 573 |
return {"ok": False, "rating": None, "confidence": None, "flags": None, "raw": raw}
|
| 574 |
|
| 575 |
|
| 576 |
-
def _moderate_image_inner(image, max_new_tokens=320):
|
| 577 |
"""Synchronously run the VLM moderation check on a PIL image (GPU-side)."""
|
| 578 |
messages = [{
|
| 579 |
"role": "user",
|
| 580 |
"content": [
|
| 581 |
{"type": "image", "image": image},
|
| 582 |
-
{"type": "text", "text": MODERATION_PROMPT},
|
| 583 |
],
|
| 584 |
}]
|
| 585 |
inputs = vlm_processor.apply_chat_template(
|
|
@@ -1160,6 +1160,23 @@ def _image_video_check_gpu(image, message, reasoning, max_new_tokens, system_pro
|
|
| 1160 |
yield from _vlm_chat_core(message, image, reasoning, max_new_tokens, system_prompt)
|
| 1161 |
|
| 1162 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1163 |
def generate_and_upload(
|
| 1164 |
model_name,
|
| 1165 |
prompt,
|
|
@@ -1842,6 +1859,17 @@ with gr.Blocks(fill_height=True) as demo:
|
|
| 1842 |
api_name="image_to_video_assets",
|
| 1843 |
)
|
| 1844 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1845 |
# UI-less combined endpoint: text -> first-frame image (R2) + video prompt.
|
| 1846 |
# `gr.api` derives its schema from the function's type hints and registers no
|
| 1847 |
# components, so it adds an API route without touching the visible UI.
|
|
|
|
| 573 |
return {"ok": False, "rating": None, "confidence": None, "flags": None, "raw": raw}
|
| 574 |
|
| 575 |
|
| 576 |
+
def _moderate_image_inner(image, max_new_tokens=320, prompt=None):
|
| 577 |
"""Synchronously run the VLM moderation check on a PIL image (GPU-side)."""
|
| 578 |
messages = [{
|
| 579 |
"role": "user",
|
| 580 |
"content": [
|
| 581 |
{"type": "image", "image": image},
|
| 582 |
+
{"type": "text", "text": prompt or MODERATION_PROMPT},
|
| 583 |
],
|
| 584 |
}]
|
| 585 |
inputs = vlm_processor.apply_chat_template(
|
|
|
|
| 1160 |
yield from _vlm_chat_core(message, image, reasoning, max_new_tokens, system_prompt)
|
| 1161 |
|
| 1162 |
|
| 1163 |
+
# --- TEMP moderation-prompt tuning endpoint (remove once rubric is finalized) ---
|
| 1164 |
+
@spaces.GPU
|
| 1165 |
+
def _moderate_debug_gpu(image, prompt_text=""):
|
| 1166 |
+
"""Run the exact moderation inference with a caller-supplied prompt so the
|
| 1167 |
+
rubric can be tuned against fixed images via the real GPU path."""
|
| 1168 |
+
return _moderate_image_inner(image, prompt=(prompt_text or None))
|
| 1169 |
+
|
| 1170 |
+
|
| 1171 |
+
def moderate_debug(image, prompt_text="", progress=gr.Progress(track_tqdm=True)):
|
| 1172 |
+
if image is None:
|
| 1173 |
+
return {"error": "no image"}
|
| 1174 |
+
try:
|
| 1175 |
+
return _moderate_debug_gpu(image, prompt_text)
|
| 1176 |
+
except Exception as exc: # noqa: BLE001
|
| 1177 |
+
return {"error": f"{type(exc).__name__}: {exc}"}
|
| 1178 |
+
|
| 1179 |
+
|
| 1180 |
def generate_and_upload(
|
| 1181 |
model_name,
|
| 1182 |
prompt,
|
|
|
|
| 1859 |
api_name="image_to_video_assets",
|
| 1860 |
)
|
| 1861 |
|
| 1862 |
+
# TEMP: moderation-prompt tuning endpoint (remove once rubric is finalized).
|
| 1863 |
+
with gr.Row(visible=False):
|
| 1864 |
+
mdbg_image = gr.Image(label="mdbg image", type="pil")
|
| 1865 |
+
mdbg_prompt = gr.Textbox(label="mdbg prompt", value="")
|
| 1866 |
+
mdbg_btn = gr.Button("mdbg", visible=False)
|
| 1867 |
+
mdbg_out = gr.JSON(label="mdbg out")
|
| 1868 |
+
mdbg_btn.click(
|
| 1869 |
+
fn=moderate_debug, inputs=[mdbg_image, mdbg_prompt], outputs=[mdbg_out],
|
| 1870 |
+
api_name="moderate_debug",
|
| 1871 |
+
)
|
| 1872 |
+
|
| 1873 |
# UI-less combined endpoint: text -> first-frame image (R2) + video prompt.
|
| 1874 |
# `gr.api` derives its schema from the function's type hints and registers no
|
| 1875 |
# components, so it adds an API route without touching the visible UI.
|