Selectable-Face-Swap / validators.py
someone-in-the-world's picture
Claude Sonnet 4.6
Add pre-commit black formatter and apply initial formatting
db79f31
Raw History Blame Contribute Delete
812 Bytes
import gradio as gr
def _validate_target(target_b64):
if not target_b64 or target_b64.strip() in ("", "null"):
raise gr.Error("Please upload a target image.")
def _validate_selection(selected_indices):
if not selected_indices:
raise gr.Error("Please select at least one face to swap.")
def _validate_sources(selected_indices, sources):
for idx in selected_indices:
if not sources.get(str(idx)):
raise gr.Error(f"Please upload a source image for face {idx + 1}.")
def _validate_bboxes(selected_indices, bboxes):
for idx in selected_indices:
bbox = bboxes.get(str(idx))
if not bbox or len(bbox) != 4:
raise gr.Error(
f"Missing bounding box for face {idx + 1}. Please re-upload the target image."
)