@chad.dev/dsh-adclip 0.1.0 → 0.1.1
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 +0 -1
- package/README.md +9 -9
- package/client.js +190 -91
- package/engine/src/adclip/api.py +42 -14
- package/engine/src/adclip/catalog.py +341 -0
- package/engine/src/adclip/image_params.py +30 -49
- package/engine/src/adclip/intents.py +30 -11
- package/engine/src/adclip/media/ffmpeg.py +4 -4
- package/engine/src/adclip/media/subtitles.py +1 -1
- package/engine/src/adclip/models.py +2 -2
- package/engine/src/adclip/params.py +19 -224
- package/engine/src/adclip/pipeline/generate.py +56 -61
- package/engine/src/adclip/pipeline/image_runner.py +23 -8
- package/engine/src/adclip/pipeline/post.py +10 -3
- package/engine/src/adclip/pipeline/qa.py +4 -1
- package/engine/src/adclip/providers/ark.py +1 -1
- package/engine/src/adclip/providers/ark_image.py +114 -0
- package/engine/src/adclip/providers/minimax_image.py +3 -0
- package/engine/src/adclip/store.py +1 -1
- package/host/dsh.js +1 -1
- package/host/proxy.js +1 -1
- package/locale/en.json +1 -1
- package/locale/zh.json +2 -2
- package/package.json +2 -2
|
@@ -122,7 +122,7 @@ def extract_frame(source: str | Path, at_s: float, target: str | Path, width: in
|
|
|
122
122
|
return out
|
|
123
123
|
|
|
124
124
|
|
|
125
|
-
def
|
|
125
|
+
def make_synthetic_clip(
|
|
126
126
|
source: str | Path | None,
|
|
127
127
|
target: str | Path,
|
|
128
128
|
*,
|
|
@@ -131,11 +131,11 @@ def make_demo_clip(
|
|
|
131
131
|
height: int,
|
|
132
132
|
fps: int = 30,
|
|
133
133
|
) -> Path:
|
|
134
|
-
"""Create a deterministic
|
|
134
|
+
"""Create a deterministic synthetic clip for tests.
|
|
135
135
|
|
|
136
136
|
With a reference source, trim/loop it to the requested duration and frame.
|
|
137
137
|
Without a source, render a test pattern so text-to-video can be exercised.
|
|
138
|
-
The clip is
|
|
138
|
+
The clip is synthetic: only the test mode uses it, never a paid provider result.
|
|
139
139
|
"""
|
|
140
140
|
out = Path(target)
|
|
141
141
|
out.parent.mkdir(parents=True, exist_ok=True)
|
|
@@ -179,7 +179,7 @@ def make_demo_clip(
|
|
|
179
179
|
]
|
|
180
180
|
proc = run(cmd, timeout=300)
|
|
181
181
|
if proc.returncode != 0 or not out.is_file():
|
|
182
|
-
raise RuntimeError(f"
|
|
182
|
+
raise RuntimeError(f"synthetic clip failed: {proc.stderr[-500:]}")
|
|
183
183
|
return out
|
|
184
184
|
|
|
185
185
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"""Pydantic contracts for
|
|
1
|
+
"""Pydantic contracts for AdClip.
|
|
2
2
|
|
|
3
3
|
The service deliberately keeps one user-visible object: a Run. A Run owns its
|
|
4
4
|
storyboard, segments, versions and artifacts. There is no project/version/shot
|
|
@@ -95,7 +95,7 @@ class Run(BaseModel):
|
|
|
95
95
|
storyboard: list[StoryboardSegment] = Field(default_factory=list)
|
|
96
96
|
result: Optional[dict[str, Any]] = None
|
|
97
97
|
error: Optional[str] = None
|
|
98
|
-
demo: bool =
|
|
98
|
+
demo: bool = False
|
|
99
99
|
cancel_requested: bool = False
|
|
100
100
|
created_at: str = ""
|
|
101
101
|
finished_at: Optional[str] = None
|
|
@@ -1,246 +1,39 @@
|
|
|
1
|
-
"""Model catalogue, scenario manifests and video parameter helpers.
|
|
1
|
+
"""Model catalogue views, scenario manifests and video parameter helpers.
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
The rows live in `catalog.py`, which knows both video and image models. This
|
|
4
|
+
module keeps the video-shaped helpers the pipeline already imports, so callers
|
|
5
|
+
can keep asking for "the video models" without knowing about kinds.
|
|
5
6
|
"""
|
|
6
7
|
from __future__ import annotations
|
|
7
8
|
|
|
8
|
-
import os
|
|
9
|
-
import time
|
|
10
9
|
from typing import Any
|
|
11
10
|
|
|
12
|
-
from . import
|
|
11
|
+
from . import catalog as model_catalog
|
|
13
12
|
|
|
14
13
|
|
|
15
|
-
def
|
|
16
|
-
return
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
# The first slice ships with a local demo provider. Real adapters are wired in
|
|
20
|
-
# the next step; their entries stay unavailable until the adapter exists.
|
|
21
|
-
MODELS: list[dict[str, Any]] = [
|
|
22
|
-
{
|
|
23
|
-
"id": "demo",
|
|
24
|
-
"provider": "demo",
|
|
25
|
-
"model": "local-demo",
|
|
26
|
-
"label": "Demo(本地占位)",
|
|
27
|
-
"native_audio": True,
|
|
28
|
-
"modes": ["text_to_video", "image_to_video", "reference_to_video"],
|
|
29
|
-
"durations": [5, 8, 10, 12, 15, 30],
|
|
30
|
-
"resolutions": ["480p", "720p", "1080p"],
|
|
31
|
-
"aspects": ["9:16", "16:9", "1:1", "4:3", "3:4", "21:9"],
|
|
32
|
-
"max_duration_s": 30,
|
|
33
|
-
"requires": [],
|
|
34
|
-
"available": True,
|
|
35
|
-
"adapter_ready": True,
|
|
36
|
-
"reason": "本地占位,不调用模型",
|
|
37
|
-
"tags": ["本地", "无模型调用"],
|
|
38
|
-
},
|
|
39
|
-
{
|
|
40
|
-
"id": "ark.seedance-2.5",
|
|
41
|
-
"provider": "ark",
|
|
42
|
-
"model": "doubao-seedance-2-5-260628",
|
|
43
|
-
"label": "Seedance 2.5(火山方舟)",
|
|
44
|
-
"native_audio": True,
|
|
45
|
-
"modes": ["text_to_video", "image_to_video", "reference_to_video"],
|
|
46
|
-
"durations": [4, 5, 8, 10, 12, 15, 30],
|
|
47
|
-
"resolutions": ["480p", "720p"],
|
|
48
|
-
"aspects": ["9:16", "16:9", "1:1", "4:3", "3:4", "21:9"],
|
|
49
|
-
"max_duration_s": 30,
|
|
50
|
-
"requires": ["ARK_API_KEY"],
|
|
51
|
-
"available": False,
|
|
52
|
-
"adapter_ready": True,
|
|
53
|
-
"reason": "适配器已实现;配置 ARK_API_KEY 后待真实账号实测",
|
|
54
|
-
"tags": ["中文对白首选", "原生音频"],
|
|
55
|
-
},
|
|
56
|
-
{
|
|
57
|
-
"id": "ark.seedance-2.0",
|
|
58
|
-
"provider": "ark",
|
|
59
|
-
"model": "doubao-seedance-2-0-260128",
|
|
60
|
-
"label": "Seedance 2.0(火山方舟)",
|
|
61
|
-
"native_audio": True,
|
|
62
|
-
"modes": ["text_to_video", "image_to_video", "reference_to_video"],
|
|
63
|
-
"durations": [4, 5, 8, 10, 12, 15],
|
|
64
|
-
"resolutions": ["480p", "720p", "1080p"],
|
|
65
|
-
"aspects": ["9:16", "16:9", "1:1", "4:3", "3:4", "21:9"],
|
|
66
|
-
"max_duration_s": 15,
|
|
67
|
-
"requires": ["ARK_API_KEY"],
|
|
68
|
-
"available": False,
|
|
69
|
-
"adapter_ready": True,
|
|
70
|
-
"reason": "适配器已实现;配置 ARK_API_KEY 后待真实账号实测",
|
|
71
|
-
"tags": ["原生音频", "中文"],
|
|
72
|
-
},
|
|
73
|
-
{
|
|
74
|
-
"id": "ark.seedance-2.0-mini",
|
|
75
|
-
"provider": "ark",
|
|
76
|
-
"model": "doubao-seedance-2-0-mini-260615",
|
|
77
|
-
"label": "Seedance 2.0 Mini(火山方舟)",
|
|
78
|
-
"native_audio": True,
|
|
79
|
-
"modes": ["text_to_video", "image_to_video", "reference_to_video"],
|
|
80
|
-
"durations": [4, 5, 8, 10, 12, 15],
|
|
81
|
-
"resolutions": ["480p", "720p", "1080p"],
|
|
82
|
-
"aspects": ["9:16", "16:9", "1:1", "4:3", "3:4", "21:9"],
|
|
83
|
-
"max_duration_s": 15,
|
|
84
|
-
"requires": ["ARK_API_KEY"],
|
|
85
|
-
"available": False,
|
|
86
|
-
"adapter_ready": True,
|
|
87
|
-
"reason": "真实账号已实测:720p 原生中文对白可用",
|
|
88
|
-
"tags": ["Mini", "原生音频", "已实测"],
|
|
89
|
-
},
|
|
90
|
-
{
|
|
91
|
-
"id": "ark.seedance-2.0-fast",
|
|
92
|
-
"provider": "ark",
|
|
93
|
-
"model": "doubao-seedance-2-0-fast-260128",
|
|
94
|
-
"label": "Seedance 2.0 Fast(火山方舟)",
|
|
95
|
-
"native_audio": True,
|
|
96
|
-
"modes": ["text_to_video", "image_to_video", "reference_to_video"],
|
|
97
|
-
"durations": [4, 5, 8, 10, 12, 15],
|
|
98
|
-
"resolutions": ["480p", "720p", "1080p"],
|
|
99
|
-
"aspects": ["9:16", "16:9", "1:1", "4:3", "3:4", "21:9"],
|
|
100
|
-
"max_duration_s": 15,
|
|
101
|
-
"requires": ["ARK_API_KEY"],
|
|
102
|
-
"available": False,
|
|
103
|
-
"adapter_ready": True,
|
|
104
|
-
"reason": "真实账号已实测:720p 原生中文对白可用",
|
|
105
|
-
"tags": ["Fast", "原生音频", "已实测"],
|
|
106
|
-
},
|
|
107
|
-
{
|
|
108
|
-
"id": "kling.v3",
|
|
109
|
-
"provider": "kling",
|
|
110
|
-
"model": "kling-v3",
|
|
111
|
-
"label": "Kling v3(可灵)",
|
|
112
|
-
"native_audio": True,
|
|
113
|
-
"modes": ["text_to_video", "image_to_video", "reference_to_video"],
|
|
114
|
-
"durations": [3, 5, 8, 10, 12, 15],
|
|
115
|
-
"resolutions": ["720p", "1080p"],
|
|
116
|
-
"aspects": ["9:16", "16:9", "1:1"],
|
|
117
|
-
"max_duration_s": 15,
|
|
118
|
-
"requires": ["KLING_API_KEY"],
|
|
119
|
-
"available": False,
|
|
120
|
-
"adapter_ready": True,
|
|
121
|
-
"reason": "适配器已实现;配置 KLING_API_KEY 后待真实账号实测",
|
|
122
|
-
"tags": ["1080p 候选", "原生音频"],
|
|
123
|
-
},
|
|
124
|
-
{
|
|
125
|
-
"id": "minimax.hailuo-2.3-fast",
|
|
126
|
-
"provider": "minimax",
|
|
127
|
-
"model": "MiniMax-Hailuo-2.3-Fast",
|
|
128
|
-
"label": "MiniMax Hailuo 2.3 Fast(图生视频)",
|
|
129
|
-
"native_audio": False,
|
|
130
|
-
"modes": ["image_to_video"],
|
|
131
|
-
"durations": [6, 10],
|
|
132
|
-
"resolutions": ["768P", "1080P"],
|
|
133
|
-
"aspects": ["9:16", "16:9", "1:1", "4:3", "3:4", "21:9"],
|
|
134
|
-
"max_duration_s": 10,
|
|
135
|
-
"requires": ["MINIMAX_API_KEY"],
|
|
136
|
-
"available": False,
|
|
137
|
-
"adapter_ready": True,
|
|
138
|
-
"reason": "图生视频已实测;无原生音频,只适合纯画面/后期配乐",
|
|
139
|
-
"tags": ["图生视频已验证", "无原生音频"],
|
|
140
|
-
},
|
|
141
|
-
{
|
|
142
|
-
"id": "minimax.h3",
|
|
143
|
-
"provider": "minimax",
|
|
144
|
-
"model": "MiniMax-H3",
|
|
145
|
-
"label": "MiniMax H3(2K · 原生对白)",
|
|
146
|
-
"native_audio": True,
|
|
147
|
-
"modes": ["text_to_video", "image_to_video"],
|
|
148
|
-
"durations": [4, 5, 6, 8, 10, 12, 15],
|
|
149
|
-
"resolutions": ["2K"],
|
|
150
|
-
"aspects": ["9:16", "16:9", "1:1", "4:3", "3:4", "21:9"],
|
|
151
|
-
"max_duration_s": 15,
|
|
152
|
-
"requires": ["MINIMAX_API_KEY"],
|
|
153
|
-
"available": False,
|
|
154
|
-
"adapter_ready": True,
|
|
155
|
-
"reason": "2K 适配器已实测:中文原生对白可用",
|
|
156
|
-
"tags": ["2K", "中文原生对白已验证"],
|
|
157
|
-
},
|
|
158
|
-
{
|
|
159
|
-
"id": "volcengine.jimeng-3.0",
|
|
160
|
-
"provider": "volcengine",
|
|
161
|
-
"model": "jimeng_ti2v_v30_pro",
|
|
162
|
-
"label": "火山引擎即梦 3.0 Pro",
|
|
163
|
-
"native_audio": False,
|
|
164
|
-
"modes": ["text_to_video", "image_to_video"],
|
|
165
|
-
"durations": [5, 10],
|
|
166
|
-
"resolutions": ["720p", "1080p"],
|
|
167
|
-
"aspects": ["9:16", "16:9", "1:1", "4:3", "3:4", "21:9"],
|
|
168
|
-
"max_duration_s": 10,
|
|
169
|
-
"requires": ["VOLC_ACCESSKEY", "VOLC_SECRETKEY"],
|
|
170
|
-
"available": False,
|
|
171
|
-
"reason": "无原生对白;只做无对白 B-roll",
|
|
172
|
-
"tags": ["无原生对白"],
|
|
173
|
-
},
|
|
174
|
-
{
|
|
175
|
-
"id": "veo.3.1",
|
|
176
|
-
"provider": "fal",
|
|
177
|
-
"model": "veo-3.1-generate-001",
|
|
178
|
-
"label": "Veo 3.1(可选)",
|
|
179
|
-
"native_audio": True,
|
|
180
|
-
"modes": ["text_to_video", "image_to_video"],
|
|
181
|
-
"durations": [8],
|
|
182
|
-
"resolutions": ["720p", "1080p"],
|
|
183
|
-
"aspects": ["9:16", "16:9"],
|
|
184
|
-
"max_duration_s": 8,
|
|
185
|
-
"requires": ["FAL_KEY"],
|
|
186
|
-
"available": False,
|
|
187
|
-
"reason": "可选海外通道,未接入",
|
|
188
|
-
"tags": ["海外", "原生音频"],
|
|
189
|
-
},
|
|
190
|
-
{
|
|
191
|
-
"id": "sora.2",
|
|
192
|
-
"provider": "fal",
|
|
193
|
-
"model": "sora-2",
|
|
194
|
-
"label": "Sora 2(可选)",
|
|
195
|
-
"native_audio": True,
|
|
196
|
-
"modes": ["text_to_video", "image_to_video"],
|
|
197
|
-
"durations": [10, 15],
|
|
198
|
-
"resolutions": ["720p"],
|
|
199
|
-
"aspects": ["9:16", "16:9"],
|
|
200
|
-
"max_duration_s": 15,
|
|
201
|
-
"requires": ["FAL_KEY", "OPENAI_API_KEY"],
|
|
202
|
-
"available": False,
|
|
203
|
-
"reason": "可选海外通道,未接入",
|
|
204
|
-
"tags": ["海外", "原生音频"],
|
|
205
|
-
},
|
|
206
|
-
]
|
|
14
|
+
def catalog_rows() -> list[dict[str, Any]]:
|
|
15
|
+
return model_catalog.for_kind("video")
|
|
207
16
|
|
|
208
17
|
|
|
209
18
|
def catalog() -> list[dict[str, Any]]:
|
|
210
|
-
"""
|
|
211
|
-
|
|
212
|
-
enabled = settings.enabled_models()
|
|
213
|
-
for row in MODELS:
|
|
214
|
-
item = dict(row)
|
|
215
|
-
# No preference file means all models are enabled by default. Once the
|
|
216
|
-
# operator saves checkboxes, only the listed ids appear in generation.
|
|
217
|
-
item["enabled"] = True if enabled is None else item["id"] in enabled
|
|
218
|
-
item["key_present"] = all(_has(name) for name in item.get("requires", []))
|
|
219
|
-
if item.get("adapter_ready") and item["id"] != "demo":
|
|
220
|
-
item["available"] = bool(item["key_present"])
|
|
221
|
-
if not item["key_present"]:
|
|
222
|
-
item["reason"] = "未配置 " + " / ".join(item.get("requires", []))
|
|
223
|
-
item["checked_at"] = time.strftime("%Y-%m-%dT%H:%M:%S%z")
|
|
224
|
-
rows.append(item)
|
|
225
|
-
return rows
|
|
19
|
+
"""Video models with live key presence and availability."""
|
|
20
|
+
return model_catalog.for_kind("video")
|
|
226
21
|
|
|
227
22
|
|
|
228
23
|
def get_model(model_id: str) -> dict[str, Any] | None:
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
return row
|
|
232
|
-
return None
|
|
24
|
+
row = model_catalog.get(model_id)
|
|
25
|
+
return row if row and row["kind"] == "video" else None
|
|
233
26
|
|
|
234
27
|
|
|
235
|
-
def available_models(
|
|
236
|
-
rows = [row for row in
|
|
237
|
-
if
|
|
238
|
-
rows = [row for row in rows if
|
|
28
|
+
def available_models(capability: str | None = None) -> list[dict[str, Any]]:
|
|
29
|
+
rows = [row for row in model_catalog.for_kind("video") if row.get("available")]
|
|
30
|
+
if capability:
|
|
31
|
+
rows = [row for row in rows if capability in (row.get("capabilities") or [])]
|
|
239
32
|
return rows
|
|
240
33
|
|
|
241
34
|
|
|
242
35
|
def default_model() -> str:
|
|
243
|
-
return "
|
|
36
|
+
return model_catalog.default_model("video", "text_to_video")
|
|
244
37
|
|
|
245
38
|
|
|
246
39
|
def supports(model_id: str, key: str, value: Any) -> bool:
|
|
@@ -292,7 +85,7 @@ DEFAULT_ADVANCED = {
|
|
|
292
85
|
"fidelity": "balanced",
|
|
293
86
|
"language": "zh",
|
|
294
87
|
"native_audio": True,
|
|
295
|
-
"subtitle": "
|
|
88
|
+
"subtitle": "off",
|
|
296
89
|
"subtitle_size": 32,
|
|
297
90
|
"music": "off",
|
|
298
91
|
"export_bitrate": "8M",
|
|
@@ -318,6 +111,7 @@ SCENARIOS: list[dict[str, Any]] = [
|
|
|
318
111
|
{"key": "aspect", "label": "比例", "type": "enum", "options": ["9:16", "16:9", "1:1", "4:3", "3:4", "21:9"], "default": "9:16"},
|
|
319
112
|
{"key": "resolution", "label": "清晰度", "type": "enum", "options": ["480p", "720p", "1080p"], "default": "720p"},
|
|
320
113
|
{"key": "model", "label": "模型", "type": "model", "default": "auto"},
|
|
114
|
+
{"key": "subtitle", "label": "字幕", "type": "enum", "options": ["off", "sidecar"], "default": "off"},
|
|
321
115
|
],
|
|
322
116
|
"examples": [],
|
|
323
117
|
},
|
|
@@ -335,6 +129,7 @@ SCENARIOS: list[dict[str, Any]] = [
|
|
|
335
129
|
{"key": "aspect", "label": "比例", "type": "enum", "options": ["9:16", "16:9", "1:1"], "default": "9:16"},
|
|
336
130
|
{"key": "resolution", "label": "清晰度", "type": "enum", "options": ["480p", "720p", "1080p"], "default": "720p"},
|
|
337
131
|
{"key": "model", "label": "模型", "type": "model", "default": "auto"},
|
|
132
|
+
{"key": "subtitle", "label": "字幕", "type": "enum", "options": ["off", "sidecar"], "default": "off"},
|
|
338
133
|
],
|
|
339
134
|
"examples": [],
|
|
340
135
|
},
|
|
@@ -1,22 +1,36 @@
|
|
|
1
|
-
"""Generation:
|
|
1
|
+
"""Generation: capability-driven model choice plus the real provider adapters."""
|
|
2
2
|
from __future__ import annotations
|
|
3
3
|
|
|
4
4
|
from pathlib import Path
|
|
5
5
|
from typing import Any
|
|
6
6
|
|
|
7
|
-
from .. import params, store
|
|
7
|
+
from .. import catalog, params, store
|
|
8
8
|
from ..media import ffmpeg
|
|
9
|
-
from ..media import stitch as stitch_mod
|
|
10
9
|
from ..providers.ark import ArkProvider
|
|
11
10
|
from ..providers.kling import KlingProvider
|
|
12
11
|
from ..providers.minimax import MiniMaxProvider
|
|
13
12
|
from . import persona as persona_mod
|
|
14
13
|
|
|
14
|
+
PROVIDERS = {"ark": ArkProvider, "kling": KlingProvider, "minimax": MiniMaxProvider}
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def _adapter(model_id: str) -> Any | None:
|
|
18
|
+
"""Adapter instance for a catalogue row, or None for the test-only model."""
|
|
19
|
+
row = catalog.get(model_id) or {}
|
|
20
|
+
provider = str(row.get("provider") or "")
|
|
21
|
+
if provider == "synthetic":
|
|
22
|
+
return None
|
|
23
|
+
factory = PROVIDERS.get(provider)
|
|
24
|
+
if factory is None:
|
|
25
|
+
raise RuntimeError(f"模型 {model_id} 没有可用的适配器(provider={provider or 'unknown'})")
|
|
26
|
+
return factory()
|
|
27
|
+
|
|
15
28
|
|
|
16
29
|
def resolve_model(run: Any) -> str:
|
|
30
|
+
"""The model id this run should use: explicit when valid, else capability-first."""
|
|
17
31
|
requested = str((run.advanced or {}).get("model") or "auto")
|
|
18
32
|
if requested not in {"", "auto"}:
|
|
19
|
-
model =
|
|
33
|
+
model = catalog.get(requested)
|
|
20
34
|
if model is None:
|
|
21
35
|
raise RuntimeError(f"unknown model: {requested}")
|
|
22
36
|
if model.get("enabled") is False:
|
|
@@ -25,16 +39,21 @@ def resolve_model(run: Any) -> str:
|
|
|
25
39
|
raise RuntimeError(f"模型 {requested} 不可用:{model.get('reason')}")
|
|
26
40
|
return requested
|
|
27
41
|
needs_dialogue = run.scenario == "viral-remake"
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
return
|
|
37
|
-
|
|
42
|
+
rows = catalog.with_capability("text_to_video", kind="video", usable=True)
|
|
43
|
+
if not rows:
|
|
44
|
+
raise RuntimeError("没有可用的视频模型:请在设置里配置对应厂商的 key")
|
|
45
|
+
order = {row["id"]: index for index, row in enumerate(catalog.rows())}
|
|
46
|
+
|
|
47
|
+
def rank(row: dict[str, Any]) -> tuple[int, int, int]:
|
|
48
|
+
# Real providers first, dialogue-capable models first when the scenario
|
|
49
|
+
# speaks, then catalogue order so the choice is deterministic.
|
|
50
|
+
return (
|
|
51
|
+
1 if row.get("provider") == "synthetic" else 0,
|
|
52
|
+
0 if (not needs_dialogue or row.get("native_audio")) else 1,
|
|
53
|
+
order.get(row["id"], 999),
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
return sorted(rows, key=rank)[0]["id"]
|
|
38
57
|
|
|
39
58
|
|
|
40
59
|
def _cast_text(advanced: dict[str, Any]) -> str:
|
|
@@ -126,16 +145,11 @@ def generate_segment(run: Any, seg: dict[str, Any], output: Path) -> dict[str, A
|
|
|
126
145
|
script = store.read_json(store.run_dir(run.id) / "artifacts" / "script.json", {}) or {}
|
|
127
146
|
ref_id = (run.inputs or {}).get("reference_asset_id")
|
|
128
147
|
source = store.asset_media_path(ref_id) if ref_id else None
|
|
129
|
-
if model == "demo":
|
|
130
|
-
ffmpeg.make_demo_clip(source, output, duration=seg_len, width=width, height=height, fps=int(advanced.get("fps") or 30))
|
|
131
|
-
return {"model": "demo", "path": str(output), "demo": True, "duration_s": seg_len}
|
|
132
148
|
prompt = _segment_prompt(run, script, seg)
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
else:
|
|
138
|
-
provider = ArkProvider()
|
|
149
|
+
provider = _adapter(model)
|
|
150
|
+
if provider is None:
|
|
151
|
+
ffmpeg.make_synthetic_clip(source, output, duration=seg_len, width=width, height=height, fps=int(advanced.get("fps") or 30))
|
|
152
|
+
return {"model": model, "path": str(output), "demo": True, "duration_s": seg_len}
|
|
139
153
|
allowed = list((params.get_model(model) or {}).get("durations") or [4, 5, 6, 10])
|
|
140
154
|
target = int(seg_len + 0.999)
|
|
141
155
|
gen_duration = next((d for d in sorted(allowed) if d >= target), max(allowed))
|
|
@@ -161,41 +175,22 @@ def generate(run_id: str) -> dict[str, Any]:
|
|
|
161
175
|
width, height = params.size_for(str(advanced.get("aspect") or "9:16"), str(advanced.get("resolution") or "720p"))
|
|
162
176
|
ref_id = (run.inputs or {}).get("reference_asset_id")
|
|
163
177
|
source = store.asset_media_path(ref_id) if ref_id else None
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
if
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
output=result_path,
|
|
184
|
-
)
|
|
185
|
-
return {"model": model, "path": str(result_path), "demo": False, "duration_s": duration}
|
|
186
|
-
|
|
187
|
-
mode = str(advanced.get("generation_mode") or "fast")
|
|
188
|
-
if mode == "fine" and duration > 8:
|
|
189
|
-
half = duration / 2
|
|
190
|
-
a = store.run_artifact(run_id, "demo_part0.mp4")
|
|
191
|
-
b = store.run_artifact(run_id, "demo_part1.mp4")
|
|
192
|
-
ffmpeg.make_demo_clip(source, a, duration=half, width=width, height=height, fps=int(advanced.get("fps") or 30))
|
|
193
|
-
ffmpeg.make_demo_clip(source, b, duration=half, width=width, height=height, fps=int(advanced.get("fps") or 30))
|
|
194
|
-
plan_data = stitch_mod.plan(
|
|
195
|
-
[{"path": str(a), "in_s": 0, "out_s": half}, {"path": str(b), "in_s": 0, "out_s": half}],
|
|
196
|
-
width=width, height=height, fit="black_pad", transition="cut", audio="keep",
|
|
197
|
-
)
|
|
198
|
-
stitch_mod.execute(plan_data, out)
|
|
199
|
-
else:
|
|
200
|
-
ffmpeg.make_demo_clip(source, out, duration=duration, width=width, height=height, fps=int(advanced.get("fps") or 30))
|
|
201
|
-
return {"model": "demo", "path": str(out), "demo": True, "duration_s": duration}
|
|
178
|
+
result_path = store.run_artifact(run_id, "provider_raw.mp4")
|
|
179
|
+
provider = _adapter(model)
|
|
180
|
+
if provider is None:
|
|
181
|
+
# Test-only synthetic model: a local clip so the pipeline stays runnable
|
|
182
|
+
# without any provider key.
|
|
183
|
+
ffmpeg.make_synthetic_clip(source, result_path, duration=duration, width=width, height=height, fps=int(advanced.get("fps") or 30))
|
|
184
|
+
return {"model": model, "path": str(result_path), "demo": True, "duration_s": duration}
|
|
185
|
+
script = store.read_json(store.run_dir(run_id) / "artifacts" / "script.json", {}) or {}
|
|
186
|
+
prompt = _script_prompt(run, script)
|
|
187
|
+
provider.generate(
|
|
188
|
+
prompt,
|
|
189
|
+
images=_reference_images(run),
|
|
190
|
+
duration=int(duration),
|
|
191
|
+
resolution=str(advanced.get("resolution") or "720p"),
|
|
192
|
+
aspect=str(advanced.get("aspect") or "9:16"),
|
|
193
|
+
model=model,
|
|
194
|
+
output=result_path,
|
|
195
|
+
)
|
|
196
|
+
return {"model": model, "path": str(result_path), "demo": False, "duration_s": duration}
|
|
@@ -7,7 +7,9 @@ from typing import Any
|
|
|
7
7
|
|
|
8
8
|
from .. import image_params, store
|
|
9
9
|
from ..models import Run, RunStep
|
|
10
|
-
from ..providers import minimax_image
|
|
10
|
+
from ..providers import ark_image, minimax_image
|
|
11
|
+
|
|
12
|
+
IMAGE_PROVIDERS = {"minimax": minimax_image.generate, "ark": ark_image.generate}
|
|
11
13
|
|
|
12
14
|
|
|
13
15
|
class Manager:
|
|
@@ -52,14 +54,26 @@ def execute(run_id: str) -> None:
|
|
|
52
54
|
prompt = str((run.inputs or {}).get("prompt") or "").strip()
|
|
53
55
|
if not prompt:
|
|
54
56
|
raise RuntimeError("prompt 不能为空")
|
|
55
|
-
|
|
56
|
-
|
|
57
|
+
provider = IMAGE_PROVIDERS.get(str(model.get("provider") or ""))
|
|
58
|
+
if provider is None:
|
|
59
|
+
raise RuntimeError(f"图片模型 {model_id} 没有可用的适配器")
|
|
60
|
+
raw = store.run_artifact(run_id, "image.bin")
|
|
61
|
+
reference = None
|
|
62
|
+
ref_id = str((run.inputs or {}).get("reference_asset_id") or "")
|
|
63
|
+
if ref_id:
|
|
64
|
+
reference = store.asset_media_path(ref_id)
|
|
65
|
+
generated = provider(
|
|
57
66
|
prompt,
|
|
58
67
|
model=str(model["model"]),
|
|
59
68
|
aspect=str(advanced.get("aspect") or "1:1"),
|
|
60
69
|
area=str(advanced.get("area") or "2K"),
|
|
61
70
|
output=raw,
|
|
71
|
+
reference=reference,
|
|
62
72
|
)
|
|
73
|
+
suffix = ".png" if raw.read_bytes()[:4] == b"\x89PNG" else ".jpg"
|
|
74
|
+
image_path = raw.with_suffix(suffix)
|
|
75
|
+
raw.replace(image_path)
|
|
76
|
+
raw = image_path
|
|
63
77
|
width, height = generated.get("width"), generated.get("height")
|
|
64
78
|
if not width or not height:
|
|
65
79
|
try:
|
|
@@ -68,7 +82,8 @@ def execute(run_id: str) -> None:
|
|
|
68
82
|
width, height = image.size
|
|
69
83
|
except Exception:
|
|
70
84
|
width = height = None
|
|
71
|
-
|
|
85
|
+
mime = "image/png" if raw.suffix == ".png" else "image/jpeg"
|
|
86
|
+
asset = store.create_asset(raw.read_bytes(), f"image-{run_id}{raw.suffix}", "image", mime)
|
|
72
87
|
run = store.read_run(run_id) or run
|
|
73
88
|
run.status = "succeeded"
|
|
74
89
|
run.step = "done"
|
|
@@ -99,12 +114,12 @@ def execute(run_id: str) -> None:
|
|
|
99
114
|
traceback.print_exc()
|
|
100
115
|
|
|
101
116
|
|
|
102
|
-
def create(prompt: str, model_id: str = "", aspect: str = "1:1", area: str = "2K", *, parent: Run | None = None) -> Run:
|
|
117
|
+
def create(prompt: str, model_id: str = "", aspect: str = "1:1", area: str = "2K", *, parent: Run | None = None, reference_asset_id: str = "") -> Run:
|
|
103
118
|
model = image_params.get_model(model_id or image_params.default_model())
|
|
104
119
|
if model is None:
|
|
105
|
-
raise ValueError("
|
|
120
|
+
raise ValueError("没有可用的图片模型;请在设置里配置对应厂商 key")
|
|
106
121
|
if not model.get("available"):
|
|
107
|
-
raise ValueError("
|
|
122
|
+
raise ValueError(f"图片模型不可用:{model.get('reason') or '请在设置里配置对应厂商 key'}")
|
|
108
123
|
aspect = aspect if aspect in (model.get("aspects") or []) else "1:1"
|
|
109
124
|
area = area if area in (model.get("areas") or []) else str(model.get("default_area") or "2K")
|
|
110
125
|
run_id = store.new_id("img")
|
|
@@ -118,7 +133,7 @@ def create(prompt: str, model_id: str = "", aspect: str = "1:1", area: str = "2K
|
|
|
118
133
|
status="queued",
|
|
119
134
|
step="queued",
|
|
120
135
|
progress=0.0,
|
|
121
|
-
inputs={"prompt": prompt},
|
|
136
|
+
inputs={"prompt": prompt, **({"reference_asset_id": reference_asset_id} if reference_asset_id else {})},
|
|
122
137
|
advanced={"model": model["id"], "aspect": aspect, "area": area},
|
|
123
138
|
steps=[RunStep(name="image", label="生成图片")],
|
|
124
139
|
demo=False,
|
|
@@ -22,11 +22,18 @@ def post(run_id: str) -> dict[str, Any]:
|
|
|
22
22
|
width, height = params.size_for(str(advanced.get("aspect") or "9:16"), str(advanced.get("resolution") or "720p"))
|
|
23
23
|
final = store.run_artifact(run_id, "final.mp4")
|
|
24
24
|
ffmpeg.normalize(raw, final, width=width, height=height, fps=int(advanced.get("fps") or 30))
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
# Subtitles are a sidecar SRT, never burned in (the ffmpeg build has no
|
|
26
|
+
# libass/drawtext). The run's own setting decides whether we deliver one.
|
|
27
|
+
srt_path = store.run_artifact(run_id, "subtitles.srt")
|
|
28
|
+
if str(advanced.get("subtitle") or "off") == "sidecar":
|
|
29
|
+
subtitles.write_srt(script, srt_path)
|
|
30
|
+
srt_value = store.rel_to_data(srt_path)
|
|
31
|
+
else:
|
|
32
|
+
srt_path.unlink(missing_ok=True)
|
|
33
|
+
srt_value = None
|
|
27
34
|
return {
|
|
28
35
|
"video": store.rel_to_data(final),
|
|
29
|
-
"srt":
|
|
36
|
+
"srt": srt_value,
|
|
30
37
|
"width": width,
|
|
31
38
|
"height": height,
|
|
32
39
|
"duration_s": ffmpeg.probe(final)["duration_s"],
|
|
@@ -25,7 +25,10 @@ def check(run_id: str) -> dict[str, Any]:
|
|
|
25
25
|
add("aspect", "画幅", "pass" if facts.get("width") and facts.get("height") else "fail", {"width": facts.get("width"), "height": facts.get("height")})
|
|
26
26
|
add("audio", "音轨", "pass" if facts.get("has_audio") else "fail", {"has_audio": facts.get("has_audio")})
|
|
27
27
|
srt = store.run_artifact(run_id, "subtitles.srt")
|
|
28
|
-
|
|
28
|
+
if str(advanced.get("subtitle") or "off") == "sidecar":
|
|
29
|
+
add("subtitles", "字幕", "pass" if srt.is_file() and srt.stat().st_size > 0 else "warn", {"path": store.rel_to_data(srt)})
|
|
30
|
+
else:
|
|
31
|
+
add("subtitles", "字幕", "pass", {"enabled": False, "path": None}, "未启用(按配置)")
|
|
29
32
|
storyboard = store.read_json(store.run_dir(run_id) / "artifacts" / "storyboard.json", {}) or {}
|
|
30
33
|
beats = storyboard.get("segments") or []
|
|
31
34
|
add("segments", "分镜", "pass" if beats else "warn", {"count": len(beats)})
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
This is intentionally small: create a content-generation task, poll it, download
|
|
4
4
|
the result. It is implemented against the official Ark REST shape used by the
|
|
5
|
-
existing
|
|
5
|
+
existing tooling, but is marked unverified until a real key is available.
|
|
6
6
|
"""
|
|
7
7
|
from __future__ import annotations
|
|
8
8
|
|