Spaces:
Running on Zero
Running on Zero
Download validators.py from maxmcd/Selectable-Face-Swap: direct link, hf CLI and curl.
- Browser
- Download file 812 Bytes
-
https://huggingface.co/spaces/maxmcd/Selectable-Face-Swap/resolve/main/validators.py
- Command line
-
hf download hf://spaces/maxmcd/Selectable-Face-Swap/validators.py
-
curl -L -o validators.py https://huggingface.co/spaces/maxmcd/Selectable-Face-Swap/resolve/main/validators.py
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." | |
| ) | |