@dickpy/dsh-oil-slide 0.0.0-stage → 0.2.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +89 -2
- package/bundled-assets/brand/empty-deck-cobalt.webp +0 -0
- package/bundled-assets/brand/oil-slide-mark-512.png +0 -0
- package/bundled-assets/skill/LICENSE +21 -0
- package/bundled-assets/skill/README.md +61 -0
- package/bundled-assets/skill/SKILL.md +185 -0
- package/bundled-assets/skill/references/art-directions.md +99 -0
- package/bundled-assets/skill/references/brand-and-canvas.md +72 -0
- package/bundled-assets/skill/references/design-baseline.txt +1 -0
- package/bundled-assets/skill/references/prompt-compiler.md +99 -0
- package/bundled-assets/skill/references/restore-and-pptx.md +178 -0
- package/bundled-assets/skill/references/staged-pptx.md +71 -0
- package/bundled-assets/skill/scripts/_runtime_utils.py +351 -0
- package/bundled-assets/skill/scripts/asset_sheet.py +528 -0
- package/bundled-assets/skill/scripts/brand_ref.py +776 -0
- package/bundled-assets/skill/scripts/crop_asset.py +1709 -0
- package/bundled-assets/skill/scripts/deck_shell.py +2322 -0
- package/bundled-assets/skill/scripts/export_images.py +280 -0
- package/bundled-assets/skill/scripts/extract_pptx.py +360 -0
- package/bundled-assets/skill/scripts/extract_slide_dom.js +1640 -0
- package/bundled-assets/skill/scripts/html_to_pptx.py +4042 -0
- package/bundled-assets/skill/scripts/measure_slide_layout.py +952 -0
- package/bundled-assets/skill/scripts/oiloil-connect.mjs +1493 -0
- package/bundled-assets/skill/scripts/oiloil-image.mjs +492 -0
- package/bundled-assets/skill/scripts/prepare_plate.py +412 -0
- package/bundled-assets/skill/scripts/render_gradient.py +258 -0
- package/bundled-assets/skill/scripts/slide_brand.py +111 -0
- package/bundled-assets/skill/scripts/slide_incremental.py +122 -0
- package/bundled-assets/skill/scripts/slide_workflow.py +711 -0
- package/bundled-assets/skill/scripts/verify_deck.py +3483 -0
- package/bundled-assets/skill/vendor/README.md +4 -0
- package/bundled-assets/skill/vendor/codex-ppt/LICENSE +21 -0
- package/bundled-assets/skill/vendor/codex-ppt/assemble_ppt.py +435 -0
- package/bundled-assets/skill/vendor/codex-ppt/codex_ppt_runtime.py +284 -0
- package/bundled-assets/skill/vendor/codex-ppt/image_gen.py +972 -0
- package/bundled-assets/skill/vendor/codex-ppt/image_providers/__init__.py +6 -0
- package/bundled-assets/skill/vendor/codex-ppt/image_providers/atlascloud.py +222 -0
- package/bundled-assets/skill/vendor/codex-ppt/image_providers/base.py +32 -0
- package/bundled-assets/skill/vendor/codex-ppt/image_providers/factory.py +21 -0
- package/bundled-assets/skill/vendor/codex-ppt/image_providers/openai_compatible.py +238 -0
- package/bundled-assets/skill/vendor/codex-ppt/requirements.txt +5 -0
- package/bundled-assets/skill/vendor/codex-ppt/styles//345/205/232/346/224/277/347/272/242/351/243/216/346/240/274.md +98 -0
- package/bundled-assets/skill/vendor/codex-ppt/styles//345/210/233/346/204/217/346/235/202/345/277/227/351/243/216.md +72 -0
- package/bundled-assets/skill/vendor/codex-ppt/styles//345/244/215/345/217/244/346/211/201/345/271/263/346/217/222/347/224/273/351/243/216.md +72 -0
- package/bundled-assets/skill/vendor/codex-ppt/styles//346/211/213/347/273/230/346/212/200/346/234/257/350/247/243/351/207/212/351/243/216.md +86 -0
- package/bundled-assets/skill/vendor/codex-ppt/styles//346/211/213/347/273/230/347/231/275/346/235/277/351/243/216.md +72 -0
- package/bundled-assets/skill/vendor/codex-ppt/styles//346/225/231/345/255/246/350/257/276/344/273/266/351/243/216.md +107 -0
- package/bundled-assets/skill/vendor/codex-ppt/styles//346/225/260/346/215/256/344/273/252/350/241/250/347/233/230/351/243/216.md +73 -0
- package/bundled-assets/skill/vendor/codex-ppt/styles//346/270/205/347/210/275/344/270/223/344/270/232/351/243/216.md +87 -0
- package/bundled-assets/skill/vendor/codex-ppt/styles//346/270/251/346/232/226/346/211/213/345/267/245/351/243/216.md +72 -0
- package/bundled-assets/skill/vendor/codex-ppt/styles//347/224/265/345/255/220/345/242/250/346/260/264/346/235/202/345/277/227/351/243/216.md +86 -0
- package/bundled-assets/skill/vendor/codex-ppt/styles//347/247/221/347/240/224/347/255/224/350/276/251/351/243/216.md +138 -0
- package/bundled-assets/skill/vendor/codex-ppt/styles//351/272/246/350/202/257/351/224/241/351/243/216/346/240/274.md +119 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/LICENSE +21 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/SKILL.md +171 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/agents/openai.yaml +4 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/__init__.py +1 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/cli.py +25 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/__init__.py +1 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/_input_normalization.py +355 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/_page_artifacts.py +132 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/build_pptx_from_manifest.py +1029 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/configure_image_backend.py +52 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/deck_run_state.py +214 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/deck_text_hints.py +179 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/finalize_deck_run.py +96 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/formula_renderer.py +254 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/image_gen.py +206 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/main.py +795 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/make_page_contact_sheet.py +28 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/native_tables.py +140 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/paddle_text_hints.py +212 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/page_job_status.py +54 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/page_text_metrics.py +334 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/path_geometry.py +174 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/prepare_deck_run.py +209 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/process_asset_sheet.py +104 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/record_imagegen_result.py +118 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/record_page_dispatch.py +83 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/record_page_result.py +130 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/remove_chroma_key.py +441 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/reset_page_job.py +74 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/runtime_env.py +283 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/split_alpha_components.py +323 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/text_hints.py +309 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/validate_pptx.py +873 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/pyproject.toml +29 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/prompts/page-worker.md +47 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/references/cli-helper.md +282 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/references/manifest-schema.md +423 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/references/page-decision-tree.md +301 -0
- package/bundled-assets/skill/vendor/image-to-editable-ppt/scripts/build-page-worker-prompt.py +134 -0
- package/cordis.patch.yml +3 -0
- package/lib/client.js +11282 -0
- package/lib/index.js +2638 -0
- package/package.json +140 -4
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
import argparse
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
|
|
5
|
+
from _page_artifacts import write_pair
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def main():
|
|
9
|
+
parser = argparse.ArgumentParser(description="Create an origin/preview contact sheet for a page.")
|
|
10
|
+
parser.add_argument("page_dir")
|
|
11
|
+
parser.add_argument("--source", default="source.png")
|
|
12
|
+
parser.add_argument("--preview", default="preview.png")
|
|
13
|
+
parser.add_argument("--out", default="split_assets_contact.png")
|
|
14
|
+
args = parser.parse_args()
|
|
15
|
+
|
|
16
|
+
page_dir = Path(args.page_dir).resolve()
|
|
17
|
+
source = page_dir / args.source
|
|
18
|
+
preview = page_dir / args.preview
|
|
19
|
+
out = page_dir / args.out
|
|
20
|
+
if not source.exists():
|
|
21
|
+
raise SystemExit(f"Missing source image: {source}")
|
|
22
|
+
if not preview.exists():
|
|
23
|
+
raise SystemExit(f"Missing preview image: {preview}")
|
|
24
|
+
write_pair(source, preview, out)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
if __name__ == "__main__":
|
|
28
|
+
main()
|
package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/native_tables.py
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
"""Rectangular editable table validation and DrawingML emission."""
|
|
2
|
+
import math
|
|
3
|
+
from copy import deepcopy
|
|
4
|
+
|
|
5
|
+
STYLE_DEFAULTS = {"font": "PingFang SC", "font_size": 18, "color": "#111111",
|
|
6
|
+
"align": "left", "valign": "top", "wrap": "none",
|
|
7
|
+
"fill": "#FFFFFF", "stroke": "#000000", "stroke_width": 1,
|
|
8
|
+
"margin_left": 0.05, "margin_right": 0.05,
|
|
9
|
+
"margin_top": 0.05, "margin_bottom": 0.05}
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
STYLE_FIELDS = set(STYLE_DEFAULTS) | {"bold", "italic", "fit_text"}
|
|
13
|
+
CELL_FIELDS = {"text", "row_span", "col_span", "style"}
|
|
14
|
+
CELL_GEOMETRY = {"left", "top", "width", "height"}
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def validate_style(style, label):
|
|
18
|
+
if not isinstance(style, dict):
|
|
19
|
+
raise ValueError(f"{label} must be an object")
|
|
20
|
+
unsupported = set(style) - STYLE_FIELDS
|
|
21
|
+
if unsupported:
|
|
22
|
+
raise ValueError(f"{label} contains unsupported fields: {', '.join(sorted(unsupported))}")
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def positive(value, label, allow_zero=False):
|
|
26
|
+
if isinstance(value, bool) or not isinstance(value, (int, float)) or not math.isfinite(value) or value < 0 or (value == 0 and not allow_zero):
|
|
27
|
+
raise ValueError(f"{label} must be a finite {'nonnegative' if allow_zero else 'positive'} number")
|
|
28
|
+
return float(value)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def normalize_table(table, manifest, normalize_position, fit_text, align, valign):
|
|
32
|
+
if not isinstance(table, dict):
|
|
33
|
+
raise ValueError("table must be an object")
|
|
34
|
+
table = deepcopy(table)
|
|
35
|
+
if "box" in table:
|
|
36
|
+
if not isinstance(table["box"], list) or len(table["box"]) != 4:
|
|
37
|
+
raise ValueError("table.box must be [x, y, width, height] in inches")
|
|
38
|
+
table.update(zip(("left", "top", "width", "height"), table["box"]))
|
|
39
|
+
table = normalize_position(manifest, table)
|
|
40
|
+
for name in ("left", "top", "width", "height"):
|
|
41
|
+
table[name] = positive(table.get(name), f"table.{name}", name in ("left", "top"))
|
|
42
|
+
cells = table.get("cells")
|
|
43
|
+
if not isinstance(cells, list) or not cells or not isinstance(cells[0], list) or not cells[0]:
|
|
44
|
+
raise ValueError("table.cells must be a nonempty rectangular 2D array")
|
|
45
|
+
rows, cols = len(cells), len(cells[0])
|
|
46
|
+
if any(not isinstance(row, list) or len(row) != cols for row in cells):
|
|
47
|
+
raise ValueError("table.cells must be rectangular")
|
|
48
|
+
for key, count, extent in (("column_widths", cols, table["width"]), ("row_heights", rows, table["height"])):
|
|
49
|
+
values = table.get(key, [1] * count)
|
|
50
|
+
if not isinstance(values, list) or len(values) != count:
|
|
51
|
+
raise ValueError(f"table.{key} must match the grid dimension")
|
|
52
|
+
values = [positive(value, f"table.{key}") for value in values]
|
|
53
|
+
table[key] = [value / sum(values) * extent for value in values]
|
|
54
|
+
style = table.get("style", {})
|
|
55
|
+
validate_style(style, "table.style")
|
|
56
|
+
owners = {}
|
|
57
|
+
output = []
|
|
58
|
+
for r, row in enumerate(cells):
|
|
59
|
+
output.append([])
|
|
60
|
+
for c, raw in enumerate(row):
|
|
61
|
+
if isinstance(raw, str):
|
|
62
|
+
raw = {"text": raw}
|
|
63
|
+
if not isinstance(raw, dict) or not isinstance(raw.get("text", ""), str):
|
|
64
|
+
raise ValueError("table cell must be a string or object with string text")
|
|
65
|
+
if (r, c) in owners:
|
|
66
|
+
if {k: v for k, v in raw.items() if k != "_owner"} not in ({}, {"text": ""}):
|
|
67
|
+
raise ValueError("covered table cells must be empty, without style or spans")
|
|
68
|
+
output[r].append({"_owner": owners[r, c]})
|
|
69
|
+
continue
|
|
70
|
+
# Normalized cells expose effective style and geometry for both renderers.
|
|
71
|
+
# Recalculate those fields rather than trusting supplied internal values.
|
|
72
|
+
allowed = CELL_FIELDS
|
|
73
|
+
if CELL_GEOMETRY <= raw.keys() and STYLE_DEFAULTS.keys() <= raw.keys() and "style" in raw:
|
|
74
|
+
allowed = allowed | STYLE_FIELDS | CELL_GEOMETRY
|
|
75
|
+
unsupported = set(raw) - allowed
|
|
76
|
+
if unsupported:
|
|
77
|
+
raise ValueError(f"table cell contains unsupported fields: {', '.join(sorted(unsupported))}")
|
|
78
|
+
rs, cs = raw.get("row_span", 1), raw.get("col_span", 1)
|
|
79
|
+
if any(isinstance(n, bool) or not isinstance(n, int) or n < 1 for n in (rs, cs)):
|
|
80
|
+
raise ValueError("table row_span/col_span must be positive integers")
|
|
81
|
+
if r + rs > rows or c + cs > cols:
|
|
82
|
+
raise ValueError("table span exceeds grid bounds")
|
|
83
|
+
for rr in range(r, r + rs):
|
|
84
|
+
for cc in range(c, c + cs):
|
|
85
|
+
if (rr, cc) in owners:
|
|
86
|
+
raise ValueError("table spans overlap")
|
|
87
|
+
owners[rr, cc] = (r, c)
|
|
88
|
+
validate_style(raw.get("style", {}), "cell.style")
|
|
89
|
+
cell = {**STYLE_DEFAULTS, **style, **raw.get("style", {}), "text": raw.get("text", ""), "row_span": rs, "col_span": cs}
|
|
90
|
+
align(cell["align"])
|
|
91
|
+
valign(cell["valign"])
|
|
92
|
+
if cell["wrap"] not in ("none", "square"):
|
|
93
|
+
raise ValueError("cell wrap must be none or square")
|
|
94
|
+
positive(cell["font_size"], "cell font_size")
|
|
95
|
+
positive(cell["stroke_width"], "cell stroke_width", True)
|
|
96
|
+
for side in ("left", "right", "top", "bottom"):
|
|
97
|
+
positive(cell[f"margin_{side}"], f"cell margin_{side}", True)
|
|
98
|
+
cell.update(left=table["left"] + sum(table["column_widths"][:c]),
|
|
99
|
+
top=table["top"] + sum(table["row_heights"][:r]),
|
|
100
|
+
width=sum(table["column_widths"][c:c + cs]), height=sum(table["row_heights"][r:r + rs]))
|
|
101
|
+
inner = cell_text_box(cell)
|
|
102
|
+
if inner["width"] <= 0 or inner["height"] <= 0:
|
|
103
|
+
raise ValueError("table cell margins leave no text area")
|
|
104
|
+
fitted = fit_text(inner, manifest)
|
|
105
|
+
cell["font_size"] = fitted.get("font_size", cell["font_size"])
|
|
106
|
+
cell["style"] = {**style, **raw.get("style", {}), "font_size": cell["font_size"]}
|
|
107
|
+
output[r].append(cell)
|
|
108
|
+
table["cells"] = output
|
|
109
|
+
return table
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def cell_text_box(cell):
|
|
113
|
+
return {**cell, "left": cell["left"] + cell["margin_left"], "top": cell["top"] + cell["margin_top"],
|
|
114
|
+
"width": cell["width"] - cell["margin_left"] - cell["margin_right"],
|
|
115
|
+
"height": cell["height"] - cell["margin_top"] - cell["margin_bottom"]}
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def table_xml(idx, table, emu, text_xml, fill_xml, line_xml, valign):
|
|
119
|
+
rows = []
|
|
120
|
+
for r, row in enumerate(table["cells"]):
|
|
121
|
+
parts = []
|
|
122
|
+
for c, cell in enumerate(row):
|
|
123
|
+
owner_r, owner_c = cell.get("_owner", (r, c))
|
|
124
|
+
origin = table["cells"][owner_r][owner_c]
|
|
125
|
+
attrs = []
|
|
126
|
+
if r == owner_r and origin["row_span"] > 1:
|
|
127
|
+
attrs.append(f'rowSpan="{origin["row_span"]}"')
|
|
128
|
+
if c == owner_c and origin["col_span"] > 1:
|
|
129
|
+
attrs.append(f'gridSpan="{origin["col_span"]}"')
|
|
130
|
+
if c != owner_c:
|
|
131
|
+
attrs.append('hMerge="1"')
|
|
132
|
+
if r != owner_r:
|
|
133
|
+
attrs.append('vMerge="1"')
|
|
134
|
+
body = text_xml(0, {**origin, "text": ""} if "_owner" in cell else cell).split("<p:txBody>", 1)[1].split("</p:txBody>", 1)[0]
|
|
135
|
+
lines = "".join(line_xml(origin["stroke"] if origin["stroke_width"] else "none", origin["stroke_width"]).replace("a:ln", f"a:ln{side}") for side in ("L", "R", "T", "B"))
|
|
136
|
+
margins = " ".join(f'mar{side}="{emu(origin[key])}"' for side, key in (("L", "margin_left"), ("R", "margin_right"), ("T", "margin_top"), ("B", "margin_bottom")))
|
|
137
|
+
parts.append(f'<a:tc {" ".join(attrs)}><a:txBody>{body}</a:txBody><a:tcPr {margins} anchor="{valign(origin["valign"])[0]}">{lines}{fill_xml(origin["fill"])}</a:tcPr></a:tc>')
|
|
138
|
+
rows.append(f'<a:tr h="{emu(table["row_heights"][r])}">{"".join(parts)}</a:tr>')
|
|
139
|
+
grid = "".join(f'<a:gridCol w="{emu(width)}"/>' for width in table["column_widths"])
|
|
140
|
+
return f'''<p:graphicFrame><p:nvGraphicFramePr><p:cNvPr id="{idx}" name="Table {idx}"/><p:cNvGraphicFramePr/><p:nvPr/></p:nvGraphicFramePr><p:xfrm><a:off x="{emu(table['left'])}" y="{emu(table['top'])}"/><a:ext cx="{emu(table['width'])}" cy="{emu(table['height'])}"/></p:xfrm><a:graphic><a:graphicData uri="http://schemas.openxmlformats.org/drawingml/2006/table"><a:tbl><a:tblPr/><a:tblGrid>{grid}</a:tblGrid>{''.join(rows)}</a:tbl></a:graphicData></a:graphic></p:graphicFrame>'''
|
package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/paddle_text_hints.py
ADDED
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Text hints backed by the PaddleOCR-VL cloud API (experimental).
|
|
3
|
+
|
|
4
|
+
Same contract as `text_hints.py`, with a different detector: the page is sent
|
|
5
|
+
to the PaddleOCR-VL service, only TEXT blocks (text / paragraph_title /
|
|
6
|
+
vision_footnote) are kept from the layout parsing result, and each block is
|
|
7
|
+
then re-measured locally with the ink metrics so the reported glyph height
|
|
8
|
+
and font size stay pixel-accurate. Output: `paddle_hints.json` plus a labeled
|
|
9
|
+
`paddle_hints.png` overlay on the source image.
|
|
10
|
+
|
|
11
|
+
Requires network access and a token in the PADDLE_OCR_TOKEN environment
|
|
12
|
+
variable (or --token). The built-in `editppt page hints` stays the offline
|
|
13
|
+
default; this script is the content-aware alternative.
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
from __future__ import annotations
|
|
17
|
+
|
|
18
|
+
import argparse
|
|
19
|
+
import json
|
|
20
|
+
import os
|
|
21
|
+
import sys
|
|
22
|
+
import time
|
|
23
|
+
from pathlib import Path
|
|
24
|
+
|
|
25
|
+
import requests
|
|
26
|
+
from PIL import Image
|
|
27
|
+
|
|
28
|
+
from page_text_metrics import contains_cjk, load_gray, measure_crop
|
|
29
|
+
from text_hints import attach_font_sizes, draw_overlay
|
|
30
|
+
|
|
31
|
+
JOB_URL = "https://paddleocr.aistudio-app.com/api/v2/ocr/jobs"
|
|
32
|
+
DEFAULT_MODEL = "PaddleOCR-VL-1.6"
|
|
33
|
+
TEXT_LABELS = {"text", "paragraph_title", "vision_footnote"}
|
|
34
|
+
USAGE_NOTE = (
|
|
35
|
+
"ADVISORY ONLY: these measurements are a reference, and some text lines may be "
|
|
36
|
+
"missed or merged. Lines sharing a size_group are the same text level and must "
|
|
37
|
+
"use exactly one font size. When assembling the final PPT: keep same-level text "
|
|
38
|
+
"at identical font sizes (apply the group's size to similar lines, including "
|
|
39
|
+
"ones you add yourself), and fill in every text the detector missed from your "
|
|
40
|
+
"own reading of the source image. box_px values are source pixels usable "
|
|
41
|
+
"directly in text_boxes; font_pt is already chosen per line (CJK vs Latin). Add "
|
|
42
|
+
"\"font_size_source\": \"measured\" to boxes you size from these hints. "
|
|
43
|
+
"Recognition text may contain occasional wrong characters — trust your own "
|
|
44
|
+
"reading of the source for the final text content."
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def submit_and_fetch(file_path: Path, token: str, model: str, timeout: int) -> list[dict]:
|
|
49
|
+
"""Submit an image or multi-page PDF; return one prunedResult per page."""
|
|
50
|
+
headers = {"Authorization": f"bearer {token}"}
|
|
51
|
+
optional = {"useDocOrientationClassify": False, "useDocUnwarping": False, "useChartRecognition": False}
|
|
52
|
+
with file_path.open("rb") as handle:
|
|
53
|
+
response = requests.post(
|
|
54
|
+
JOB_URL,
|
|
55
|
+
headers=headers,
|
|
56
|
+
data={"model": model, "optionalPayload": json.dumps(optional)},
|
|
57
|
+
files={"file": handle},
|
|
58
|
+
timeout=60,
|
|
59
|
+
)
|
|
60
|
+
if response.status_code != 200:
|
|
61
|
+
raise RuntimeError(f"PaddleOCR job submit failed ({response.status_code}): {response.text[:300]}")
|
|
62
|
+
job_id = response.json()["data"]["jobId"]
|
|
63
|
+
print(f"job submitted: {job_id}", file=sys.stderr)
|
|
64
|
+
|
|
65
|
+
started = time.time()
|
|
66
|
+
while True:
|
|
67
|
+
status = requests.get(f"{JOB_URL}/{job_id}", headers=headers, timeout=60).json()["data"]
|
|
68
|
+
state = status["state"]
|
|
69
|
+
if state == "done":
|
|
70
|
+
break
|
|
71
|
+
if state == "failed":
|
|
72
|
+
raise RuntimeError(f"PaddleOCR job failed: {status.get('errorMsg')}")
|
|
73
|
+
if time.time() - started > timeout:
|
|
74
|
+
raise RuntimeError(f"PaddleOCR job timed out after {timeout}s (state={state})")
|
|
75
|
+
time.sleep(5)
|
|
76
|
+
|
|
77
|
+
jsonl = requests.get(status["resultUrl"]["jsonUrl"], timeout=60)
|
|
78
|
+
jsonl.raise_for_status()
|
|
79
|
+
pages = []
|
|
80
|
+
for line in jsonl.text.strip().split("\n"):
|
|
81
|
+
if not line.strip():
|
|
82
|
+
continue
|
|
83
|
+
for result in json.loads(line)["result"]["layoutParsingResults"]:
|
|
84
|
+
pages.append(result["prunedResult"])
|
|
85
|
+
if not pages:
|
|
86
|
+
raise RuntimeError("PaddleOCR returned no pages")
|
|
87
|
+
return pages
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def text_blocks_to_lines(pruned: dict, gray, min_glyph: int,
|
|
91
|
+
scale_x: float = 1.0, scale_y: float = 1.0) -> list[dict]:
|
|
92
|
+
"""Keep text blocks only and re-measure each with local ink metrics.
|
|
93
|
+
|
|
94
|
+
scale_x/scale_y map OCR-page coordinates onto the gray image when the OCR
|
|
95
|
+
service rendered the page at a different resolution than source.png
|
|
96
|
+
(typical for PDF inputs).
|
|
97
|
+
"""
|
|
98
|
+
height, width = gray.shape
|
|
99
|
+
lines = []
|
|
100
|
+
for block in pruned.get("parsing_res_list", []):
|
|
101
|
+
if block.get("block_label") not in TEXT_LABELS:
|
|
102
|
+
continue
|
|
103
|
+
text = str(block.get("block_content", "")).strip()
|
|
104
|
+
bx1, by1, bx2, by2 = (float(v) for v in block["block_bbox"])
|
|
105
|
+
x1, y1 = int(round(bx1 * scale_x)), int(round(by1 * scale_y))
|
|
106
|
+
x2, y2 = int(round(bx2 * scale_x)), int(round(by2 * scale_y))
|
|
107
|
+
x1, y1 = max(0, x1), max(0, y1)
|
|
108
|
+
x2, y2 = min(width, x2), min(height, y2)
|
|
109
|
+
if x2 - x1 < 4 or y2 - y1 < 4:
|
|
110
|
+
continue
|
|
111
|
+
entry = {"text": text, "block_label": block.get("block_label")}
|
|
112
|
+
measured = measure_crop(gray[y1:y2, x1:x2], clean_border=False)
|
|
113
|
+
if measured["ok"] and measured["glyph_height_px"] >= min_glyph:
|
|
114
|
+
glyph = measured["glyph_height_px"]
|
|
115
|
+
bx, by, bw, bh = measured["bbox"]
|
|
116
|
+
pad_x = max(2, int(round(glyph * 0.35)))
|
|
117
|
+
pad_y = max(1, int(round(glyph * 0.30)))
|
|
118
|
+
left = max(0, x1 + bx - pad_x)
|
|
119
|
+
top = max(0, y1 + by - pad_y)
|
|
120
|
+
entry.update(
|
|
121
|
+
box_px=[left, top, min(width, x1 + bx + bw + pad_x) - left, min(height, y1 + by + bh + pad_y) - top],
|
|
122
|
+
glyph_height_px=round(glyph, 1),
|
|
123
|
+
line_count=measured["line_count"],
|
|
124
|
+
glyph_source="ink-measured",
|
|
125
|
+
)
|
|
126
|
+
else:
|
|
127
|
+
# Ink measurement failed (low contrast inside the block); fall
|
|
128
|
+
# back to the OCR block box and approximate the glyph from it.
|
|
129
|
+
line_count = max(1, text.count("\n") + 1)
|
|
130
|
+
entry.update(
|
|
131
|
+
box_px=[x1, y1, x2 - x1, y2 - y1],
|
|
132
|
+
glyph_height_px=round((y2 - y1) / (line_count * 1.3), 1),
|
|
133
|
+
line_count=line_count,
|
|
134
|
+
glyph_source="bbox-estimate",
|
|
135
|
+
)
|
|
136
|
+
lines.append(entry)
|
|
137
|
+
lines.sort(key=lambda line: (line["box_px"][1], line["box_px"][0]))
|
|
138
|
+
for index, line in enumerate(lines, 1):
|
|
139
|
+
line["id"] = f"P{index:02d}"
|
|
140
|
+
return lines
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
def build_page_hints(page_dir: Path, pruned: dict, source_name: str = "source.png",
|
|
144
|
+
min_glyph: int = 6) -> dict:
|
|
145
|
+
"""Turn one page's prunedResult into the hints payload for its page dir."""
|
|
146
|
+
source_path = page_dir / source_name
|
|
147
|
+
gray = load_gray(source_path)
|
|
148
|
+
height, width = gray.shape
|
|
149
|
+
scale_x = width / float(pruned["width"]) if pruned.get("width") else 1.0
|
|
150
|
+
scale_y = height / float(pruned["height"]) if pruned.get("height") else 1.0
|
|
151
|
+
lines = text_blocks_to_lines(pruned, gray, min_glyph, scale_x, scale_y)
|
|
152
|
+
|
|
153
|
+
manifest_like = {"source": {"width_px": width, "height_px": height}, "slide": {"width": 13.333, "height": 7.5}}
|
|
154
|
+
request_path = page_dir / "page_request.json"
|
|
155
|
+
if request_path.exists():
|
|
156
|
+
request = json.loads(request_path.read_text(encoding="utf-8"))
|
|
157
|
+
for key in ("slide", "content_box"):
|
|
158
|
+
if request.get(key):
|
|
159
|
+
manifest_like[key] = request[key]
|
|
160
|
+
attach_font_sizes(lines, manifest_like)
|
|
161
|
+
for line in lines:
|
|
162
|
+
line["font_pt"] = line["font_pt_if_cjk"] if contains_cjk(line["text"]) else line["font_pt_if_latin"]
|
|
163
|
+
return {
|
|
164
|
+
"schema_version": 1,
|
|
165
|
+
"backend": "paddleocr-vl",
|
|
166
|
+
"source": {"width_px": width, "height_px": height},
|
|
167
|
+
"lines": lines,
|
|
168
|
+
"note": USAGE_NOTE,
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
def main() -> int:
|
|
173
|
+
parser = argparse.ArgumentParser(
|
|
174
|
+
description="Text hints via the PaddleOCR-VL cloud API: text blocks with content, re-measured locally for font sizes.",
|
|
175
|
+
)
|
|
176
|
+
parser.add_argument("page_dir", help="Page directory containing source.png.")
|
|
177
|
+
parser.add_argument("--source", default="source.png", help="Source image relative to the page directory.")
|
|
178
|
+
parser.add_argument("--out", default="paddle_hints.json", help="Hints JSON relative to the page directory.")
|
|
179
|
+
parser.add_argument("--overlay", default="paddle_hints.png", help="Labeled overlay image. Pass an empty string to skip.")
|
|
180
|
+
parser.add_argument("--token", default=os.environ.get("PADDLE_OCR_TOKEN", ""), help="API token; defaults to $PADDLE_OCR_TOKEN.")
|
|
181
|
+
parser.add_argument("--model", default=DEFAULT_MODEL)
|
|
182
|
+
parser.add_argument("--timeout", type=int, default=300, help="Job polling timeout in seconds.")
|
|
183
|
+
parser.add_argument("--min-glyph", type=int, default=6)
|
|
184
|
+
args = parser.parse_args()
|
|
185
|
+
|
|
186
|
+
if not args.token:
|
|
187
|
+
raise SystemExit("Missing token: set PADDLE_OCR_TOKEN or pass --token.")
|
|
188
|
+
page_dir = Path(args.page_dir).expanduser().resolve()
|
|
189
|
+
source_path = page_dir / args.source
|
|
190
|
+
if not source_path.exists():
|
|
191
|
+
raise SystemExit(f"Missing source image: {source_path}")
|
|
192
|
+
|
|
193
|
+
started = time.time()
|
|
194
|
+
try:
|
|
195
|
+
pages = submit_and_fetch(source_path, args.token, args.model, args.timeout)
|
|
196
|
+
except RuntimeError as exc:
|
|
197
|
+
raise SystemExit(str(exc))
|
|
198
|
+
hints = build_page_hints(page_dir, pages[0], source_name=args.source, min_glyph=args.min_glyph)
|
|
199
|
+
hints["elapsed_seconds"] = round(time.time() - started, 1)
|
|
200
|
+
lines = hints["lines"]
|
|
201
|
+
out_path = page_dir / args.out
|
|
202
|
+
out_path.write_text(json.dumps(hints, ensure_ascii=False, indent=2) + "\n", encoding="utf-8")
|
|
203
|
+
if args.overlay:
|
|
204
|
+
draw_overlay(Image.open(source_path), lines, page_dir / args.overlay)
|
|
205
|
+
hints["overlay"] = args.overlay
|
|
206
|
+
print(json.dumps({"lines": len(lines), "elapsed_seconds": hints["elapsed_seconds"],
|
|
207
|
+
"out": str(out_path)}, ensure_ascii=False))
|
|
208
|
+
return 0
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
if __name__ == "__main__":
|
|
212
|
+
raise SystemExit(main())
|
package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/page_job_status.py
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
import argparse
|
|
3
|
+
import json
|
|
4
|
+
from collections import Counter, defaultdict
|
|
5
|
+
|
|
6
|
+
from deck_run_state import (
|
|
7
|
+
active_pages,
|
|
8
|
+
dispatch_slots_available,
|
|
9
|
+
dispatchable_pages,
|
|
10
|
+
load_jobs,
|
|
11
|
+
load_run_state,
|
|
12
|
+
max_concurrent_pages,
|
|
13
|
+
run_dir_from_target,
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def main():
|
|
18
|
+
parser = argparse.ArgumentParser(description="Print page job status without modifying run state.")
|
|
19
|
+
parser.add_argument("run", help="Run directory or deck_manifest.json")
|
|
20
|
+
parser.add_argument("--json", action="store_true")
|
|
21
|
+
args = parser.parse_args()
|
|
22
|
+
|
|
23
|
+
run_dir = run_dir_from_target(args.run)
|
|
24
|
+
jobs = load_jobs(run_dir)
|
|
25
|
+
state = load_run_state(run_dir)
|
|
26
|
+
by_status = defaultdict(list)
|
|
27
|
+
for page in jobs.get("pages", []):
|
|
28
|
+
by_status[page.get("status", "unknown")].append(page.get("page_id"))
|
|
29
|
+
summary = {
|
|
30
|
+
"run_dir": str(run_dir),
|
|
31
|
+
"run_status": state.get("status"),
|
|
32
|
+
"page_count": len(jobs.get("pages", [])),
|
|
33
|
+
"max_concurrent_pages": max_concurrent_pages(jobs),
|
|
34
|
+
"active_dispatches": [page.get("page_id") for page in active_pages(jobs)],
|
|
35
|
+
"dispatch_slots_available": dispatch_slots_available(jobs),
|
|
36
|
+
"dispatchable_pages": [page.get("page_id") for page in dispatchable_pages(jobs)],
|
|
37
|
+
"counts": dict(Counter(page.get("status", "unknown") for page in jobs.get("pages", []))),
|
|
38
|
+
"pages": dict(sorted(by_status.items())),
|
|
39
|
+
}
|
|
40
|
+
if args.json:
|
|
41
|
+
print(json.dumps(summary, ensure_ascii=False, indent=2))
|
|
42
|
+
return
|
|
43
|
+
print(f"run_dir={summary['run_dir']}")
|
|
44
|
+
print(f"run_status={summary['run_status']}")
|
|
45
|
+
print(f"max_concurrent_pages={summary['max_concurrent_pages']}")
|
|
46
|
+
print(f"active_dispatches={', '.join(summary['active_dispatches']) if summary['active_dispatches'] else '-'}")
|
|
47
|
+
print(f"dispatch_slots_available={summary['dispatch_slots_available']}")
|
|
48
|
+
print(f"dispatchable_pages={', '.join(summary['dispatchable_pages']) if summary['dispatchable_pages'] else '-'}")
|
|
49
|
+
for status, pages in summary["pages"].items():
|
|
50
|
+
print(f"{status}: {', '.join(pages) if pages else '-'}")
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
if __name__ == "__main__":
|
|
54
|
+
main()
|