Skip to content

Yuan1z0825/nature-skills / skills/nature-image2ppt

nature-image2ppt

Flagged

Reconstruct slide images, screenshots, scanned PDFs, or image-only PPTX files as object-level editable PowerPoint. Use for 图片转可编辑PPT、截图还原PPT and diagram reconstruction; not authoring a new deck from research notes.

FileKindSize
.gitignoreother573 B
LICENSEother1.1 KB
README.mdmarkdown4.0 KB
README_EN.mdmarkdown4.3 KB
SKILL.mdskill md9.8 KB
agents/openai.yamlconfig272 B
cli/image2ppt/__init__.pyscript22 B
cli/image2ppt/cli.pyscript698 B
cli/image2ppt/runtime/__init__.pyscript69 B
cli/image2ppt/runtime/_input_normalization.pyscript15.9 KB
cli/image2ppt/runtime/_page_artifacts.pyscript4.5 KB
cli/image2ppt/runtime/build_pptx_from_manifest.pyscript54.0 KB
cli/image2ppt/runtime/configure_image_backend.pyscript5.8 KB
cli/image2ppt/runtime/deck_run_state.pyscript5.6 KB
cli/image2ppt/runtime/deck_text_hints.pyscript6.8 KB
cli/image2ppt/runtime/finalize_deck_run.pyscript3.1 KB
cli/image2ppt/runtime/formula_renderer.pyscript9.6 KB
cli/image2ppt/runtime/image_gen.pyscript37.1 KB
cli/image2ppt/runtime/main.pyscript39.7 KB
cli/image2ppt/runtime/make_page_contact_sheet.pyscript1.1 KB
cli/image2ppt/runtime/paddle_text_hints.pyscript10.7 KB
cli/image2ppt/runtime/page_job_status.pyscript2.1 KB
cli/image2ppt/runtime/page_text_metrics.pyscript11.6 KB
cli/image2ppt/runtime/prepare_deck_run.pyscript7.3 KB
cli/image2ppt/runtime/process_asset_sheet.pyscript6.0 KB
cli/image2ppt/runtime/record_imagegen_result.pyscript5.9 KB
cli/image2ppt/runtime/record_page_dispatch.pyscript2.8 KB
cli/image2ppt/runtime/record_page_result.pyscript4.6 KB
cli/image2ppt/runtime/remove_chroma_key.pyscript13.5 KB
cli/image2ppt/runtime/reset_page_job.pyscript2.6 KB
cli/image2ppt/runtime/runtime_env.pyscript18.8 KB
cli/image2ppt/runtime/split_alpha_components.pyscript9.2 KB
cli/image2ppt/runtime/text_hints.pyscript14.0 KB
cli/image2ppt/runtime/validate_pptx.pyscript38.7 KB
cli/pyproject.tomlmanifest570 B
config.example.yamlconfig1.0 KB
manifest.yamlconfig480 B
prompts/page-worker-base.mdmarkdown7.4 KB
prompts/page-worker.mdmarkdown5.1 KB
references/assets-provenance-contract.mdmarkdown2.9 KB
references/cli-helper.mdmarkdown17.8 KB
references/manifest-arrow-extension.mdmarkdown2.5 KB
references/manifest-schema.mdmarkdown19.9 KB
references/object-routing.mdmarkdown3.4 KB
references/ocr-text-hints-contract.mdmarkdown3.0 KB
references/page-decision-tree.mdmarkdown21.7 KB
references/qa-contract.mdmarkdown5.4 KB
references/region-decomposition.mdmarkdown6.5 KB
references/runtime-dependencies.mdmarkdown2.5 KB
references/workflow.mdmarkdown6.7 KB
requirements.txtmanifest176 B
schemas/page-manifest-v2.schema.jsonconfig2.9 KB
scripts/build_page_worker_prompt.pyscript4.1 KB
scripts/inspect_arrow_atomicity.pyscript7.3 KB
scripts/inspect_region_decomposition.pyscript18.1 KB
scripts/postprocess_manifest_arrows.pyscript18.4 KB
scripts/render_image2ppt_qa.pyscript11.1 KB
scripts/run_final_image2ppt_qa.pyscript9.0 KB
scripts/run_image2ppt_qa.pyscript9.5 KB
scripts/runtime_paths.pyscript4.0 KB
scripts/visual_review_evidence.pyscript5.4 KB
tests/support.pyscript6.4 KB
tests/test_console_portability.pyscript1021 B
tests/test_deck_slide_size.pyscript1.1 KB
tests/test_dispatch_concurrency.pyscript2.9 KB
tests/test_formula_renderer.pyscript4.3 KB
tests/test_independence.pyscript2.2 KB
tests/test_input_normalization_alpha.pyscript2.3 KB
tests/test_input_normalization_opc_targets.pyscript1.9 KB
tests/test_isolated_lifecycle.pyscript9.5 KB
tests/test_manifest_arrows.pyscript8.6 KB
tests/test_migration_parity.pyscript3.2 KB
tests/test_multi_agent_backend.pyscript80.8 KB
tests/test_ocr_http.pyscript16.7 KB
tests/test_paddle_result_url_safety.pyscript3.2 KB
tests/test_page_hints.pyscript10.4 KB
tests/test_path_confinement.pyscript7.5 KB
tests/test_pdf_backend.pyscript4.3 KB
tests/test_project_metadata.pyscript4.7 KB
tests/test_quality_contracts.pyscript9.1 KB
tests/test_region_decomposition.pyscript6.2 KB
tests/test_render_guard.pyscript2.4 KB
tests/test_runtime_config.pyscript2.6 KB
tests/test_runtime_paths.pyscript2.2 KB
tests/test_script_inventory.pyscript2.1 KB
tests/test_slide_layout.pyscript9.3 KB
tests/test_state_e2e.pyscript7.8 KB
tests/test_structure_reconstruction.pyscript12.5 KB
tests/test_thin_profile.pyscript4.0 KB
tests/test_visual_review_evidence.pyscript2.3 KB
tests/test_visual_review_runtime.pyscript2.9 KB

tests/test_structure_reconstruction.py

View on GitHub
from __future__ import annotations

import json
import re
import subprocess
import sys
import tempfile
import unittest
import zipfile
from pathlib import Path
from xml.etree import ElementTree as ET

from PIL import Image

from support import SCRIPTS, build_deck, build_page, write_json


NS = {
    "a": "http://schemas.openxmlformats.org/drawingml/2006/main",
    "p": "http://schemas.openxmlformats.org/presentationml/2006/main",
}


def run_ok(command: list[str]) -> None:
    result = subprocess.run(command, text=True, capture_output=True, check=False)
    if result.returncode != 0:
        raise AssertionError(result.stdout + result.stderr)


def graph_manifest(page: Path) -> Path:
    page.mkdir(parents=True)
    Image.new("RGB", (800, 450), "white").save(page / "source.png")
    nodes = []
    node_shapes = []
    node_anchors = []
    for index in range(42):
        row, column = divmod(index, 7)
        x = 70 + column * 85
        y = 65 + row * 44
        item_id = f"kg_node_{index + 1:02d}"
        node_shapes.append(
            {
                "id": item_id,
                "type": "ellipse",
                "box_px": [x, y, 22, 22],
                "fill": "#E8F2FF",
                "stroke": "#2563EB",
                "stroke_width": 1.2,
                "z_index": 100 + index,
            }
        )
        nodes.append(
            {
                "id": f"node-{index + 1:02d}",
                "manifest_id": item_id,
                "geometry": "circle",
                "source_center_px": [x + 11, y + 11],
                "source_size_px": [22, 22],
                "position_tolerance_px": 1,
                "size_tolerance_px": 1,
            }
        )
        node_anchors.append(
            {
                "id": f"anchor-{item_id}",
                "kind": "circle-node",
                "manifest_id": item_id,
                "source_bbox_px": [x, y, 22, 22],
            }
        )

    edges = []
    edge_shapes = []
    edge_anchors = []
    for index in range(41):
        start = nodes[index]["source_center_px"]
        end = nodes[index + 1]["source_center_px"]
        item_id = f"kg_edge_{index + 1:02d}"
        dashed = index % 5 == 4
        shape = {
            "id": item_id,
            "type": "line",
            "points_px": [*start, *end],
            "stroke": "#64748B",
            "stroke_width": 1.0,
            "connector": "straight",
            "start_arrow": "none",
            "end_arrow": "triangle",
            "z_index": 20 + index,
        }
        if dashed:
            shape["dash"] = "dash"
        edge_shapes.append(shape)
        edges.append(
            {
                "id": f"edge-{index + 1:02d}",
                "manifest_id": item_id,
                "source_points_px": [*start, *end],
                "line_style": "dashed" if dashed else "solid",
                "direction": "end",
                "position_tolerance_px": 1,
            }
        )
        edge_anchors.append(
            {
                "id": f"anchor-{item_id}",
                "kind": "dashed-relationship" if dashed else "directed-connector",
                "manifest_id": item_id,
                "source_points_px": [*start, *end],
            }
        )

    thin_arrow = {
        "id": "standalone_thin_arrow",
        "type": "line",
        "points_px": [100, 390, 300, 390],
        "stroke": "#0F766E",
        "stroke_width": 2.5,
        "connector": "straight",
        "start_arrow": "none",
        "end_arrow": "triangle",
        "z_index": 250,
    }
    filled_arrow = {
        "id": "standalone_filled_arrow",
        "type": "shape",
        "preset": "rightArrow",
        "box_px": [380, 365, 230, 55],
        "fill": "#2563EB",
        "stroke": "none",
        "text": "下一阶段",
        "font_size": 14,
        "text_color": "#FFFFFF",
        "align": "center",
        "valign": "middle",
        "z_index": 260,
    }
    graph_shape_ids = [item["id"] for item in [*node_shapes, *edge_shapes]]
    manifest = {
        "schema_version": 1,
        "slide": {"width": 13.333, "height": 7.5, "background": "#FFFFFF"},
        "content_box": {"left": 0, "top": 0, "width": 13.333, "height": 7.5},
        "source": {"path": "source.png", "width_px": 800, "height_px": 450},
        "page_strategy": "native-structure",
        "required_text": ["Knowledge Graph", "下一阶段"],
        "text_inventory": ["Knowledge Graph", "下一阶段"],
        "visual_inventory": [
            {"id": "graph", "description": "native structural measured knowledge graph", "decision": "native structure"},
            {"id": "arrows", "description": "native structural ordinary arrows", "decision": "native structure"},
        ],
        "background_strategy": {
            "mode": "native-or-script",
            "source_consistency_contract": "solid white source background",
            "removed_foreground": [],
            "comparison_note": "solid white background matched",
        },
        "quality_checks": {
            "font_size_calibrated": True,
            "visual_inventory_matched": True,
            "background_strategy_checked": True,
            "shape_corner_geometry_checked": True,
        },
        "text_boxes": [
            {
                "id": "title",
                "text": "Knowledge Graph",
                "box_px": [30, 10, 400, 35],
                "font_size": 20,
                "font_size_source": "measured",
                "color": "#111827",
                "z_index": 300,
            }
        ],
        "shapes": [*edge_shapes, *node_shapes, thin_arrow, filled_arrow],
        "images": [],
        "asset_provenance": [],
        "image2ppt_region_decomposition": {
            "schema_version": "image2ppt-region-decomposition-v1",
            "page_complexity": "structured",
            "source_size_px": [800, 450],
            "regions": [
                {
                    "id": "title-region",
                    "label": "Title",
                    "source_bbox_px": [0, 0, 800, 50],
                    "risk_level": "low",
                    "strategy": "native-text-layout",
                    "reason": "Measured native title.",
                    "manifest_ids": {"shapes": [], "text_boxes": ["title"], "images": []},
                    "protected_visual_anchors": [],
                },
                {
                    "id": "knowledge-graph-region",
                    "label": "42-node knowledge graph",
                    "source_bbox_px": [40, 50, 650, 300],
                    "risk_level": "high",
                    "strategy": "native-object-decomposition",
                    "reason": "All 42 circles and 41 directed relationships are individually measured.",
                    "manifest_ids": {"shapes": graph_shape_ids, "text_boxes": [], "images": []},
                    "protected_visual_anchors": [*node_anchors, *edge_anchors],
                    "compound_diagram": {
                        "kind": "knowledge-graph",
                        "object_inventory_complete": True,
                        "measurement_reviewed": True,
                        "native_object_policy": "measured-simple-objects-native",
                        "nodes": nodes,
                        "edges": edges,
                    },
                },
                {
                    "id": "arrow-region",
                    "label": "Arrow examples",
                    "source_bbox_px": [40, 350, 700, 90],
                    "risk_level": "medium",
                    "strategy": "native-object-decomposition",
                    "reason": "Ordinary arrows are single native objects.",
                    "manifest_ids": {
                        "shapes": [thin_arrow["id"], filled_arrow["id"]],
                        "text_boxes": [],
                        "images": [],
                    },
                    "protected_visual_anchors": [
                        {
                            "id": "anchor-standalone-thin",
                            "kind": "directed-connector",
                            "manifest_id": thin_arrow["id"],
                            "source_points_px": thin_arrow["points_px"],
                        },
                        {
                            "id": "anchor-standalone-filled",
                            "kind": "route-line",
                            "manifest_id": filled_arrow["id"],
                            "source_bbox_px": filled_arrow["box_px"],
                        },
                    ],
                },
            ],
        },
    }
    path = page / "manifest.json"
    write_json(path, manifest)
    write_json(page / "imagegen-jobs.json", {"schema_version": 1, "jobs": []})
    return path


def slide_xml(pptx: Path) -> ET.Element:
    with zipfile.ZipFile(pptx) as archive:
        return ET.fromstring(archive.read("ppt/slides/slide1.xml"))


def structure_counts(pptx: Path) -> dict[str, int]:
    root = slide_xml(pptx)
    ellipses = 0
    filled = 0
    for shape in root.findall(".//p:sp", NS):
        geom = shape.find(".//a:prstGeom", NS)
        if geom is not None and geom.get("prst") == "ellipse":
            ellipses += 1
        if geom is not None and geom.get("prst") == "rightArrow":
            filled += 1
    return {
        "circle_nodes": ellipses,
        "connectors": len(root.findall(".//p:cxnSp", NS)),
        "filled_arrows": filled,
        "pictures": len(root.findall(".//p:pic", NS)),
    }


class StructureReconstructionTests(unittest.TestCase):
    def test_42_native_nodes_relations_and_atomic_arrows_survive_final_build(self) -> None:
        with tempfile.TemporaryDirectory() as tmp:
            run = Path(tmp)
            page = run / "pages" / "page_001"
            manifest = graph_manifest(page)
            page_pptx = build_page(page)
            region_report = page / "region-report.json"
            run_ok(
                [sys.executable, str(SCRIPTS / "inspect_region_decomposition.py"), "--manifest", str(manifest), "--out", str(region_report)]
            )
            page_arrow_report = page / "arrow-postprocess.json"
            run_ok(
                [sys.executable, str(SCRIPTS / "postprocess_manifest_arrows.py"), str(page_pptx), "--manifest", str(manifest), "--report", str(page_arrow_report)]
            )
            page_inspection = page / "arrow-inspection.json"
            run_ok(
                [sys.executable, str(SCRIPTS / "inspect_arrow_atomicity.py"), str(page_pptx), "--manifest", str(manifest), "--out", str(page_inspection)]
            )
            counts = structure_counts(page_pptx)
            self.assertEqual(counts["circle_nodes"], 42)
            self.assertEqual(counts["connectors"], 42)  # 41 relations + one standalone thin arrow
            self.assertEqual(counts["filled_arrows"], 1)
            self.assertEqual(counts["pictures"], 0)
            region = json.loads(region_report.read_text(encoding="utf-8"))
            self.assertTrue(region["passed"], region)
            self.assertEqual(region["pages"][0]["region_count"], 3)
            arrows = json.loads(page_inspection.read_text(encoding="utf-8"))
            self.assertTrue(arrows["passed"], arrows)
            self.assertEqual(arrows["summary"]["connectors"], 42)
            self.assertEqual(arrows["summary"]["filled_arrows"], 1)

            final = run / "final" / "deck_edited.pptx"
            write_json(
                run / "deck_manifest.json",
                {
                    "schema_version": 1,
                    "job_dir": str(run),
                    "page_count": 1,
                    "slide": {"width": 13.333, "height": 7.5},
                    "pages": [{"page_id": "page_001", "manifest": "pages/page_001/manifest.json", "source_image": "pages/page_001/source.png"}],
                    "output": "final/deck_edited.pptx",
                },
            )
            final.parent.mkdir(parents=True, exist_ok=True)
            build_deck(run / "deck_manifest.json", final)
            final_arrow_report = final.parent / "arrow-postprocess.json"
            run_ok(
                [sys.executable, str(SCRIPTS / "postprocess_manifest_arrows.py"), str(final), "--run", str(run), "--report", str(final_arrow_report)]
            )
            final_inspection = final.parent / "arrow-inspection.json"
            run_ok(
                [sys.executable, str(SCRIPTS / "inspect_arrow_atomicity.py"), str(final), "--run", str(run), "--out", str(final_inspection)]
            )
            self.assertEqual(structure_counts(final), counts)
            self.assertTrue(json.loads(final_inspection.read_text(encoding="utf-8"))["passed"])


if __name__ == "__main__":
    unittest.main()
canvas-designanthropics/skillsCreate beautiful visual art in .png and .pdf documents using design philosophy. You should use this skill when the user asks to create a poster, piece of art, design, or other static piece. Create original visual designs, never copying existing artists' work to avoid copyright violations.Stars: 198kUpdated Claude CodeCodexVerifiedInstall
docxanthropics/skillsUse this skill whenever the user wants to create, read, edit, or manipulate Word documents (.docx files) or Word templates (.dotx files). Triggers include: any mention of 'Word doc', 'word document', '.docx', '.dotx', or requests to produce professional documents with formatting like tables of contents, headings, page numbers, or letterheads. Also use when extracting or reorganizing content from .docx or .dotx files, inserting or replacing images in documents, performing find-and-replace in Word files, working with tracked changes or comments, or converting content into a polished Word document. If the user asks for a 'report', 'memo', 'letter', 'template', or similar deliverable as a Word or .docx file, use this skill. Do NOT use for PDFs, spreadsheets, Google Docs, or general coding tasks unrelated to document generation.Stars: 198kUpdated Claude CodeCodexVerifiedInstall
pdfanthropics/skillsUse this skill whenever the user wants to do anything with PDF files. This includes reading or extracting text/tables from PDFs, combining or merging multiple PDFs into one, splitting PDFs apart, rotating pages, adding watermarks, creating new PDFs, filling PDF forms, encrypting/decrypting PDFs, extracting images, and OCR on scanned PDFs to make them searchable. If the user mentions a .pdf file or asks to produce one, use this skill.Stars: 198kUpdated Claude CodeCodexVerifiedInstall
pptxanthropics/skillsUse this skill any time a .pptx or .potx file is involved in any way — as input, output, or both. This includes: creating slide decks, pitch decks, or presentations; reading, parsing, or extracting text from any .pptx or .potx file (even if the extracted content will be used elsewhere, like in an email or summary); editing, modifying, or updating existing presentations; combining or splitting slide files; working with templates (.potx), layouts, speaker notes, or comments. Trigger whenever the user mentions "deck," "slides," "presentation," or references a .pptx or .potx filename, regardless of what they plan to do with the content afterward. If a .pptx or .potx file needs to be opened, created, or touched, use this skill.Stars: 198kUpdated Claude CodeCodexVerifiedInstall