vybbench / scoring /references.py
dzcoco's picture
Add files using upload-large-folder tool
bd00f85 verified
Raw History Blame Contribute Delete
1.51 kB
"""The prompts, and the color ground truth.
The font ground truths ship as rendered images under ``references/`` -- one
PIL render of the case's word in its pinned font file (provenance per case in
``data/fonts.jsonl``: google/fonts commit, file path, sha256). The color
ground truth is defined here: a solid rectangle on white, which scores exactly
zero through the color metric.
"""
from __future__ import annotations
from PIL import Image, ImageDraw
from .cases import FontCase
CANVAS = 1024
FONT_PROMPT_TEMPLATE = (
'A plain white image. The word "{word}" in solid black, centered, in the '
"font {family} {variant}. Nothing else in the image."
)
COLOR_PROMPT_TEMPLATE = (
"A plain white (#FFFFFF) image with a single solid rectangle of {hex} in "
"the middle. No border, no shadow, no texture, no gradient."
)
RECT_FRACTION = 0.5 # rectangle side, as a fraction of the canvas
def font_prompt(case: FontCase) -> str:
return FONT_PROMPT_TEMPLATE.format(
family=case.family, variant=case.variant, word=case.word
)
def color_prompt(hex_color: str) -> str:
return COLOR_PROMPT_TEMPLATE.format(hex=hex_color.upper())
def render_color_reference(hex_color: str, canvas: int = CANVAS) -> Image.Image:
image = Image.new("RGB", (canvas, canvas), "#FFFFFF")
side = round(canvas * RECT_FRACTION)
corner = (canvas - side) // 2
ImageDraw.Draw(image).rectangle(
(corner, corner, corner + side, corner + side), fill=hex_color
)
return image