docs: make visual contact sheet readable
Browse files
images/visual_tables_contact_sheet.png
CHANGED
|
|
Git LFS Details
|
|
|
Git LFS Details
|
results/archive_manifest.json
CHANGED
|
@@ -26,9 +26,9 @@
|
|
| 26 |
"sha256": "3c42502d5b311c9654768d7531aa574ebb012df8ee646d322ada03327a5da0b2"
|
| 27 |
},
|
| 28 |
{
|
| 29 |
-
"bytes":
|
| 30 |
"path": "images/visual_tables_contact_sheet.png",
|
| 31 |
-
"sha256": "
|
| 32 |
},
|
| 33 |
{
|
| 34 |
"bytes": 1543,
|
|
|
|
| 26 |
"sha256": "3c42502d5b311c9654768d7531aa574ebb012df8ee646d322ada03327a5da0b2"
|
| 27 |
},
|
| 28 |
{
|
| 29 |
+
"bytes": 8677992,
|
| 30 |
"path": "images/visual_tables_contact_sheet.png",
|
| 31 |
+
"sha256": "4bda8d27c7abde7ea4b620f0c1ea0d197116609fb9b70a69d03b0275db78b7b3"
|
| 32 |
},
|
| 33 |
{
|
| 34 |
"bytes": 1543,
|
scripts/render_visual_tables.py
CHANGED
|
@@ -218,6 +218,31 @@ def render(
|
|
| 218 |
return destination
|
| 219 |
|
| 220 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 221 |
def main() -> int:
|
| 222 |
parser = argparse.ArgumentParser(description=__doc__)
|
| 223 |
parser.add_argument("--run-dir", type=Path, required=True)
|
|
@@ -229,9 +254,9 @@ def main() -> int:
|
|
| 229 |
rows = load_rows(args.run_dir, prompt_ids)
|
| 230 |
prompts = [rows[("png_baseline", prompt_id)] for prompt_id in prompt_ids]
|
| 231 |
output = args.output
|
| 232 |
-
for key, codec in CODECS.items()
|
| 233 |
-
|
| 234 |
-
LOGGER.info("rendered %d tables to %s", len(CODECS), output)
|
| 235 |
return 0
|
| 236 |
|
| 237 |
|
|
|
|
| 218 |
return destination
|
| 219 |
|
| 220 |
|
| 221 |
+
def render_contact_sheet(tables: list[Path], output: Path, *, gap: int = 48) -> Path:
|
| 222 |
+
"""Stack full-width tables vertically so labels remain readable in browser viewers."""
|
| 223 |
+
if not tables:
|
| 224 |
+
raise ValueError("at least one table is required")
|
| 225 |
+
images: list[Image.Image] = []
|
| 226 |
+
for table in tables:
|
| 227 |
+
with Image.open(table) as image:
|
| 228 |
+
images.append(image.convert("RGB"))
|
| 229 |
+
width = max(image.width for image in images)
|
| 230 |
+
height = sum(image.height for image in images) + gap * (len(images) - 1)
|
| 231 |
+
canvas = Image.new("RGB", (width, height), BG)
|
| 232 |
+
y = 0
|
| 233 |
+
for index, image in enumerate(images):
|
| 234 |
+
canvas.paste(image, ((width - image.width) // 2, y))
|
| 235 |
+
y += image.height
|
| 236 |
+
if index < len(images) - 1:
|
| 237 |
+
divider_y = y + gap // 2
|
| 238 |
+
ImageDraw.Draw(canvas).rectangle((24, divider_y - 1, width - 24, divider_y + 1), fill="#263746")
|
| 239 |
+
y += gap
|
| 240 |
+
destination = output / "visual_tables_contact_sheet.png"
|
| 241 |
+
destination.parent.mkdir(parents=True, exist_ok=True)
|
| 242 |
+
canvas.save(destination, format="PNG", optimize=True)
|
| 243 |
+
return destination
|
| 244 |
+
|
| 245 |
+
|
| 246 |
def main() -> int:
|
| 247 |
parser = argparse.ArgumentParser(description=__doc__)
|
| 248 |
parser.add_argument("--run-dir", type=Path, required=True)
|
|
|
|
| 254 |
rows = load_rows(args.run_dir, prompt_ids)
|
| 255 |
prompts = [rows[("png_baseline", prompt_id)] for prompt_id in prompt_ids]
|
| 256 |
output = args.output
|
| 257 |
+
rendered = [render(key, codec, args.run_dir.resolve(), prompts, rows, output) for key, codec in CODECS.items()]
|
| 258 |
+
render_contact_sheet(rendered, output)
|
| 259 |
+
LOGGER.info("rendered %d tables and a vertical contact sheet to %s", len(CODECS), output)
|
| 260 |
return 0
|
| 261 |
|
| 262 |
|
tests/test_render_visual_tables.py
CHANGED
|
@@ -7,7 +7,7 @@ from pathlib import Path
|
|
| 7 |
|
| 8 |
import pytest
|
| 9 |
from PIL import Image
|
| 10 |
-
from render_visual_tables import CODECS, load_prompt_ids, load_rows, render
|
| 11 |
|
| 12 |
|
| 13 |
def test_load_prompt_ids_accepts_manifest_object(tmp_path: Path) -> None:
|
|
@@ -180,3 +180,19 @@ def test_render_rejects_fifo_replacement_without_blocking(tmp_path: Path) -> Non
|
|
| 180 |
loaded,
|
| 181 |
tmp_path / "output",
|
| 182 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
import pytest
|
| 9 |
from PIL import Image
|
| 10 |
+
from render_visual_tables import CODECS, load_prompt_ids, load_rows, render, render_contact_sheet
|
| 11 |
|
| 12 |
|
| 13 |
def test_load_prompt_ids_accepts_manifest_object(tmp_path: Path) -> None:
|
|
|
|
| 180 |
loaded,
|
| 181 |
tmp_path / "output",
|
| 182 |
)
|
| 183 |
+
|
| 184 |
+
|
| 185 |
+
def test_render_contact_sheet_stacks_tables_at_full_width(tmp_path: Path) -> None:
|
| 186 |
+
first = tmp_path / "first.png"
|
| 187 |
+
second = tmp_path / "second.png"
|
| 188 |
+
Image.new("RGB", (100, 50), "red").save(first)
|
| 189 |
+
Image.new("RGB", (80, 60), "blue").save(second)
|
| 190 |
+
|
| 191 |
+
output = render_contact_sheet([first, second], tmp_path / "output", gap=20)
|
| 192 |
+
|
| 193 |
+
with Image.open(output) as image:
|
| 194 |
+
assert image.size == (100, 130)
|
| 195 |
+
assert image.getpixel((0, 0)) == (255, 0, 0)
|
| 196 |
+
assert image.getpixel((10, 60)) == (13, 20, 27)
|
| 197 |
+
assert image.getpixel((10, 70)) == (0, 0, 255)
|
| 198 |
+
assert image.getpixel((10, 129)) == (0, 0, 255)
|