@clipen/clipen-cli 0.0.0-stage → 1.0.0
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 +79 -2
- package/apps/web/dist/assets/index-D5D2HiB1.js +14 -0
- package/apps/web/dist/assets/index-DIMuOXSu.css +1 -0
- package/apps/web/dist/favicon.svg +1 -0
- package/apps/web/dist/index.html +16 -0
- package/bin/clipen.js +157 -0
- package/clipen +18 -0
- package/install +25 -0
- package/package.json +52 -4
- package/pyproject.toml +28 -0
- package/requirements/asr-runtime.txt +13 -0
- package/requirements/runtime.txt +20 -0
- package/src/clipen/__init__.py +3 -0
- package/src/clipen/analysis/__init__.py +89 -0
- package/src/clipen/analysis/artifacts.py +416 -0
- package/src/clipen/analysis/audio.py +392 -0
- package/src/clipen/analysis/evidence.py +102 -0
- package/src/clipen/analysis/evidence_service.py +751 -0
- package/src/clipen/analysis/image_similarity.py +143 -0
- package/src/clipen/analysis/keyframes.py +171 -0
- package/src/clipen/analysis/models.py +230 -0
- package/src/clipen/analysis/qwen_worker.py +629 -0
- package/src/clipen/analysis/resources.py +21 -0
- package/src/clipen/analysis/runtime.py +64 -0
- package/src/clipen/analysis/service.py +626 -0
- package/src/clipen/analysis/setup.py +935 -0
- package/src/clipen/analysis/setup_cli.py +117 -0
- package/src/clipen/analysis/storage.py +2046 -0
- package/src/clipen/analysis/transcription.py +948 -0
- package/src/clipen/analysis/visual.py +176 -0
- package/src/clipen/annotations/__init__.py +10 -0
- package/src/clipen/annotations/models.py +22 -0
- package/src/clipen/annotations/storage.py +380 -0
- package/src/clipen/annotations/suggestions.py +120 -0
- package/src/clipen/asr_release.py +139 -0
- package/src/clipen/bootstrap.py +967 -0
- package/src/clipen/cli.py +84 -0
- package/src/clipen/controller/__init__.py +17 -0
- package/src/clipen/controller/app.py +1470 -0
- package/src/clipen/controller/server.py +543 -0
- package/src/clipen/domain/__init__.py +30 -0
- package/src/clipen/domain/errors.py +5 -0
- package/src/clipen/domain/media_time.py +117 -0
- package/src/clipen/domain/timeline.py +584 -0
- package/src/clipen/domain/validation.py +15 -0
- package/src/clipen/editing/EDITORIAL_REGRESSIONS.md +38 -0
- package/src/clipen/editing/PROGRAM_FORMAT.md +102 -0
- package/src/clipen/editing/README.md +115 -0
- package/src/clipen/editing/REFACTOR_DESIGN.md +241 -0
- package/src/clipen/editing/REFACTOR_HANDOFF.md +73 -0
- package/src/clipen/editing/__init__.py +15 -0
- package/src/clipen/editing/agent.py +13 -0
- package/src/clipen/editing/agent_models.py +134 -0
- package/src/clipen/editing/agent_repository.py +757 -0
- package/src/clipen/editing/agent_tools.py +532 -0
- package/src/clipen/editing/alignment.py +110 -0
- package/src/clipen/editing/alignment_setup.py +108 -0
- package/src/clipen/editing/alignment_worker.py +22 -0
- package/src/clipen/editing/change_report.py +71 -0
- package/src/clipen/editing/compiler.py +41 -0
- package/src/clipen/editing/component_looks.py +107 -0
- package/src/clipen/editing/component_review.py +78 -0
- package/src/clipen/editing/coordinator.py +374 -0
- package/src/clipen/editing/editorial_review.py +187 -0
- package/src/clipen/editing/evidence_jobs.py +295 -0
- package/src/clipen/editing/history_changes.py +131 -0
- package/src/clipen/editing/music_choices.py +15 -0
- package/src/clipen/editing/production_catalog.py +192 -0
- package/src/clipen/editing/production_limits.py +59 -0
- package/src/clipen/editing/production_media.py +226 -0
- package/src/clipen/editing/production_preview.py +180 -0
- package/src/clipen/editing/production_progress.py +141 -0
- package/src/clipen/editing/production_requirements.py +50 -0
- package/src/clipen/editing/production_tools.py +596 -0
- package/src/clipen/editing/program_audio.py +118 -0
- package/src/clipen/editing/program_direction.py +49 -0
- package/src/clipen/editing/program_story.py +53 -0
- package/src/clipen/editing/program_subtitles.py +134 -0
- package/src/clipen/editing/programme_review.py +73 -0
- package/src/clipen/editing/prompt_history.py +47 -0
- package/src/clipen/editing/recut.py +127 -0
- package/src/clipen/editing/refinement_references.py +188 -0
- package/src/clipen/editing/resolve_export.py +616 -0
- package/src/clipen/editing/resolve_titles.py +234 -0
- package/src/clipen/editing/skill_tools.py +575 -0
- package/src/clipen/editing/source_dialogue.py +82 -0
- package/src/clipen/editing/speech_coverage.py +30 -0
- package/src/clipen/editing/speech_quality.py +6 -0
- package/src/clipen/editing/tool_receipts.py +52 -0
- package/src/clipen/editing/versions.py +161 -0
- package/src/clipen/editing/visual_preview.py +93 -0
- package/src/clipen/editing/workbench.py +74 -0
- package/src/clipen/filesystem.py +25 -0
- package/src/clipen/finishing/README.md +103 -0
- package/src/clipen/finishing/__init__.py +1 -0
- package/src/clipen/finishing/audio.py +149 -0
- package/src/clipen/finishing/catalog.py +181 -0
- package/src/clipen/finishing/models.py +14 -0
- package/src/clipen/finishing/renderer.py +26 -0
- package/src/clipen/mcp_editing/__init__.py +5 -0
- package/src/clipen/mcp_editing/__main__.py +40 -0
- package/src/clipen/mcp_editing/server.py +353 -0
- package/src/clipen/media/__init__.py +50 -0
- package/src/clipen/media/discovery.py +266 -0
- package/src/clipen/media/models.py +360 -0
- package/src/clipen/media/preview.py +147 -0
- package/src/clipen/media/probe.py +446 -0
- package/src/clipen/media/service.py +317 -0
- package/src/clipen/media/storage.py +742 -0
- package/src/clipen/music_vocabulary.py +5 -0
- package/src/clipen/planning/__init__.py +9 -0
- package/src/clipen/planning/models.py +240 -0
- package/src/clipen/power.py +23 -0
- package/src/clipen/projects/__init__.py +26 -0
- package/src/clipen/projects/agent_schema.py +94 -0
- package/src/clipen/projects/annotation_schema.py +40 -0
- package/src/clipen/projects/deletion.py +269 -0
- package/src/clipen/projects/evidence_schema.py +52 -0
- package/src/clipen/projects/finishing_schema.py +34 -0
- package/src/clipen/projects/models.py +192 -0
- package/src/clipen/projects/picker.py +256 -0
- package/src/clipen/projects/preview_schema.py +29 -0
- package/src/clipen/projects/service.py +175 -0
- package/src/clipen/projects/storage.py +1478 -0
- package/src/clipen/projects/timeline_schema.py +32 -0
- package/src/clipen/projects/validation_schema.py +28 -0
- package/src/clipen/provider_registry.py +75 -0
- package/src/clipen/providers/__init__.py +43 -0
- package/src/clipen/providers/account.py +194 -0
- package/src/clipen/providers/claude.py +375 -0
- package/src/clipen/providers/claude_editing.py +111 -0
- package/src/clipen/providers/codex.py +1036 -0
- package/src/clipen/providers/codex_editing.py +91 -0
- package/src/clipen/providers/editing_agent.py +565 -0
- package/src/clipen/providers/errors.py +51 -0
- package/src/clipen/providers/recovery.py +270 -0
- package/src/clipen/py.typed +1 -0
- package/src/clipen/rendering/__init__.py +12 -0
- package/src/clipen/rendering/cover.py +126 -0
- package/src/clipen/rendering/custom_components.py +240 -0
- package/src/clipen/rendering/custom_render.py +197 -0
- package/src/clipen/rendering/fonts/anton-OFL.txt +93 -0
- package/src/clipen/rendering/fonts/bebasneue-OFL.txt +93 -0
- package/src/clipen/rendering/fonts/caveat-OFL.txt +93 -0
- package/src/clipen/rendering/fonts/chenyu-OFL.txt +93 -0
- package/src/clipen/rendering/fonts/delagothicone-OFL.txt +93 -0
- package/src/clipen/rendering/fonts/hachimarupop-OFL.txt +93 -0
- package/src/clipen/rendering/fonts/iansui-OFL.txt +93 -0
- package/src/clipen/rendering/fonts/manifest.json +145 -0
- package/src/clipen/rendering/fonts/playfairdisplay-OFL.txt +93 -0
- package/src/clipen/rendering/fonts/rocknrollone-OFL.txt +93 -0
- package/src/clipen/rendering/fonts/yomogi-OFL.txt +94 -0
- package/src/clipen/rendering/fonts/yuseimagic-OFL.txt +93 -0
- package/src/clipen/rendering/fonts/zenkurenaido-OFL.txt +93 -0
- package/src/clipen/rendering/fonts/zenmarugothic-OFL.txt +93 -0
- package/src/clipen/rendering/production_effects.py +64 -0
- package/src/clipen/rendering/program_components.py +193 -0
- package/src/clipen/rendering/program_creator.py +649 -0
- package/src/clipen/rendering/program_identities.py +255 -0
- package/src/clipen/rendering/program_motion.py +141 -0
- package/src/clipen/rendering/program_studio.py +168 -0
- package/src/clipen/rendering/program_styles.py +235 -0
- package/src/clipen/rendering/program_subtitles.py +52 -0
- package/src/clipen/rendering/renderer.py +708 -0
- package/src/clipen/rendering/storage.py +243 -0
- package/src/clipen/rendering/titles.py +360 -0
- package/src/clipen/skills/__init__.py +4 -0
- package/src/clipen/skills/builtin/SKILL.md +72 -0
- package/src/clipen/skills/builtin/assets/sample-daily-vlog.mp4 +0 -0
- package/src/clipen/skills/builtin/assets/sample-event-recap.mp4 +0 -0
- package/src/clipen/skills/builtin/assets/sample-food-review.mp4 +0 -0
- package/src/clipen/skills/builtin/assets/sample-product-demo.mp4 +0 -0
- package/src/clipen/skills/builtin/assets/sample-product-review.mp4 +0 -0
- package/src/clipen/skills/builtin/assets/sample-product-unboxing.mp4 +0 -0
- package/src/clipen/skills/builtin/assets/sample-shorts-highlight.mp4 +0 -0
- package/src/clipen/skills/builtin/assets/sample-travel-highlight.mp4 +0 -0
- package/src/clipen/skills/builtin/assets/sample-travel-vlog.mp4 +0 -0
- package/src/clipen/skills/builtin/assets/style-cinema.png +0 -0
- package/src/clipen/skills/builtin/assets/style-editorial.png +0 -0
- package/src/clipen/skills/builtin/assets/style-tpl-daily-vlog.png +0 -0
- package/src/clipen/skills/builtin/assets/style-tpl-event-recap.png +0 -0
- package/src/clipen/skills/builtin/assets/style-tpl-food-review.png +0 -0
- package/src/clipen/skills/builtin/assets/style-tpl-product-demo.png +0 -0
- package/src/clipen/skills/builtin/assets/style-tpl-product-review.png +0 -0
- package/src/clipen/skills/builtin/assets/style-tpl-product-unboxing.png +0 -0
- package/src/clipen/skills/builtin/assets/style-tpl-shorts-highlight.png +0 -0
- package/src/clipen/skills/builtin/assets/style-tpl-travel-highlight.png +0 -0
- package/src/clipen/skills/builtin/assets/style-tpl-travel-vlog.png +0 -0
- package/src/clipen/skills/builtin/assets/style-variety.png +0 -0
- package/src/clipen/skills/builtin/components.json +133 -0
- package/src/clipen/skills/builtin/font_sources.json +20 -0
- package/src/clipen/skills/builtin/font_styles.json +329 -0
- package/src/clipen/skills/builtin/manifest.json +32 -0
- package/src/clipen/skills/builtin/presets.json +8 -0
- package/src/clipen/skills/builtin/references/captions.md +14 -0
- package/src/clipen/skills/builtin/references/channel-design.md +37 -0
- package/src/clipen/skills/builtin/references/editing.md +30 -0
- package/src/clipen/skills/builtin/references/font-chenyu-OFL.txt +93 -0
- package/src/clipen/skills/builtin/references/font-iansui-OFL.txt +93 -0
- package/src/clipen/skills/builtin/references/graphics.md +59 -0
- package/src/clipen/skills/builtin/references/review.md +16 -0
- package/src/clipen/skills/builtin/references/sound.md +8 -0
- package/src/clipen/skills/builtin/references/story.md +7 -0
- package/src/clipen/skills/builtin/skills/travel-program/SKILL.md +27 -0
- package/src/clipen/skills/builtin/skills/travel-program/manifest.json +6 -0
- package/src/clipen/skills/builtin/template-skills/clipen-daily-vlog/SKILL.md +33 -0
- package/src/clipen/skills/builtin/template-skills/clipen-daily-vlog/manifest.json +8 -0
- package/src/clipen/skills/builtin/template-skills/clipen-event-recap/SKILL.md +34 -0
- package/src/clipen/skills/builtin/template-skills/clipen-event-recap/manifest.json +8 -0
- package/src/clipen/skills/builtin/template-skills/clipen-food-review/SKILL.md +33 -0
- package/src/clipen/skills/builtin/template-skills/clipen-food-review/manifest.json +8 -0
- package/src/clipen/skills/builtin/template-skills/clipen-product-demo/SKILL.md +35 -0
- package/src/clipen/skills/builtin/template-skills/clipen-product-demo/manifest.json +8 -0
- package/src/clipen/skills/builtin/template-skills/clipen-product-review/SKILL.md +36 -0
- package/src/clipen/skills/builtin/template-skills/clipen-product-review/manifest.json +8 -0
- package/src/clipen/skills/builtin/template-skills/clipen-product-unboxing/SKILL.md +39 -0
- package/src/clipen/skills/builtin/template-skills/clipen-product-unboxing/manifest.json +8 -0
- package/src/clipen/skills/builtin/template-skills/clipen-shorts-highlight/SKILL.md +38 -0
- package/src/clipen/skills/builtin/template-skills/clipen-shorts-highlight/manifest.json +8 -0
- package/src/clipen/skills/builtin/template-skills/clipen-travel-highlight/SKILL.md +34 -0
- package/src/clipen/skills/builtin/template-skills/clipen-travel-highlight/manifest.json +8 -0
- package/src/clipen/skills/builtin/template-skills/clipen-travel-vlog/SKILL.md +37 -0
- package/src/clipen/skills/builtin/template-skills/clipen-travel-vlog/manifest.json +8 -0
- package/src/clipen/skills/builtin/templates.json +284 -0
- package/src/clipen/skills/builtin/visual_styles.json +1074 -0
- package/src/clipen/skills/catalog.py +218 -0
- package/src/clipen/skills/library.py +131 -0
- package/src/clipen/skills/package.py +231 -0
- package/src/clipen/skills/visual_styles.py +44 -0
- package/src/clipen/workspace.py +210 -0
- package/uninstall +25 -0
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"""Cancellable installation of the fixed local alignment runtime, without source uploads."""
|
|
2
|
+
import hashlib
|
|
3
|
+
import json
|
|
4
|
+
import os
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
import platform
|
|
7
|
+
import shutil
|
|
8
|
+
import sys
|
|
9
|
+
import time
|
|
10
|
+
import urllib.request
|
|
11
|
+
import uuid
|
|
12
|
+
import venv
|
|
13
|
+
|
|
14
|
+
from clipen.projects import ProjectError
|
|
15
|
+
from .alignment import FILES, MODEL, REVISION
|
|
16
|
+
|
|
17
|
+
HASHES = {
|
|
18
|
+
'chat_template.json':'75a8cfca24f00de72d796fbfed6858fc9614ef3dabd8696684cc3bc03a9c58ff',
|
|
19
|
+
'config.json':'8dc126e1a4ac001acb02f3a9ca6277c8a20a25485fde293bc99eeab3aedc604d',
|
|
20
|
+
'generation_config.json':'948d089b23bca1d214e768d59c4438365665f52ec6d33678f4062206b3fbbb8c',
|
|
21
|
+
'merges.txt':'8831e4f1a044471340f7c0a83d7bd71306a5b867e95fd870f74d0c5308a904d5',
|
|
22
|
+
'model.safetensors':'be19ef8ac4326d032e7673342930b14c2df30bd68c1632493b0f563e30829f91',
|
|
23
|
+
'model.safetensors.index.json':'766eb50873855eeb4d95ab92def358cfd173bfc8c7aabd8635ababa1edf6db79',
|
|
24
|
+
'preprocessor_config.json':'45e120a4eda2c20c5d7f2ea9354e63536bf35e27aa573fb7cdf78017b378770d',
|
|
25
|
+
'tokenizer_config.json':'3ab80063f8511deb9566e6ad438d17b7a6277fcffd52d92854112f19d36bd81c',
|
|
26
|
+
'vocab.json':'ca10d7e9fb3ed18575dd1e277a2579c16d108e32f27439684afa0e10b1440910',
|
|
27
|
+
}
|
|
28
|
+
RECEIPT = {'model':MODEL,'revision':REVISION,'runtime':'mlx-audio-0.6.0'}
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def root_for(data_root):
|
|
32
|
+
return Path(data_root)/'alignment'/'qwen3-0.6b-8bit-v1'
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def verified_runtime(root):
|
|
36
|
+
root=Path(root);receipt=root/'ready.json';model=root/'model';python=root/'runtime/bin/python'
|
|
37
|
+
if (any(p.is_symlink() for p in (root.parent,root,model,root/'runtime',root/'runtime/bin',receipt))
|
|
38
|
+
or not receipt.is_file() or receipt.stat().st_size>4096 or not python.is_file()):
|
|
39
|
+
return None
|
|
40
|
+
try:
|
|
41
|
+
if json.loads(receipt.read_text())!=RECEIPT:return None
|
|
42
|
+
for name,size in FILES.items():
|
|
43
|
+
path=model/name
|
|
44
|
+
if path.is_symlink() or not path.is_file() or path.stat().st_size!=size:return None
|
|
45
|
+
value=hashlib.sha256()
|
|
46
|
+
with path.open('rb') as source:
|
|
47
|
+
while block:=source.read(1024*1024):value.update(block)
|
|
48
|
+
if value.hexdigest()!=HASHES[name]:return None
|
|
49
|
+
return python,model
|
|
50
|
+
except (OSError,ValueError):return None
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def install_runtime(data_root, cancel, progress=lambda _:None):
|
|
54
|
+
if sys.platform!='darwin' or platform.machine()!='arm64':
|
|
55
|
+
raise ProjectError('alignment_platform_unsupported','本機對齊目前支援 Apple Silicon Mac。',status_code=409)
|
|
56
|
+
if data_root is None:raise ProjectError('alignment_unavailable','本機對齊目錄尚未設定。',status_code=409)
|
|
57
|
+
from clipen.finishing.audio import run_process
|
|
58
|
+
from .production_media import atomic_json
|
|
59
|
+
import fcntl
|
|
60
|
+
root=root_for(data_root)
|
|
61
|
+
if root.parent.is_symlink() or root.is_symlink():
|
|
62
|
+
raise ProjectError('storage_unsafe','模型安裝路徑不安全。',status_code=409)
|
|
63
|
+
root.parent.mkdir(mode=0o700,exist_ok=True,parents=True)
|
|
64
|
+
lock_path=root.parent/'setup.lock'
|
|
65
|
+
fd=os.open(lock_path,os.O_CREAT|os.O_RDWR|getattr(os,'O_NOFOLLOW',0),0o600)
|
|
66
|
+
staging=None
|
|
67
|
+
try:
|
|
68
|
+
deadline=time.monotonic()+1800
|
|
69
|
+
while True:
|
|
70
|
+
if cancel.is_set():raise ProjectError('user_cancelled','已取消模型準備。',status_code=409)
|
|
71
|
+
if time.monotonic()>deadline:raise ProjectError('alignment_setup_timeout','模型準備逾時。',status_code=409)
|
|
72
|
+
try:fcntl.flock(fd,fcntl.LOCK_EX|fcntl.LOCK_NB);break
|
|
73
|
+
except BlockingIOError:cancel.wait(.2)
|
|
74
|
+
if verified_runtime(root):
|
|
75
|
+
return {'ready':True,'model':MODEL,'revision':REVISION,'reused':True}
|
|
76
|
+
if root.exists():
|
|
77
|
+
# An invalid prior environment is preserved for diagnosis. Never
|
|
78
|
+
# silently delete an existing user installation during a retry.
|
|
79
|
+
raise ProjectError('alignment_install_invalid','現有對齊環境未通過驗證,請修復該本機環境。',status_code=409)
|
|
80
|
+
if shutil.disk_usage(root.parent).free < sum(FILES.values())+1024**3:
|
|
81
|
+
raise ProjectError('alignment_disk_space','準備對齊模型需要額外約 2.3 GB 可用空間。',status_code=409)
|
|
82
|
+
staging=root.parent/('.setup-'+uuid.uuid4().hex)
|
|
83
|
+
staging.mkdir(mode=0o700);(staging/'model').mkdir(mode=0o700)
|
|
84
|
+
progress({'phase':'runtime'})
|
|
85
|
+
venv.EnvBuilder(with_pip=True).create(staging/'runtime')
|
|
86
|
+
run_process([str(staging/'runtime/bin/python'),'-m','pip','install','--disable-pip-version-check','mlx-audio==0.6.0'],cancel,timeout=900)
|
|
87
|
+
total=sum(FILES.values());completed=0
|
|
88
|
+
for name,size in FILES.items():
|
|
89
|
+
path=staging/'model'/name
|
|
90
|
+
request=urllib.request.Request(f'https://huggingface.co/{MODEL}/resolve/{REVISION}/{name}',headers={'User-Agent':'Clipen-local-alignment/1'})
|
|
91
|
+
value=hashlib.sha256();count=0
|
|
92
|
+
with urllib.request.urlopen(request,timeout=30) as response,path.open('xb') as output:
|
|
93
|
+
while block:=response.read(1024*1024):
|
|
94
|
+
if cancel.is_set():raise ProjectError('user_cancelled','已取消模型下載。',status_code=409)
|
|
95
|
+
if time.monotonic()>deadline:raise ProjectError('alignment_setup_timeout','模型下載逾時。',status_code=409)
|
|
96
|
+
count+=len(block)
|
|
97
|
+
if count>size:raise ValueError('alignment download exceeds pinned size')
|
|
98
|
+
output.write(block);value.update(block)
|
|
99
|
+
progress({'phase':'model','completed_bytes':completed+count,'total_bytes':total})
|
|
100
|
+
if count!=size or value.hexdigest()!=HASHES[name]:
|
|
101
|
+
raise ProjectError('alignment_download_invalid','模型下載未通過固定版本校驗。',status_code=409)
|
|
102
|
+
completed+=size
|
|
103
|
+
atomic_json(staging/'ready.json',RECEIPT)
|
|
104
|
+
os.rename(staging,root);staging=None
|
|
105
|
+
return {'ready':True,'model':MODEL,'revision':REVISION,'reused':False}
|
|
106
|
+
finally:
|
|
107
|
+
if staging is not None:shutil.rmtree(staging,ignore_errors=True)
|
|
108
|
+
os.close(fd)
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"""Offline subprocess for the separately installed MLX forced-aligner."""
|
|
2
|
+
import json
|
|
3
|
+
import os
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
import sys
|
|
6
|
+
|
|
7
|
+
os.environ['HF_HUB_OFFLINE'] = '1'
|
|
8
|
+
os.environ['TRANSFORMERS_OFFLINE'] = '1'
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def main():
|
|
12
|
+
from mlx_audio.stt import load
|
|
13
|
+
request = json.loads(Path(sys.argv[1]).read_text())
|
|
14
|
+
model = load(request['model'])
|
|
15
|
+
language = {'zh':'Chinese','en':'English','ja':'Japanese'}[request['language']]
|
|
16
|
+
result = model.generate(audio=request['audio'], text=request['text'], language=language)
|
|
17
|
+
words = [{'text':i.text, 'start':float(i.start_time), 'end':float(i.end_time)} for i in result]
|
|
18
|
+
Path(request['output']).write_text(json.dumps(words, ensure_ascii=False))
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
if __name__ == '__main__':
|
|
22
|
+
main()
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"""The account the AI gives of each change: what it changed and why, how it handled each review note,
|
|
2
|
+
and what it left undone. finish_edit refuses to close a change without one."""
|
|
3
|
+
from clipen.projects import ProjectError
|
|
4
|
+
|
|
5
|
+
OUTCOMES = {'done': '已處理', 'partly': '部分處理', 'not_done': '沒有處理', 'kept': '照你說的保留'}
|
|
6
|
+
# Work may be left only for one of these: the person has to decide or supply something,
|
|
7
|
+
# or no Clipen tool can do it. Running out of effort is not a reason.
|
|
8
|
+
REASONS = {'needs_you': '需要你決定或提供', 'cannot': 'Clipen 目前做不到'}
|
|
9
|
+
UNFINISHED = 'change_report_unfinished'
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def _text(value, limit):
|
|
13
|
+
return isinstance(value, str) and 0 < len(value.strip()) <= limit
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def _invalid(message):
|
|
17
|
+
return ProjectError('change_report_invalid', message, status_code=422)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def check_report(arguments, intent):
|
|
21
|
+
"""The report finish_edit was given, checked against the notes the person sent with this request."""
|
|
22
|
+
changes = arguments.get('changes')
|
|
23
|
+
if not isinstance(changes, list) or not 1 <= len(changes) <= 20 or not all(
|
|
24
|
+
isinstance(c, dict) and set(c) <= {'what', 'why'} and _text(c.get('what'), 200) and _text(c.get('why'), 300) for c in changes):
|
|
25
|
+
raise _invalid('finish_edit 要附上修改說明:changes 列出 1–20 項,每項寫 what(改了什麼,200 字內)與 why(為什麼,300 字內),用觀眾看得懂的話。')
|
|
26
|
+
not_done = arguments.get('not_done', [])
|
|
27
|
+
if not isinstance(not_done, list) or len(not_done) > 10 or not all(
|
|
28
|
+
isinstance(item, dict) and set(item) <= {'what', 'reason', 'detail'} and item.get('reason') in REASONS
|
|
29
|
+
and _text(item.get('what'), 200) and _text(item.get('detail'), 300) for item in not_done):
|
|
30
|
+
raise _invalid('not_done 每項要有 what(沒做到什麼)、reason 與 detail,最多 10 項。reason 只能是 needs_you'
|
|
31
|
+
'(detail 寫使用者要決定或提供什麼)或 cannot(detail 寫是哪個工具限制做不到)。'
|
|
32
|
+
'你的工具做得到的事不能列在這裡,要先做完。')
|
|
33
|
+
request = intent.get('latest_revision_request') or {}
|
|
34
|
+
sent = {item['reference_id'] for item in (request.get('references') or {}).get('items', []) if isinstance(item, dict) and 'reference_id' in item}
|
|
35
|
+
notes = arguments.get('notes', [])
|
|
36
|
+
if not isinstance(notes, list) or not all(
|
|
37
|
+
isinstance(n, dict) and set(n) <= {'reference_id', 'outcome', 'explanation', 'reason'} and n.get('outcome') in OUTCOMES
|
|
38
|
+
and _text(n.get('explanation'), 300) and isinstance(n.get('reference_id'), str) for n in notes):
|
|
39
|
+
raise _invalid('notes 每項要有 reference_id、outcome(done/partly/not_done/kept)與 explanation(300 字內)。')
|
|
40
|
+
if any(n['outcome'] in ('partly', 'not_done') and n.get('reason') not in REASONS for n in notes):
|
|
41
|
+
raise _invalid('outcome 是 partly 或 not_done 的注記要附 reason:needs_you(需要使用者決定或提供)或 cannot(工具做不到)。'
|
|
42
|
+
'你的工具做得到的就先做完,再回報 done。')
|
|
43
|
+
answered = [n['reference_id'] for n in notes]
|
|
44
|
+
if len(answered) != len(set(answered)) or set(answered) != sent:
|
|
45
|
+
missing = len(sent - set(answered))
|
|
46
|
+
raise _invalid(f'使用者這次送了 {len(sent)} 筆注記,notes 要逐筆回應每一筆(reference_id 不重複、不多不少)'
|
|
47
|
+
+ (f';還有 {missing} 筆沒回應。' if missing else '。'))
|
|
48
|
+
return {'changes': [{'what': c['what'].strip(), 'why': c['why'].strip()} for c in changes],
|
|
49
|
+
'notes': [{'reference_id': n['reference_id'], 'outcome': n['outcome'], 'explanation': n['explanation'].strip(),
|
|
50
|
+
**({'reason': n['reason']} if n['outcome'] in ('partly', 'not_done') else {})} for n in notes],
|
|
51
|
+
'not_done': [{'what': i['what'].strip(), 'reason': i['reason'], 'detail': i['detail'].strip()} for i in not_done]}
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def unfinished(report):
|
|
55
|
+
"""What the report leaves undone, as short lines the AI is asked to reconsider."""
|
|
56
|
+
return ([f"注記 {n['reference_id']}:{n['explanation']}" for n in report['notes'] if n['outcome'] in ('partly', 'not_done')]
|
|
57
|
+
+ [f"{i['what']}({i['detail']})" for i in report['not_done']])
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def challenge(report):
|
|
61
|
+
"""Asked once per request before work is left undone: do what the tools can do first."""
|
|
62
|
+
left = unfinished(report)
|
|
63
|
+
return ProjectError(UNFINISHED, '修改說明裡還有沒做完的地方:' + ';'.join(left)[:900]
|
|
64
|
+
+ '。用你的工具做得到的,現在就做完並改回報 done;只有真的需要使用者決定或提供、或工具確實做不到的才保留,'
|
|
65
|
+
'確認後再呼叫一次 finish_edit。', status_code=409)
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def carried(report):
|
|
69
|
+
"""What the last change left for the person, handed to the next request."""
|
|
70
|
+
return [{'what': i['what'], 'reason': i['reason'], 'detail': i['detail']} for i in report.get('not_done', [])
|
|
71
|
+
if isinstance(i, dict) and i.get('reason') in REASONS]
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"""Output settings stored with an edit timeline."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from dataclasses import dataclass
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
_PRESETS = {
|
|
9
|
+
"landscape_1080p": (1920, 1080),
|
|
10
|
+
"portrait_1080p": (1080, 1920),
|
|
11
|
+
}
|
|
12
|
+
_FRAME_RATES = frozenset((24, 25, 30, 60))
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
@dataclass(frozen=True, slots=True)
|
|
16
|
+
class OutputSettings:
|
|
17
|
+
preset: str
|
|
18
|
+
frame_rate: int
|
|
19
|
+
|
|
20
|
+
def __post_init__(self) -> None:
|
|
21
|
+
if not isinstance(self.preset, str) or self.preset not in _PRESETS:
|
|
22
|
+
raise ValueError("output preset is invalid")
|
|
23
|
+
if (
|
|
24
|
+
isinstance(self.frame_rate, bool)
|
|
25
|
+
or not isinstance(self.frame_rate, int)
|
|
26
|
+
or self.frame_rate not in _FRAME_RATES
|
|
27
|
+
):
|
|
28
|
+
raise ValueError("output frame rate is invalid")
|
|
29
|
+
|
|
30
|
+
@property
|
|
31
|
+
def canvas(self) -> tuple[int, int]:
|
|
32
|
+
return _PRESETS[self.preset]
|
|
33
|
+
|
|
34
|
+
def to_payload(self) -> dict[str, object]:
|
|
35
|
+
width, height = self.canvas
|
|
36
|
+
return {
|
|
37
|
+
"preset": self.preset,
|
|
38
|
+
"frame_rate": self.frame_rate,
|
|
39
|
+
"width": width,
|
|
40
|
+
"height": height,
|
|
41
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"""Looks: named sets of typefaces and colours that graphics of one kind share.
|
|
2
|
+
|
|
3
|
+
The Agent designs each look (a chapter look, a place look, a reaction look...) and
|
|
4
|
+
every free design names the look it uses. Clipen gives the page that look's
|
|
5
|
+
fonts and colours as --look-font-<key> and --look-<key> variables, and a page may
|
|
6
|
+
draw text only in its look's typefaces, so graphics of one kind stay consistent
|
|
7
|
+
while their layout and motion remain free.
|
|
8
|
+
|
|
9
|
+
Each graphic keeps a copy of its look, so every version draws as it was saved.
|
|
10
|
+
The run's list of looks lives beside the film; the copies on the current film
|
|
11
|
+
win, so going back to an earlier version also brings back its looks.
|
|
12
|
+
"""
|
|
13
|
+
import json
|
|
14
|
+
import re
|
|
15
|
+
|
|
16
|
+
from clipen.projects import ProjectError
|
|
17
|
+
from clipen.rendering.custom_components import FONT_CHOICES
|
|
18
|
+
|
|
19
|
+
KEY = re.compile(r'^[A-Za-z0-9_\-一-鿿]{1,24}$')
|
|
20
|
+
HEX = re.compile(r'^#[0-9a-fA-F]{6}$')
|
|
21
|
+
MAX_LOOKS, MAX_FONTS, MAX_COLORS = 8, 3, 6
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def _invalid(message):
|
|
25
|
+
return ProjectError('component_look_invalid', message, status_code=422)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def normalize(value):
|
|
29
|
+
"""A look as given by the Agent, checked: {look_id, name, fonts: [{key, label, family}], colors: [{key, label, value}]}."""
|
|
30
|
+
if not isinstance(value, dict) or not isinstance(value.get('look_id'), str) or not KEY.match(value['look_id']):
|
|
31
|
+
raise _invalid('look_id 要是 1–24 個字的英數字、中文、- 或 _。')
|
|
32
|
+
name = value.get('name') if isinstance(value.get('name'), str) and value['name'].strip() else value['look_id']
|
|
33
|
+
fonts, colors = value.get('fonts'), value.get('colors', [])
|
|
34
|
+
if not isinstance(fonts, list) or not 1 <= len(fonts) <= MAX_FONTS:
|
|
35
|
+
raise _invalid(f'每個外觀要有 1–{MAX_FONTS} 套字型。')
|
|
36
|
+
if not isinstance(colors, list) or len(colors) > MAX_COLORS:
|
|
37
|
+
raise _invalid(f'每個外觀最多 {MAX_COLORS} 個顏色。')
|
|
38
|
+
def entries(items, kind):
|
|
39
|
+
seen, result = set(), []
|
|
40
|
+
for entry in items:
|
|
41
|
+
if not isinstance(entry, dict) or not isinstance(entry.get('key'), str) or not KEY.match(entry['key']) or entry['key'] in seen:
|
|
42
|
+
raise _invalid('字型與顏色的 key 要是不重複的英數字、中文、- 或 _。')
|
|
43
|
+
seen.add(entry['key'])
|
|
44
|
+
label = entry.get('label') if isinstance(entry.get('label'), str) and entry['label'].strip() else entry['key']
|
|
45
|
+
if kind == 'font':
|
|
46
|
+
if entry.get('family') not in FONT_CHOICES:
|
|
47
|
+
raise _invalid('可用的字型:' + '、'.join(FONT_CHOICES) + '。')
|
|
48
|
+
result.append({'key': entry['key'], 'label': label.strip()[:24], 'family': entry['family']})
|
|
49
|
+
else:
|
|
50
|
+
if not isinstance(entry.get('value'), str) or not HEX.match(entry['value']):
|
|
51
|
+
raise _invalid('顏色要寫成 #rrggbb。')
|
|
52
|
+
result.append({'key': entry['key'], 'label': label.strip()[:24], 'value': entry['value'].lower()})
|
|
53
|
+
return result
|
|
54
|
+
return {'look_id': value['look_id'], 'name': name.strip()[:24], 'fonts': entries(fonts, 'font'), 'colors': entries(colors, 'color')}
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def _path(tools):
|
|
58
|
+
return tools.repository.projects.root / tools.project_id / f'component-looks-{tools.run_id}.json'
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def stored(tools):
|
|
62
|
+
path = _path(tools)
|
|
63
|
+
if path.is_symlink():
|
|
64
|
+
raise ProjectError('storage_unsafe', '外觀檔案不安全。', status_code=409)
|
|
65
|
+
if not path.exists():
|
|
66
|
+
return {}
|
|
67
|
+
return {look['look_id']: look for look in json.loads(path.read_text(encoding='utf-8'))}
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def store(tools, looks):
|
|
71
|
+
from .production_media import atomic_json
|
|
72
|
+
atomic_json(_path(tools), list(looks.values()))
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def on_film(tools, timeline=None):
|
|
76
|
+
"""(graphic, profile) for each free design on the film."""
|
|
77
|
+
from .production_media import load_text_styles
|
|
78
|
+
styles = load_text_styles(tools.repository.projects, tools.project_id)
|
|
79
|
+
timeline = timeline or tools._timeline()
|
|
80
|
+
return [(item, styles[item.style_id]) for track in timeline.tracks
|
|
81
|
+
if track.track_id == 'program-components' or track.track_id.startswith('program-components-')
|
|
82
|
+
for item in track.items if styles.get(item.style_id, {}).get('component_id') == 'custom']
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def current(tools):
|
|
86
|
+
"""The run's looks, as the current film has them."""
|
|
87
|
+
looks = stored(tools)
|
|
88
|
+
for _, profile in on_film(tools):
|
|
89
|
+
look = profile.get('look')
|
|
90
|
+
if look:
|
|
91
|
+
looks[look['look_id']] = look
|
|
92
|
+
return looks
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def public(look, used=0):
|
|
96
|
+
"""A look as the Agent and the review page see it, with the variables a page writes."""
|
|
97
|
+
return {**look, 'used_by': used,
|
|
98
|
+
'fonts': [{**f, 'css': f'var(--look-font-{f["key"]})'} for f in look['fonts']],
|
|
99
|
+
'colors': [{**c, 'css': f'var(--look-{c["key"]})'} for c in look['colors']]}
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
def listing(tools):
|
|
103
|
+
counts = {}
|
|
104
|
+
for _, profile in on_film(tools):
|
|
105
|
+
if profile.get('look'):
|
|
106
|
+
counts[profile['look']['look_id']] = counts.get(profile['look']['look_id'], 0) + 1
|
|
107
|
+
return [public(look, counts.get(key, 0)) for key, look in current(tools).items()]
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"""Content checks that keep programme graphics tied to a moment, not a template."""
|
|
2
|
+
from collections import Counter
|
|
3
|
+
import re
|
|
4
|
+
import unicodedata
|
|
5
|
+
|
|
6
|
+
# Short reactions land on one beat; a long hold reads as a static label.
|
|
7
|
+
REACTION_COMPONENTS = frozenset({'reaction', 'impact', 'burst'})
|
|
8
|
+
REACTION_MAX_SECONDS = 2
|
|
9
|
+
RESTATE_RATIO = .5
|
|
10
|
+
SAME_POSITION_DISTANCE = .03
|
|
11
|
+
SAME_POSITION_RUN = 3
|
|
12
|
+
UNIFORM_DURATION_SHARE = .5
|
|
13
|
+
UNIFORM_DURATION_MINIMUM = 4
|
|
14
|
+
_PARALLEL = re.compile(r'^[^,,・]{2,8}[,,][^,,・]{2,8}$')
|
|
15
|
+
_CONCRETE = re.compile(r'[\d¥¥円元$€%]')
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def significant(text):
|
|
19
|
+
return ''.join(c for c in unicodedata.normalize('NFKC', text)
|
|
20
|
+
if unicodedata.category(c)[0] not in 'PZCS')
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def _bigrams(text):
|
|
24
|
+
text = significant(text)
|
|
25
|
+
return [text[n:n+2] for n in range(len(text)-1)]
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def restated_ratio(text, subtitles):
|
|
29
|
+
"""Share of the graphic's character pairs copied from concurrent subtitles."""
|
|
30
|
+
pairs = _bigrams(text)
|
|
31
|
+
spoken = significant(''.join(subtitles))
|
|
32
|
+
return sum(pair in spoken for pair in pairs)/len(pairs) if pairs else 0.
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def concurrent_subtitles(timeline, start, duration):
|
|
36
|
+
end = start+duration
|
|
37
|
+
return [i.text for t in timeline.tracks if t.track_id == 'agent-subtitles' for i in t.items
|
|
38
|
+
if i.start_frame < end and start < i.start_frame+i.duration_frames]
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def fact_has_information(text, detail):
|
|
42
|
+
"""A fact carries a grounded detail line or a concrete number/price."""
|
|
43
|
+
return bool(detail.strip()) or bool(_CONCRETE.search(text))
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def design_notes(timeline, elements, styles):
|
|
47
|
+
"""Advisory findings; heuristics never block delivery on their own."""
|
|
48
|
+
fps = timeline.frame_rate.numerator/timeline.frame_rate.denominator
|
|
49
|
+
ordered = sorted(elements, key=lambda i: (i.start_frame, i.item_id))
|
|
50
|
+
notes = []
|
|
51
|
+
run = []
|
|
52
|
+
for element in ordered:
|
|
53
|
+
profile = styles.get(element.style_id, {})
|
|
54
|
+
point = (profile.get('x'), profile.get('y'))
|
|
55
|
+
if run and None not in point and all(abs(a-b) <= SAME_POSITION_DISTANCE
|
|
56
|
+
for a, b in zip(point, run[-1][1])):
|
|
57
|
+
run.append((element.item_id, point))
|
|
58
|
+
else:
|
|
59
|
+
if len(run) >= SAME_POSITION_RUN:
|
|
60
|
+
notes.append({'code': 'component_position_repeated', 'item_ids': [i for i, _ in run]})
|
|
61
|
+
run = [(element.item_id, point)] if None not in point else []
|
|
62
|
+
if len(run) >= SAME_POSITION_RUN:
|
|
63
|
+
notes.append({'code': 'component_position_repeated', 'item_ids': [i for i, _ in run]})
|
|
64
|
+
if len(ordered) >= UNIFORM_DURATION_MINIMUM:
|
|
65
|
+
duration, count = Counter(round(i.duration_frames/fps*2)/2 for i in ordered).most_common(1)[0]
|
|
66
|
+
if count/len(ordered) > UNIFORM_DURATION_SHARE:
|
|
67
|
+
notes.append({'code': 'component_duration_uniform', 'seconds': duration, 'count': count})
|
|
68
|
+
for element in ordered:
|
|
69
|
+
kind = styles.get(element.style_id, {}).get('component_id')
|
|
70
|
+
primary = element.text.partition('\n')[0]
|
|
71
|
+
if kind not in {'program_title'} and _PARALLEL.match(primary):
|
|
72
|
+
notes.append({'code': 'component_parallel_phrasing', 'item_id': element.item_id, 'text': primary})
|
|
73
|
+
messages = {
|
|
74
|
+
'component_position_repeated': '連續多個元件擺在同一位置。請依每個畫面的人物、物件與空白處重新決定位置。',
|
|
75
|
+
'component_duration_uniform': '多數元件的顯示時長相同,節奏像固定節拍。請依每個瞬間的閱讀需要調整。',
|
|
76
|
+
'component_parallel_phrasing': '「A,B」對句常只是描述畫面。請改成畫面看不出的資訊或觀點,或移除這個元件。',
|
|
77
|
+
}
|
|
78
|
+
return [{**note, 'message': messages[note['code']]} for note in notes]
|