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." )