"""Render a synthetic Devanagari (Nepali) test page with known ground truth. Each GT line is drawn with PIL/raqm (proper shaping via HarfBuzz) at a known position, so we get both the exact text and per-line boxes. This exists only for smoke tests of the Indra pipeline on this machine: real evaluation happens on the remote machine's frozen sets. The font (OFL) and the page here are test assets, not eval data. Usage: PYTHONPATH=/tmp/opencode/indra-lib python3 make_synth_page.py [outdir] """ import json import sys from pathlib import Path from PIL import Image, ImageDraw, ImageFont FONT = Path(__file__).parent / "testdata" / "NotoSansDevanagari.ttf" # Mixed Nepali coverage: initial/final matras, conjuncts, nukta, danda, # digits, ॐ, ष/ृ, and a Latin word (vocab contains Latin too). LINES = [ "नेपाल भाषा ऱूपमा", "क्षरत्र ज्ञान तन्त्र पुनर्निर्माण", "ॐ नमः शिवाय ।", "उपयोगकर्ता सङ्केत द्वोपक स्मृति", "क१२३४५६७८९० ख२०२६ ग₹।", "फलमूल असन्न हृदय ऋतु", "नेपाल काठमाडौँ बराहनगर ॥", "कितावबाट गर्दैछु भव्य यात्रा", "५६ सालदेखि ४८ जना ।", "स्वतन्त्र बृहत् जीवनसाथी", ] def main(argv=None): out = Path(argv[0] if argv else ".").resolve() out.mkdir(parents=True, exist_ok=True) Wpx, Hpx = 1240, 1754 # ~A4 @150dpi size = 32 # px; run small: big pages skew the smoke test toward slow det font = ImageFont.truetype(str(FONT), size) img = Image.new("RGB", (Wpx, Hpx), "white") d = ImageDraw.Draw(img) gt = [] y = 90 for i, text in enumerate(LINES): d.text((60, y), text, font=font, fill="black") bb = d.textbbox((60, y), text, font=font) gt.append( { "i": i, "text": text, "box": [float(bb[0]), float(bb[1]), float(bb[2]), float(bb[3])], } ) y += int(size * 2.0) page = out / "synth_nepali_page.png" img.save(page) gt_file = out / "synth_nepali_gt.jsonl" gt_file.write_text(json.dumps({"file": page.name, "lines": gt}) + "\n") # predict-schema record (image/lines/text) for `cer` rec_file = out / "synth_nepali_record.jsonl" rec_file.write_text( json.dumps( { "image": str(page), "page": 1, "w": Wpx, "h": Hpx, "lines": [{"box": g["box"], "text": g["text"], "conf": 1.0} for g in gt], "text": "\n".join(g["text"] for g in gt), }, ensure_ascii=False, ) + "\n", encoding="utf-8", ) print(f"image: {page}\ngt: {gt_file}\nrecord: {rec_file}") for g in gt: print(f" {g['i']:2d} {g['text']}") if __name__ == "__main__": main(sys.argv[1:])