Download ignored_preview.py from q6/N: direct link, hf CLI and curl.
- Browser
- Download file 856 Bytes
-
https://huggingface.co/spaces/q6/N/resolve/main/ignored_preview.py
- Command line
-
hf download hf://spaces/q6/N/ignored_preview.py
-
curl -L -o ignored_preview.py https://huggingface.co/spaces/q6/N/resolve/main/ignored_preview.py
856 Bytes
| from PIL import Image, ImageDraw | |
| TEXT_OVERLAY_COLOR = "#6d9" | |
| TEXT_OVERLAY_OPACITY = 0.55 | |
| BOX_WIDTH = 2 | |
| BOX_COLORS = { | |
| "eyes": "#6ad", | |
| "hands": "#a9e", | |
| "feet": "#fa6", | |
| } | |
| def save_ignored_preview(input_path, output_path, regions, text_mask=None): | |
| with Image.open(input_path) as source: | |
| preview = source.convert("RGB") | |
| if text_mask is not None: | |
| overlay = Image.new("RGB", preview.size, TEXT_OVERLAY_COLOR) | |
| tinted = Image.blend(preview, overlay, TEXT_OVERLAY_OPACITY) | |
| preview = Image.composite(tinted, preview, text_mask) | |
| draw = ImageDraw.Draw(preview) | |
| for part, boxes in regions.items(): | |
| for x1, y1, x2, y2 in boxes: | |
| draw.rectangle( | |
| (x1, y1, x2 - 1, y2 - 1), outline=BOX_COLORS[part], width=BOX_WIDTH, | |
| ) | |
| preview.save(output_path, format="PNG") | |