""" test_selector.py ---------------- Demonstrates the content-aware infographic selector: 1. Derive requirements from content (item count, longest label, longest description). 2. Query bank catalogue — selector picks the slide whose boxes fit the text. 3. Clone that slide and fill it with the real content. py test_selector.py """ import json import sys from pathlib import Path ROOT = Path(__file__).parent.parent BANK = ROOT / "infographic_bank" TMPL = ROOT / "Template new.pptx" OUT = Path(__file__).parent / "output" / "selector_test.pptx" CAT = BANK / "bank_catalogue_slim.json" sys.path.insert(0, str(Path(__file__).parent)) from engine.slide_cloner import SlideCloner from engine.text_replacer import replace_slide_text from engine.slide_selector import select_slide, content_requirements with open(CAT, encoding="utf-8") as f: catalogue = json.load(f) cloner = SlideCloner(str(OUT), template_path=str(TMPL)) # ── Slide 1: 5-step process ────────────────────────────────────────────────── content1 = { "title": "Five Steps to a Powerful Opening", "steps": [ {"label": "Hook", "description": "Open with a bold statement or question that grabs attention."}, {"label": "Context", "description": "Give the audience a clear reason to listen to what comes next."}, {"label": "Objective", "description": "State plainly what the audience will learn or take away."}, {"label": "Structure", "description": "Preview the flow of your talk so the audience can follow along."}, {"label": "Engage", "description": "Invite early participation to build rapport and energy."}, ], } reqs1 = content_requirements(content1) reqs1["visual_type"] = "process" entry1 = select_slide(catalogue, reqs1) print(f"Slide 1 -> {entry1['file']} [{entry1['slide_index']}] " f"(label_cap={entry1.get('max_label_chars')}, desc_cap={entry1.get('max_desc_chars')})") slide1 = cloner.clone_slide(str(BANK / entry1["file"]), entry1["slide_index"]) replace_slide_text(slide1, content1) # ── Slide 2: 6-item timeline ───────────────────────────────────────────────── content2 = { "title": "Course Progression", "steps": [ {"label": "Introduction", "description": "Understanding the basics of public speaking"}, {"label": "Fear", "description": "Facing and overcoming the fear"}, {"label": "Message", "description": "Getting your point across clearly"}, {"label": "Message", "description": "Getting your point across clearly"}, {"label": "Delivery", "description": "Body language and vocal techniques"}, {"label": "Engagement", "description": "Connecting with your audience"}, {"label": "Mastery", "description": "Putting it all into practice"}, ], } reqs2 = content_requirements(content2) reqs2["visual_type"] = "timeline" entry2 = select_slide(catalogue, reqs2) print(f"Slide 2 -> {entry2['file']} [{entry2['slide_index']}] " f"(label_cap={entry2.get('max_label_chars')}, desc_cap={entry2.get('max_desc_chars')})") slide2 = cloner.clone_slide(str(BANK / entry2["file"]), entry2["slide_index"]) replace_slide_text(slide2, content2) # ── Slide 3: 8-item hub ────────────────────────────────────────────────────── content3 = { "title": "Gaining Confidence in What You Say", "steps": [ {"label": "Know", "description": "Master your content before stepping on stage."}, {"label": "Tailor", "description": "Adapt language and examples to your audience."}, {"label": "Stories", "description": "Anchor key points in real-world stories."}, {"label": "Authentic", "description": "Speak from genuine experience and belief."}, {"label": "Prepare", "description": "Rehearse until the words flow naturally."}, {"label": "Nerves", "description": "Use breathing and pacing to stay calm."}, {"label": "Questions", "description": "Welcome interaction to build confidence."}, {"label": "Reflect", "description": "Review each performance and adjust."}, ], } reqs3 = content_requirements(content3) reqs3["visual_type"] = "hub" entry3 = select_slide(catalogue, reqs3) print(f"Slide 3 -> {entry3['file']} [{entry3['slide_index']}] " f"(label_cap={entry3.get('max_label_chars')}, desc_cap={entry3.get('max_desc_chars')})") slide3 = cloner.clone_slide(str(BANK / entry3["file"]), entry3["slide_index"]) replace_slide_text(slide3, content3) cloner.save() print(f"\nOpen output/selector_test.pptx to verify.")