@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,52 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
import argparse
|
|
3
|
+
import json
|
|
4
|
+
|
|
5
|
+
from deck_run_state import load_deck, load_jobs, read_json, run_dir_from_target, save_deck, write_json
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def backend_contract(args):
|
|
9
|
+
return {
|
|
10
|
+
"backend_id": "openai-compatible-api",
|
|
11
|
+
"tool_name": "editppt image",
|
|
12
|
+
"tool_call": "editppt image generate/edit",
|
|
13
|
+
"model": args.model,
|
|
14
|
+
"requires_openai_api_key": False,
|
|
15
|
+
"mode_policy": "generate-or-edit-per-asset",
|
|
16
|
+
"chroma_key_helper": "editppt image process-sheet",
|
|
17
|
+
"input_context_policy": "pass every visual reference via editppt image edit --image",
|
|
18
|
+
"save_path_policy": "write outputs to the page directory before adding them to the manifest",
|
|
19
|
+
"handoff_rule": "use only the configured image channel and record openai-compatible-api",
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def main():
|
|
24
|
+
parser = argparse.ArgumentParser(description="Record the run-level image backend contract.")
|
|
25
|
+
parser.add_argument("run")
|
|
26
|
+
parser.add_argument(
|
|
27
|
+
"--backend-id",
|
|
28
|
+
default="openai-compatible-api",
|
|
29
|
+
choices=["openai-compatible-api", "editppt-image-cli"],
|
|
30
|
+
)
|
|
31
|
+
parser.add_argument("--model", default=None)
|
|
32
|
+
args = parser.parse_args()
|
|
33
|
+
|
|
34
|
+
run_dir = run_dir_from_target(args.run)
|
|
35
|
+
deck = load_deck(run_dir)
|
|
36
|
+
contract = backend_contract(args)
|
|
37
|
+
deck["image_backend"] = contract
|
|
38
|
+
save_deck(run_dir, deck)
|
|
39
|
+
|
|
40
|
+
jobs = load_jobs(run_dir)
|
|
41
|
+
for page in jobs.get("pages", []):
|
|
42
|
+
if page["status"] != "pending":
|
|
43
|
+
continue
|
|
44
|
+
request_path = run_dir / page["page_request"]
|
|
45
|
+
request = read_json(request_path)
|
|
46
|
+
request["image_backend"] = contract
|
|
47
|
+
write_json(request_path, request)
|
|
48
|
+
print(json.dumps({"image_backend": contract}, ensure_ascii=False, indent=2))
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
if __name__ == "__main__":
|
|
52
|
+
main()
|
package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/deck_run_state.py
ADDED
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import hashlib
|
|
2
|
+
import json
|
|
3
|
+
from datetime import datetime, timezone
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
ACTIVE_PAGE_STATUSES = {"dispatched"}
|
|
8
|
+
DISPATCHABLE_PAGE_STATUSES = {"pending"}
|
|
9
|
+
DEFAULT_MAX_CONCURRENT_PAGES = 6
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def now_iso():
|
|
13
|
+
return datetime.now(timezone.utc).isoformat(timespec="seconds").replace("+00:00", "Z")
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def read_json(path, default=None):
|
|
17
|
+
path = Path(path)
|
|
18
|
+
if not path.exists():
|
|
19
|
+
if default is not None:
|
|
20
|
+
return default
|
|
21
|
+
raise FileNotFoundError(path)
|
|
22
|
+
return json.loads(path.read_text(encoding="utf-8"))
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def write_json(path, data):
|
|
26
|
+
path = Path(path)
|
|
27
|
+
path.parent.mkdir(parents=True, exist_ok=True)
|
|
28
|
+
path.write_text(json.dumps(data, ensure_ascii=False, indent=2) + "\n", encoding="utf-8")
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def sha256_file(path):
|
|
32
|
+
digest = hashlib.sha256()
|
|
33
|
+
with Path(path).open("rb") as handle:
|
|
34
|
+
for chunk in iter(lambda: handle.read(1024 * 1024), b""):
|
|
35
|
+
digest.update(chunk)
|
|
36
|
+
return digest.hexdigest()
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def sha256_text(value):
|
|
40
|
+
return hashlib.sha256(str(value).encode("utf-8")).hexdigest()
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def run_dir_from_target(target):
|
|
44
|
+
path = Path(target).expanduser().resolve()
|
|
45
|
+
if path.is_dir():
|
|
46
|
+
return path
|
|
47
|
+
if path.name == "deck_manifest.json":
|
|
48
|
+
return path.parent
|
|
49
|
+
raise ValueError(f"Expected run directory or deck_manifest.json: {target}")
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def deck_manifest_path(run_dir):
|
|
53
|
+
return Path(run_dir) / "deck_manifest.json"
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def page_jobs_path(run_dir):
|
|
57
|
+
return Path(run_dir) / "page_jobs.json"
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def run_state_path(run_dir):
|
|
61
|
+
return Path(run_dir) / "run_state.json"
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def load_deck(run_dir):
|
|
65
|
+
return read_json(deck_manifest_path(run_dir))
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def save_deck(run_dir, deck):
|
|
69
|
+
write_json(deck_manifest_path(run_dir), deck)
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def load_jobs(run_dir):
|
|
73
|
+
return read_json(page_jobs_path(run_dir))
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def save_jobs(run_dir, jobs):
|
|
77
|
+
write_json(page_jobs_path(run_dir), jobs)
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def load_run_state(run_dir):
|
|
81
|
+
return read_json(run_state_path(run_dir), default={"status": "created", "history": []})
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def save_run_state(run_dir, state):
|
|
85
|
+
write_json(run_state_path(run_dir), state)
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def set_run_status(run_dir, status, note=None):
|
|
89
|
+
state = load_run_state(run_dir)
|
|
90
|
+
if state.get("status") != status:
|
|
91
|
+
state.setdefault("history", []).append(
|
|
92
|
+
{"from": state.get("status"), "to": status, "at": now_iso(), "note": note}
|
|
93
|
+
)
|
|
94
|
+
state["status"] = status
|
|
95
|
+
state["updated_at"] = now_iso()
|
|
96
|
+
save_run_state(run_dir, state)
|
|
97
|
+
return state
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def normalize_page_id(value):
|
|
101
|
+
text = str(value).strip()
|
|
102
|
+
if text.startswith("page_"):
|
|
103
|
+
return text
|
|
104
|
+
if text.isdigit():
|
|
105
|
+
return f"page_{int(text):03d}"
|
|
106
|
+
raise ValueError(f"Invalid page id: {value}")
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def find_page(jobs, page):
|
|
110
|
+
page_id = normalize_page_id(page)
|
|
111
|
+
for entry in jobs.get("pages", []):
|
|
112
|
+
if entry.get("page_id") == page_id or entry.get("id") == page_id:
|
|
113
|
+
return entry
|
|
114
|
+
raise KeyError(f"Page not found in page_jobs.json: {page_id}")
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
def resolve_run_path(run_dir, value):
|
|
118
|
+
path = Path(value)
|
|
119
|
+
if path.is_absolute():
|
|
120
|
+
return path.resolve()
|
|
121
|
+
return (Path(run_dir) / path).resolve()
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
def rel_to_run(run_dir, value):
|
|
125
|
+
path = Path(value).resolve()
|
|
126
|
+
return path.relative_to(Path(run_dir).resolve()).as_posix()
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
def resolve_inside(base_dir, value):
|
|
130
|
+
base = Path(base_dir).resolve()
|
|
131
|
+
path = Path(value)
|
|
132
|
+
if not path.is_absolute():
|
|
133
|
+
path = base / path
|
|
134
|
+
path = path.resolve()
|
|
135
|
+
try:
|
|
136
|
+
path.relative_to(base)
|
|
137
|
+
except ValueError as exc:
|
|
138
|
+
raise ValueError(f"Path is outside allowed directory: {path}") from exc
|
|
139
|
+
return path
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
def all_pages_have_status(jobs, statuses):
|
|
143
|
+
allowed = set(statuses)
|
|
144
|
+
return all(page.get("status") in allowed for page in jobs.get("pages", []))
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
def max_concurrent_pages(jobs):
|
|
148
|
+
value = jobs.get("max_concurrent_pages", DEFAULT_MAX_CONCURRENT_PAGES)
|
|
149
|
+
try:
|
|
150
|
+
value = int(value)
|
|
151
|
+
except (TypeError, ValueError) as exc:
|
|
152
|
+
raise ValueError(f"Invalid max_concurrent_pages: {value}") from exc
|
|
153
|
+
if value < 1:
|
|
154
|
+
raise ValueError("max_concurrent_pages must be >= 1")
|
|
155
|
+
return value
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
def active_pages(jobs):
|
|
159
|
+
return [page for page in jobs.get("pages", []) if page.get("status") in ACTIVE_PAGE_STATUSES]
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
def dispatchable_pages(jobs):
|
|
163
|
+
return [
|
|
164
|
+
page
|
|
165
|
+
for page in jobs.get("pages", [])
|
|
166
|
+
if page.get("status") in DISPATCHABLE_PAGE_STATUSES
|
|
167
|
+
]
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
def dispatch_slots_available(jobs):
|
|
171
|
+
return max(0, max_concurrent_pages(jobs) - len(active_pages(jobs)))
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
def update_jobs_run_status(jobs):
|
|
175
|
+
pages = jobs.get("pages", [])
|
|
176
|
+
if pages and all(page.get("status") in {"dispatched", "recorded", "accepted"} for page in pages):
|
|
177
|
+
jobs["run_status"] = "pages_dispatched"
|
|
178
|
+
if pages and all(page.get("status") in {"recorded", "accepted"} for page in pages):
|
|
179
|
+
jobs["run_status"] = "pages_recorded"
|
|
180
|
+
if pages and all(page.get("status") == "accepted" for page in pages):
|
|
181
|
+
jobs["run_status"] = "complete"
|
|
182
|
+
jobs["updated_at"] = now_iso()
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
def inside_or_missing(page_dir, value):
|
|
186
|
+
path = resolve_inside(page_dir, value)
|
|
187
|
+
if not path.exists():
|
|
188
|
+
raise FileNotFoundError(path)
|
|
189
|
+
return path
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
def safe_agent_label(agent_id, nickname=None):
|
|
193
|
+
label = str(agent_id).strip()
|
|
194
|
+
if nickname:
|
|
195
|
+
label += f" ({nickname})"
|
|
196
|
+
return label
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
def page_dir_for(run_dir, page):
|
|
200
|
+
return resolve_run_path(run_dir, page["page_dir"])
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
def ensure_file(path, label):
|
|
204
|
+
path = Path(path)
|
|
205
|
+
if not path.exists() or not path.is_file():
|
|
206
|
+
raise FileNotFoundError(f"Missing {label}: {path}")
|
|
207
|
+
return path
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
def ensure_dir(path, label):
|
|
211
|
+
path = Path(path)
|
|
212
|
+
if not path.exists() or not path.is_dir():
|
|
213
|
+
raise FileNotFoundError(f"Missing {label}: {path}")
|
|
214
|
+
return path
|
package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/deck_text_hints.py
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Generate text hints for every page of a prepared run.
|
|
3
|
+
|
|
4
|
+
Runs as part of `editppt prepare`, after page directories exist: each
|
|
5
|
+
`pages/page_NNN/` receives canonical `text_hints.json` and `text_hints.png`
|
|
6
|
+
files so page workers find their text measurements already in place.
|
|
7
|
+
|
|
8
|
+
Backend selection per run:
|
|
9
|
+
- With a PaddleOCR token (PADDLE_OCR_TOKEN env var, or PADDLE_OCR_TOKEN in
|
|
10
|
+
~/.editppt/config.yaml): PDF inputs are submitted to the OCR service as ONE
|
|
11
|
+
job covering all pages; image/PPTX inputs submit each page's source.png.
|
|
12
|
+
OCR coordinates are rescaled to each page's actual source.png resolution
|
|
13
|
+
and re-measured locally with the ink metrics.
|
|
14
|
+
- Without a token, or when the service fails: the built-in offline detector
|
|
15
|
+
(`text_hints.py`) runs per page, so every page still gets hints.
|
|
16
|
+
|
|
17
|
+
Hint generation is best-effort: a page that fails is reported and skipped,
|
|
18
|
+
and the page worker can regenerate with `editppt page hints <page_dir>`.
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
from __future__ import annotations
|
|
22
|
+
|
|
23
|
+
import argparse
|
|
24
|
+
import json
|
|
25
|
+
import os
|
|
26
|
+
import sys
|
|
27
|
+
from pathlib import Path
|
|
28
|
+
|
|
29
|
+
from PIL import Image
|
|
30
|
+
|
|
31
|
+
from deck_run_state import load_deck, load_jobs, page_dir_for, run_dir_from_target
|
|
32
|
+
from text_hints import draw_overlay, page_text_hints
|
|
33
|
+
|
|
34
|
+
HINTS_JSON = "text_hints.json"
|
|
35
|
+
HINTS_PNG = "text_hints.png"
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def paddle_token() -> str:
|
|
39
|
+
token = os.environ.get("PADDLE_OCR_TOKEN", "").strip()
|
|
40
|
+
if token:
|
|
41
|
+
return token
|
|
42
|
+
try:
|
|
43
|
+
from runtime_env import config_path, read_config_file
|
|
44
|
+
|
|
45
|
+
return str(read_config_file(config_path()).get("PADDLE_OCR_TOKEN", "")).strip()
|
|
46
|
+
except Exception:
|
|
47
|
+
return ""
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def write_hints(page_dir: Path, hints: dict, overlay: bool) -> None:
|
|
51
|
+
(page_dir / HINTS_JSON).write_text(json.dumps(hints, ensure_ascii=False, indent=2) + "\n", encoding="utf-8")
|
|
52
|
+
if overlay:
|
|
53
|
+
draw_overlay(Image.open(page_dir / "source.png"), hints["lines"], page_dir / HINTS_PNG)
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def builtin_page(page_dir: Path) -> dict:
|
|
57
|
+
hints = page_text_hints(page_dir)
|
|
58
|
+
hints["backend"] = "builtin-ink"
|
|
59
|
+
return hints
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def synthesize_pdf(page_dirs: list[Path], out_path: Path) -> None:
|
|
63
|
+
"""Bundle the per-page source images into one PDF (one page per image).
|
|
64
|
+
|
|
65
|
+
Lets every input type — single image, multiple images, image-based PPTX —
|
|
66
|
+
reach the OCR service as a single batch job instead of one job per page.
|
|
67
|
+
Page size is the image's pixel size in points; build_page_hints rescales
|
|
68
|
+
the OCR coordinates back to each source.png regardless of the resolution
|
|
69
|
+
the service rendered at.
|
|
70
|
+
"""
|
|
71
|
+
import fitz
|
|
72
|
+
|
|
73
|
+
document = fitz.open()
|
|
74
|
+
for page_dir in page_dirs:
|
|
75
|
+
with Image.open(page_dir / "source.png") as image:
|
|
76
|
+
width, height = image.size
|
|
77
|
+
page = document.new_page(width=width, height=height)
|
|
78
|
+
page.insert_image(fitz.Rect(0, 0, width, height), filename=str(page_dir / "source.png"))
|
|
79
|
+
document.save(out_path)
|
|
80
|
+
document.close()
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def paddle_pages(run_dir: Path, deck: dict, page_dirs: list[Path], token: str, timeout: int) -> dict[Path, dict]:
|
|
84
|
+
"""Fetch OCR results for all pages in ONE job; returns {page_dir: hints}."""
|
|
85
|
+
import tempfile
|
|
86
|
+
|
|
87
|
+
from paddle_text_hints import DEFAULT_MODEL, build_page_hints, submit_and_fetch
|
|
88
|
+
|
|
89
|
+
original = None
|
|
90
|
+
if str(deck.get("input_type", "")) == "pdf":
|
|
91
|
+
input_dir = run_dir / "input"
|
|
92
|
+
candidates = sorted(input_dir.glob("*.pdf")) if input_dir.exists() else []
|
|
93
|
+
original = candidates[0] if candidates else None
|
|
94
|
+
|
|
95
|
+
synthesized = None
|
|
96
|
+
try:
|
|
97
|
+
if original is None:
|
|
98
|
+
handle = tempfile.NamedTemporaryFile(suffix=".pdf", delete=False)
|
|
99
|
+
handle.close()
|
|
100
|
+
synthesized = Path(handle.name)
|
|
101
|
+
synthesize_pdf(page_dirs, synthesized)
|
|
102
|
+
original = synthesized
|
|
103
|
+
pages = submit_and_fetch(original, token, DEFAULT_MODEL, timeout)
|
|
104
|
+
finally:
|
|
105
|
+
if synthesized is not None:
|
|
106
|
+
synthesized.unlink(missing_ok=True)
|
|
107
|
+
if len(pages) != len(page_dirs):
|
|
108
|
+
raise RuntimeError(f"OCR returned {len(pages)} pages for {len(page_dirs)} page dirs")
|
|
109
|
+
return {page_dir: build_page_hints(page_dir, pruned) for page_dir, pruned in zip(page_dirs, pages)}
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def main() -> int:
|
|
113
|
+
parser = argparse.ArgumentParser(description="Generate per-page text hints for a prepared run.")
|
|
114
|
+
parser.add_argument("run", help="Run directory or deck_manifest.json path.")
|
|
115
|
+
parser.add_argument("--timeout", type=int, default=300, help="OCR job timeout in seconds.")
|
|
116
|
+
parser.add_argument("--no-overlay", action="store_true", help="Skip the labeled overlay images.")
|
|
117
|
+
args = parser.parse_args()
|
|
118
|
+
|
|
119
|
+
run_dir = run_dir_from_target(args.run)
|
|
120
|
+
deck = load_deck(run_dir)
|
|
121
|
+
jobs = load_jobs(run_dir)
|
|
122
|
+
page_dirs = [page_dir_for(run_dir, page) for page in jobs.get("pages", [])]
|
|
123
|
+
page_dirs = [d for d in page_dirs if (d / "source.png").exists()]
|
|
124
|
+
if not page_dirs:
|
|
125
|
+
print("text-hints: no pages with source.png; skipped", file=sys.stderr)
|
|
126
|
+
return 0
|
|
127
|
+
|
|
128
|
+
token = paddle_token()
|
|
129
|
+
results: dict[Path, dict] = {}
|
|
130
|
+
backend = "builtin-ink"
|
|
131
|
+
if not token:
|
|
132
|
+
print(
|
|
133
|
+
"text-hints: no PaddleOCR token configured; falling back to the built-in offline "
|
|
134
|
+
"detector (geometry only — it measures where text is and how large, but cannot read "
|
|
135
|
+
"it). A free PaddleOCR-VL token adds recognized text content and cleaner block "
|
|
136
|
+
"boundaries, noticeably improving text fidelity in the final PPT. The free personal quota "
|
|
137
|
+
"is currently more than enough for this skill, so applying is risk-free with no extra "
|
|
138
|
+
"cost. ASK THE USER once "
|
|
139
|
+
"before reconstructing pages: configure a token now (apply at "
|
|
140
|
+
"https://aistudio.baidu.com/account/accessToken, then `editppt config "
|
|
141
|
+
"--paddle-ocr-token <token>` and `editppt run hints <run>` to regenerate this run's "
|
|
142
|
+
"hints), or continue with the offline result. Respect their choice and do not ask again.",
|
|
143
|
+
file=sys.stderr,
|
|
144
|
+
)
|
|
145
|
+
if token:
|
|
146
|
+
try:
|
|
147
|
+
results = paddle_pages(run_dir, deck, page_dirs, token, args.timeout)
|
|
148
|
+
backend = "paddleocr-vl"
|
|
149
|
+
except Exception as exc:
|
|
150
|
+
print(f"text-hints: PaddleOCR failed ({exc}); falling back to built-in detector", file=sys.stderr)
|
|
151
|
+
results = {}
|
|
152
|
+
|
|
153
|
+
written = 0
|
|
154
|
+
for page_dir in page_dirs:
|
|
155
|
+
try:
|
|
156
|
+
hints = results.get(page_dir) or builtin_page(page_dir)
|
|
157
|
+
# Dense diagrams can defeat the OCR layout model entirely (the
|
|
158
|
+
# whole figure is classified as an image and only a headline
|
|
159
|
+
# survives). When OCR found almost nothing but the offline
|
|
160
|
+
# detector finds plenty, the geometric hints are more useful.
|
|
161
|
+
if hints.get("backend") == "paddleocr-vl" and len(hints["lines"]) <= 2:
|
|
162
|
+
offline = builtin_page(page_dir)
|
|
163
|
+
if len(offline["lines"]) >= 6:
|
|
164
|
+
print(
|
|
165
|
+
f"text-hints: {page_dir.name}: OCR found {len(hints['lines'])} text lines but the "
|
|
166
|
+
f"offline detector found {len(offline['lines'])}; using the offline result for this page",
|
|
167
|
+
file=sys.stderr,
|
|
168
|
+
)
|
|
169
|
+
hints = offline
|
|
170
|
+
write_hints(page_dir, hints, overlay=not args.no_overlay)
|
|
171
|
+
written += 1
|
|
172
|
+
except Exception as exc:
|
|
173
|
+
print(f"text-hints: {page_dir.name} failed ({exc}); worker can run `editppt page hints` itself", file=sys.stderr)
|
|
174
|
+
print(f"text-hints: wrote {written}/{len(page_dirs)} pages (backend={backend})")
|
|
175
|
+
return 0
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
if __name__ == "__main__":
|
|
179
|
+
raise SystemExit(main())
|
package/bundled-assets/skill/vendor/image-to-editable-ppt/cli/editppt/runtime/finalize_deck_run.py
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
import argparse
|
|
3
|
+
import json
|
|
4
|
+
import subprocess
|
|
5
|
+
import sys
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
|
|
8
|
+
from deck_run_state import load_deck, load_jobs, now_iso, run_dir_from_target, save_deck, save_jobs, set_run_status, sha256_file, write_json
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
SCRIPT_DIR = Path(__file__).resolve().parent
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def run(command):
|
|
15
|
+
print("+ " + " ".join(str(part) for part in command), flush=True)
|
|
16
|
+
subprocess.run([str(part) for part in command], check=True)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def final_output_path(run_dir, deck):
|
|
20
|
+
output = Path(deck.get("output", "final/deck_edited.pptx"))
|
|
21
|
+
if output.is_absolute():
|
|
22
|
+
return output
|
|
23
|
+
return run_dir / output
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def assert_pages_ready(run_dir, jobs):
|
|
27
|
+
problems = []
|
|
28
|
+
for page in jobs.get("pages", []):
|
|
29
|
+
if page.get("status") not in {"recorded", "accepted"}:
|
|
30
|
+
problems.append(f"{page['page_id']} status={page.get('status')}")
|
|
31
|
+
continue
|
|
32
|
+
result = page.get("result") or {}
|
|
33
|
+
if result.get("validation_passed") is not True:
|
|
34
|
+
problems.append(f"{page['page_id']} validation_passed={result.get('validation_passed')}")
|
|
35
|
+
outputs = result.get("outputs") or {}
|
|
36
|
+
hashes = result.get("hashes") or {}
|
|
37
|
+
if not outputs or set(outputs) != set(hashes):
|
|
38
|
+
problems.append(f"{page['page_id']} missing recorded output hashes; validate and record the page again")
|
|
39
|
+
continue
|
|
40
|
+
files = [(outputs[key], digest) for key, digest in hashes.items()]
|
|
41
|
+
files.extend((result.get("asset_hashes") or {}).items())
|
|
42
|
+
for relative_path, expected_hash in files:
|
|
43
|
+
path = Path(run_dir) / relative_path
|
|
44
|
+
if not path.is_file() or sha256_file(path) != expected_hash:
|
|
45
|
+
problems.append(
|
|
46
|
+
f"{page['page_id']} recorded artifact changed or missing: {relative_path}; "
|
|
47
|
+
"repair affected outputs, validate and record the page again"
|
|
48
|
+
)
|
|
49
|
+
if problems:
|
|
50
|
+
raise SystemExit("Pages are not ready for finalize:\n" + "\n".join(problems))
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def main():
|
|
54
|
+
parser = argparse.ArgumentParser(description="Build and validate the final editable PPTX from recorded pages.")
|
|
55
|
+
parser.add_argument("run", help="Run directory or deck_manifest.json")
|
|
56
|
+
args = parser.parse_args()
|
|
57
|
+
|
|
58
|
+
run_dir = run_dir_from_target(args.run)
|
|
59
|
+
deck = load_deck(run_dir)
|
|
60
|
+
jobs = load_jobs(run_dir)
|
|
61
|
+
assert_pages_ready(run_dir, jobs)
|
|
62
|
+
|
|
63
|
+
out = final_output_path(run_dir, deck)
|
|
64
|
+
out.parent.mkdir(parents=True, exist_ok=True)
|
|
65
|
+
run([sys.executable, SCRIPT_DIR / "build_pptx_from_manifest.py", "--deck-manifest", run_dir / "deck_manifest.json", "--out", out])
|
|
66
|
+
set_run_status(run_dir, "deck_built", "final pptx built")
|
|
67
|
+
|
|
68
|
+
validation = out.parent / "validation.json"
|
|
69
|
+
run([sys.executable, SCRIPT_DIR / "validate_pptx.py", out, "--deck-manifest", run_dir / "deck_manifest.json", "--report", validation])
|
|
70
|
+
set_run_status(run_dir, "deck_validated", "final pptx validation passed")
|
|
71
|
+
|
|
72
|
+
for page in jobs.get("pages", []):
|
|
73
|
+
page["status"] = "accepted"
|
|
74
|
+
page["accepted"] = True
|
|
75
|
+
page["accepted_at"] = now_iso()
|
|
76
|
+
jobs["run_status"] = "complete"
|
|
77
|
+
jobs["updated_at"] = now_iso()
|
|
78
|
+
save_jobs(run_dir, jobs)
|
|
79
|
+
deck["completed_at"] = now_iso()
|
|
80
|
+
save_deck(run_dir, deck)
|
|
81
|
+
summary = {
|
|
82
|
+
"schema_version": 1,
|
|
83
|
+
"run_id": deck.get("run_id"),
|
|
84
|
+
"status": "complete",
|
|
85
|
+
"page_count": len(jobs.get("pages", [])),
|
|
86
|
+
"output": str(out),
|
|
87
|
+
"validation": str(validation),
|
|
88
|
+
"completed_at": now_iso(),
|
|
89
|
+
}
|
|
90
|
+
write_json(out.parent / "run_summary.json", summary)
|
|
91
|
+
set_run_status(run_dir, "complete", "final deck complete")
|
|
92
|
+
print(json.dumps(summary, ensure_ascii=False, indent=2))
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
if __name__ == "__main__":
|
|
96
|
+
main()
|