@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
package/engine/src/adclip/api.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"""FastAPI surface for
|
|
1
|
+
"""FastAPI surface for AdClip.
|
|
2
2
|
|
|
3
3
|
No pricing, quotes or billing endpoints exist. The first slice runs a local
|
|
4
4
|
demo pipeline so the DSH UI, storyboard, edits, personas and stitching can be
|
|
@@ -19,13 +19,16 @@ from typing import Any
|
|
|
19
19
|
from fastapi import Body, FastAPI, HTTPException, Query, Request
|
|
20
20
|
from fastapi.responses import FileResponse, JSONResponse
|
|
21
21
|
|
|
22
|
+
from . import catalog as model_catalog
|
|
22
23
|
from . import image_params, intents, llm, params, personas, settings, store
|
|
23
24
|
from .providers import discovery
|
|
24
25
|
from .media import ffmpeg
|
|
25
26
|
from .media import stitch as stitch_mod
|
|
27
|
+
from .media import subtitles
|
|
26
28
|
from .models import AssistantRequest, Run, RunStep, StitchRequest
|
|
27
29
|
from .pipeline import image_runner
|
|
28
30
|
from .pipeline import replace as segment_replace
|
|
31
|
+
from .pipeline import qa as qa_pipeline
|
|
29
32
|
from .pipeline import runner, segment
|
|
30
33
|
|
|
31
34
|
@asynccontextmanager
|
|
@@ -37,8 +40,8 @@ async def _lifespan(_app: FastAPI):
|
|
|
37
40
|
yield
|
|
38
41
|
|
|
39
42
|
|
|
40
|
-
app = FastAPI(title="
|
|
41
|
-
VERSION = "0.1.
|
|
43
|
+
app = FastAPI(title="AdClip", version="0.1.0", lifespan=_lifespan)
|
|
44
|
+
VERSION = "0.1.1"
|
|
42
45
|
|
|
43
46
|
|
|
44
47
|
def _media_type(path: Path) -> str:
|
|
@@ -71,7 +74,7 @@ def health() -> dict[str, Any]:
|
|
|
71
74
|
"ok": True,
|
|
72
75
|
"service": "adclip",
|
|
73
76
|
"version": VERSION,
|
|
74
|
-
"demo":
|
|
77
|
+
"demo": False,
|
|
75
78
|
"data": str(store.DATA),
|
|
76
79
|
"models": len(models),
|
|
77
80
|
"available_models": [row["id"] for row in models if row.get("available")],
|
|
@@ -90,8 +93,15 @@ def scenarios() -> dict[str, Any]:
|
|
|
90
93
|
|
|
91
94
|
|
|
92
95
|
@app.get("/models")
|
|
93
|
-
def models() -> dict[str, Any]:
|
|
94
|
-
|
|
96
|
+
def models(kind: str = "", capability: str = "") -> dict[str, Any]:
|
|
97
|
+
rows = model_catalog.rows()
|
|
98
|
+
if kind:
|
|
99
|
+
rows = [row for row in rows if row["kind"] == kind]
|
|
100
|
+
if capability:
|
|
101
|
+
rows = [row for row in rows if capability in (row.get("capabilities") or [])]
|
|
102
|
+
return {"models": rows, "kinds": sorted({row["kind"] for row in rows}),
|
|
103
|
+
"capabilities": {kind_name: sorted({cap for row in rows if row["kind"] == kind_name for cap in row["capabilities"]})
|
|
104
|
+
for kind_name in sorted({row["kind"] for row in rows})}}
|
|
95
105
|
|
|
96
106
|
|
|
97
107
|
@app.post("/assets/upload")
|
|
@@ -149,19 +159,19 @@ def media(path: str) -> FileResponse:
|
|
|
149
159
|
# ---------------------------------------------------------------------------
|
|
150
160
|
@app.get("/settings/models")
|
|
151
161
|
def get_settings_models() -> dict[str, Any]:
|
|
152
|
-
return {"enabled": settings.enabled_models(), "models":
|
|
162
|
+
return {"enabled": settings.enabled_models(), "models": model_catalog.rows()}
|
|
153
163
|
|
|
154
164
|
|
|
155
165
|
@app.post("/settings/models")
|
|
156
166
|
def set_settings_models(payload: dict[str, Any] = Body(...)) -> dict[str, Any]:
|
|
157
|
-
valid = {str(row["id"]) for row in
|
|
167
|
+
valid = {str(row["id"]) for row in model_catalog.rows()}
|
|
158
168
|
enabled = []
|
|
159
169
|
for value in payload.get("enabled") or []:
|
|
160
170
|
value = str(value or "").strip()
|
|
161
171
|
if value in valid and value not in enabled:
|
|
162
172
|
enabled.append(value)
|
|
163
173
|
settings.set_enabled_models(enabled)
|
|
164
|
-
return {"enabled": enabled, "models":
|
|
174
|
+
return {"enabled": enabled, "models": model_catalog.rows()}
|
|
165
175
|
|
|
166
176
|
|
|
167
177
|
@app.get("/models/discover")
|
|
@@ -263,7 +273,7 @@ def _new_run(scenario_id: str, inputs: dict[str, Any], advanced: dict[str, Any],
|
|
|
263
273
|
parent_run_id=parent.id if parent else None,
|
|
264
274
|
version=(parent.version + 1) if parent else 1,
|
|
265
275
|
changes=changes or [],
|
|
266
|
-
demo=
|
|
276
|
+
demo=False,
|
|
267
277
|
)
|
|
268
278
|
store.write_run(run)
|
|
269
279
|
runner.manager.start(run.id)
|
|
@@ -298,6 +308,7 @@ def create_image(payload: dict[str, Any] = Body(...)) -> JSONResponse:
|
|
|
298
308
|
model_id=str(payload.get("model") or ""),
|
|
299
309
|
aspect=str(payload.get("aspect") or "1:1"),
|
|
300
310
|
area=str(payload.get("area") or "2K"),
|
|
311
|
+
reference_asset_id=str(payload.get("reference_asset_id") or ""),
|
|
301
312
|
)
|
|
302
313
|
except ValueError as exc:
|
|
303
314
|
raise HTTPException(status_code=409, detail=str(exc)) from exc
|
|
@@ -448,13 +459,21 @@ def _post_derive(parent: Run, changes: list[dict[str, Any]]) -> Run:
|
|
|
448
459
|
root = store.run_dir(run_id) / "artifacts"
|
|
449
460
|
root.mkdir(parents=True, exist_ok=True)
|
|
450
461
|
src = store.run_dir(parent.id) / "artifacts"
|
|
451
|
-
for name in ("script.json", "skeleton.json", "storyboard.json", "qa.json"
|
|
462
|
+
for name in ("script.json", "skeleton.json", "storyboard.json", "qa.json"):
|
|
452
463
|
source = src / name
|
|
453
464
|
if source.is_file():
|
|
454
465
|
shutil.copy2(source, root / name)
|
|
455
466
|
advanced = copy.deepcopy(parent.advanced)
|
|
456
467
|
inputs = copy.deepcopy(parent.inputs)
|
|
457
468
|
_apply_changes(advanced, inputs, changes)
|
|
469
|
+
# The SRT follows the post-processed run's own setting, regenerated from the
|
|
470
|
+
# script that came over with the parent.
|
|
471
|
+
script = store.read_json(store.run_dir(parent.id) / "artifacts" / "script.json", {}) or {}
|
|
472
|
+
srt_target = root / "subtitles.srt"
|
|
473
|
+
if str(advanced.get("subtitle") or "off") == "sidecar":
|
|
474
|
+
subtitles.write_srt(script, srt_target)
|
|
475
|
+
else:
|
|
476
|
+
srt_target.unlink(missing_ok=True)
|
|
458
477
|
bitrate = str(advanced.get("export_bitrate") or "8M")
|
|
459
478
|
fps = int(advanced.get("fps") or 30)
|
|
460
479
|
source_video = src / "final.mp4"
|
|
@@ -471,7 +490,10 @@ def _post_derive(parent: Run, changes: list[dict[str, Any]]) -> Run:
|
|
|
471
490
|
)
|
|
472
491
|
notes = []
|
|
473
492
|
if any(str((c.get("field") or "")).startswith("post.subtitle") for c in changes):
|
|
474
|
-
|
|
493
|
+
if str(advanced.get("subtitle") or "off") == "sidecar":
|
|
494
|
+
notes.append("字幕已改为 SRT 旁挂文件(画面不烧录)")
|
|
495
|
+
else:
|
|
496
|
+
notes.append("字幕已关闭,本次不生成 SRT")
|
|
475
497
|
if any(str((c.get("field") or "")).startswith("post.music") for c in changes):
|
|
476
498
|
notes.append("音乐替换尚未接入;本次未改动音轨")
|
|
477
499
|
run = Run(
|
|
@@ -508,7 +530,13 @@ def _post_derive(parent: Run, changes: list[dict[str, Any]]) -> Run:
|
|
|
508
530
|
changes=changes,
|
|
509
531
|
)
|
|
510
532
|
store.write_run(run)
|
|
511
|
-
|
|
533
|
+
# The copied QA report described the parent's artifact set; re-check so a
|
|
534
|
+
# subtitle toggle shows up as the new run's own verdict.
|
|
535
|
+
report = qa_pipeline.check(run_id)
|
|
536
|
+
reloaded = store.read_run(run_id) or run
|
|
537
|
+
reloaded.result = {**(reloaded.result or {}), "qa": report}
|
|
538
|
+
store.write_run(reloaded)
|
|
539
|
+
return reloaded
|
|
512
540
|
|
|
513
541
|
|
|
514
542
|
@app.post("/runs/{run_id}/derive")
|
|
@@ -629,7 +657,7 @@ def stitch(payload: StitchRequest) -> dict[str, Any]:
|
|
|
629
657
|
advanced={"stitch": payload.model_dump()},
|
|
630
658
|
steps=[],
|
|
631
659
|
result={"video": record["path"], "asset_id": record["id"], "duration_s": record.get("duration_s"), "warnings": plan.get("warnings") or []},
|
|
632
|
-
demo=
|
|
660
|
+
demo=False,
|
|
633
661
|
created_at=store.now(),
|
|
634
662
|
finished_at=store.now(),
|
|
635
663
|
)
|
|
@@ -0,0 +1,341 @@
|
|
|
1
|
+
"""One catalogue for every model the plugin can drive.
|
|
2
|
+
|
|
3
|
+
Each row declares what it is (`kind`), what it can do (`capabilities`), what it
|
|
4
|
+
costs to be usable (`requires`), and how it is parameterised. Generation pages
|
|
5
|
+
filter on `capabilities`; nothing in the UI or the pipeline matches model ids.
|
|
6
|
+
|
|
7
|
+
Capability vocabulary (fixed):
|
|
8
|
+
video: text_to_video, image_to_video, reference_to_video
|
|
9
|
+
image: text_to_image, image_to_image
|
|
10
|
+
"""
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
import os
|
|
14
|
+
import time
|
|
15
|
+
from typing import Any
|
|
16
|
+
|
|
17
|
+
from . import settings
|
|
18
|
+
|
|
19
|
+
VIDEO_CAPABILITIES = ("text_to_video", "image_to_video", "reference_to_video")
|
|
20
|
+
IMAGE_CAPABILITIES = ("text_to_image", "image_to_image")
|
|
21
|
+
|
|
22
|
+
VIDEO_ROWS: list[dict[str, Any]] = [
|
|
23
|
+
{
|
|
24
|
+
"id": "ark.seedance-2.5",
|
|
25
|
+
"kind": "video",
|
|
26
|
+
"provider": "ark",
|
|
27
|
+
"model": "doubao-seedance-2-5-260628",
|
|
28
|
+
"label": "Seedance 2.5(火山方舟)",
|
|
29
|
+
"capabilities": ["text_to_video", "image_to_video", "reference_to_video"],
|
|
30
|
+
"native_audio": True,
|
|
31
|
+
"durations": [4, 5, 8, 10, 12, 15, 30],
|
|
32
|
+
"resolutions": ["480p", "720p"],
|
|
33
|
+
"aspects": ["9:16", "16:9", "1:1", "4:3", "3:4", "21:9"],
|
|
34
|
+
"max_duration_s": 30,
|
|
35
|
+
"requires": ["ARK_API_KEY"],
|
|
36
|
+
"adapter_ready": True,
|
|
37
|
+
"tags": ["中文对白首选", "原生音频"],
|
|
38
|
+
"reason": "未配置 ARK_API_KEY",
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
"id": "ark.seedance-2.0",
|
|
42
|
+
"kind": "video",
|
|
43
|
+
"provider": "ark",
|
|
44
|
+
"model": "doubao-seedance-2-0-260128",
|
|
45
|
+
"label": "Seedance 2.0(火山方舟)",
|
|
46
|
+
"capabilities": ["text_to_video", "image_to_video", "reference_to_video"],
|
|
47
|
+
"native_audio": True,
|
|
48
|
+
"durations": [4, 5, 8, 10, 12, 15],
|
|
49
|
+
"resolutions": ["480p", "720p", "1080p"],
|
|
50
|
+
"aspects": ["9:16", "16:9", "1:1", "4:3", "3:4", "21:9"],
|
|
51
|
+
"max_duration_s": 15,
|
|
52
|
+
"requires": ["ARK_API_KEY"],
|
|
53
|
+
"adapter_ready": True,
|
|
54
|
+
"tags": ["原生音频", "中文"],
|
|
55
|
+
"reason": "未配置 ARK_API_KEY",
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
"id": "ark.seedance-2.0-mini",
|
|
59
|
+
"kind": "video",
|
|
60
|
+
"provider": "ark",
|
|
61
|
+
"model": "doubao-seedance-2-0-mini-260615",
|
|
62
|
+
"label": "Seedance 2.0 Mini(火山方舟)",
|
|
63
|
+
"capabilities": ["text_to_video", "image_to_video", "reference_to_video"],
|
|
64
|
+
"native_audio": True,
|
|
65
|
+
"durations": [4, 5, 8, 10, 12, 15],
|
|
66
|
+
"resolutions": ["480p", "720p", "1080p"],
|
|
67
|
+
"aspects": ["9:16", "16:9", "1:1", "4:3", "3:4", "21:9"],
|
|
68
|
+
"max_duration_s": 15,
|
|
69
|
+
"requires": ["ARK_API_KEY"],
|
|
70
|
+
"adapter_ready": True,
|
|
71
|
+
"tags": ["Mini", "原生音频", "已实测"],
|
|
72
|
+
"reason": "未配置 ARK_API_KEY",
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
"id": "ark.seedance-2.0-fast",
|
|
76
|
+
"kind": "video",
|
|
77
|
+
"provider": "ark",
|
|
78
|
+
"model": "doubao-seedance-2-0-fast-260128",
|
|
79
|
+
"label": "Seedance 2.0 Fast(火山方舟)",
|
|
80
|
+
"capabilities": ["text_to_video", "image_to_video", "reference_to_video"],
|
|
81
|
+
"native_audio": True,
|
|
82
|
+
"durations": [4, 5, 8, 10, 12, 15],
|
|
83
|
+
"resolutions": ["480p", "720p", "1080p"],
|
|
84
|
+
"aspects": ["9:16", "16:9", "1:1", "4:3", "3:4", "21:9"],
|
|
85
|
+
"max_duration_s": 15,
|
|
86
|
+
"requires": ["ARK_API_KEY"],
|
|
87
|
+
"adapter_ready": True,
|
|
88
|
+
"tags": ["Fast", "原生音频", "已实测"],
|
|
89
|
+
"reason": "未配置 ARK_API_KEY",
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
"id": "kling.v3",
|
|
93
|
+
"kind": "video",
|
|
94
|
+
"provider": "kling",
|
|
95
|
+
"model": "kling-v3",
|
|
96
|
+
"label": "Kling v3(可灵)",
|
|
97
|
+
"capabilities": ["text_to_video", "image_to_video", "reference_to_video"],
|
|
98
|
+
"native_audio": True,
|
|
99
|
+
"durations": [3, 5, 8, 10, 12, 15],
|
|
100
|
+
"resolutions": ["720p", "1080p"],
|
|
101
|
+
"aspects": ["9:16", "16:9", "1:1"],
|
|
102
|
+
"max_duration_s": 15,
|
|
103
|
+
"requires": ["KLING_API_KEY"],
|
|
104
|
+
"adapter_ready": True,
|
|
105
|
+
"tags": ["1080p 候选", "原生音频"],
|
|
106
|
+
"reason": "未配置 KLING_API_KEY",
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
"id": "minimax.hailuo-2.3-fast",
|
|
110
|
+
"kind": "video",
|
|
111
|
+
"provider": "minimax",
|
|
112
|
+
"model": "MiniMax-Hailuo-2.3-Fast",
|
|
113
|
+
"label": "MiniMax Hailuo 2.3 Fast(图生视频)",
|
|
114
|
+
"capabilities": ["image_to_video"],
|
|
115
|
+
"native_audio": False,
|
|
116
|
+
"durations": [6, 10],
|
|
117
|
+
"resolutions": ["768P", "1080P"],
|
|
118
|
+
"aspects": ["9:16", "16:9", "1:1", "4:3", "3:4", "21:9"],
|
|
119
|
+
"max_duration_s": 10,
|
|
120
|
+
"requires": ["MINIMAX_API_KEY"],
|
|
121
|
+
"adapter_ready": True,
|
|
122
|
+
"tags": ["图生视频已验证", "无原生音频"],
|
|
123
|
+
"reason": "未配置 MINIMAX_API_KEY",
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
"id": "minimax.h3",
|
|
127
|
+
"kind": "video",
|
|
128
|
+
"provider": "minimax",
|
|
129
|
+
"model": "MiniMax-H3",
|
|
130
|
+
"label": "MiniMax H3(2K · 原生对白)",
|
|
131
|
+
"capabilities": ["text_to_video", "image_to_video"],
|
|
132
|
+
"native_audio": True,
|
|
133
|
+
"durations": [4, 5, 6, 8, 10, 12, 15],
|
|
134
|
+
"resolutions": ["2K"],
|
|
135
|
+
"aspects": ["9:16", "16:9", "1:1", "4:3", "3:4", "21:9"],
|
|
136
|
+
"max_duration_s": 15,
|
|
137
|
+
"requires": ["MINIMAX_API_KEY"],
|
|
138
|
+
"adapter_ready": True,
|
|
139
|
+
"tags": ["2K", "中文原生对白已验证"],
|
|
140
|
+
"reason": "未配置 MINIMAX_API_KEY",
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
"id": "volcengine.jimeng-3.0",
|
|
144
|
+
"kind": "video",
|
|
145
|
+
"provider": "volcengine",
|
|
146
|
+
"model": "jimeng_ti2v_v30_pro",
|
|
147
|
+
"label": "火山引擎即梦 3.0 Pro",
|
|
148
|
+
"capabilities": ["text_to_video", "image_to_video"],
|
|
149
|
+
"native_audio": False,
|
|
150
|
+
"durations": [5, 10],
|
|
151
|
+
"resolutions": ["720p", "1080p"],
|
|
152
|
+
"aspects": ["9:16", "16:9", "1:1", "4:3", "3:4", "21:9"],
|
|
153
|
+
"max_duration_s": 10,
|
|
154
|
+
"requires": ["VOLC_ACCESSKEY", "VOLC_SECRETKEY"],
|
|
155
|
+
"adapter_ready": False,
|
|
156
|
+
"tags": ["无原生对白"],
|
|
157
|
+
"reason": "适配器未接入",
|
|
158
|
+
},
|
|
159
|
+
{
|
|
160
|
+
"id": "veo.3.1",
|
|
161
|
+
"kind": "video",
|
|
162
|
+
"provider": "fal",
|
|
163
|
+
"model": "veo-3.1-generate-001",
|
|
164
|
+
"label": "Veo 3.1(可选)",
|
|
165
|
+
"capabilities": ["text_to_video", "image_to_video"],
|
|
166
|
+
"native_audio": True,
|
|
167
|
+
"durations": [8],
|
|
168
|
+
"resolutions": ["720p", "1080p"],
|
|
169
|
+
"aspects": ["9:16", "16:9"],
|
|
170
|
+
"max_duration_s": 8,
|
|
171
|
+
"requires": ["FAL_KEY"],
|
|
172
|
+
"adapter_ready": False,
|
|
173
|
+
"tags": ["海外", "原生音频"],
|
|
174
|
+
"reason": "适配器未接入",
|
|
175
|
+
},
|
|
176
|
+
{
|
|
177
|
+
"id": "sora.2",
|
|
178
|
+
"kind": "video",
|
|
179
|
+
"provider": "fal",
|
|
180
|
+
"model": "sora-2",
|
|
181
|
+
"label": "Sora 2(可选)",
|
|
182
|
+
"capabilities": ["text_to_video", "image_to_video"],
|
|
183
|
+
"native_audio": True,
|
|
184
|
+
"durations": [10, 15],
|
|
185
|
+
"resolutions": ["720p"],
|
|
186
|
+
"aspects": ["9:16", "16:9"],
|
|
187
|
+
"max_duration_s": 15,
|
|
188
|
+
"requires": ["FAL_KEY", "OPENAI_API_KEY"],
|
|
189
|
+
"adapter_ready": False,
|
|
190
|
+
"tags": ["海外", "原生音频"],
|
|
191
|
+
"reason": "适配器未接入",
|
|
192
|
+
},
|
|
193
|
+
]
|
|
194
|
+
|
|
195
|
+
IMAGE_ROWS: list[dict[str, Any]] = [
|
|
196
|
+
{
|
|
197
|
+
"id": "minimax.h3-image",
|
|
198
|
+
"kind": "image",
|
|
199
|
+
"provider": "minimax",
|
|
200
|
+
"model": "MiniMax-H3-Image",
|
|
201
|
+
"label": "MiniMax H3 Image",
|
|
202
|
+
"capabilities": ["text_to_image"],
|
|
203
|
+
"aspects": ["1:1", "3:4", "4:3", "9:16", "16:9"],
|
|
204
|
+
"areas": ["1K", "2K", "4K"],
|
|
205
|
+
"default_area": "2K",
|
|
206
|
+
"requires": ["MINIMAX_API_KEY"],
|
|
207
|
+
"adapter_ready": True,
|
|
208
|
+
"tags": ["文生图"],
|
|
209
|
+
"reason": "未配置 MINIMAX_API_KEY",
|
|
210
|
+
},
|
|
211
|
+
{
|
|
212
|
+
"id": "minimax.h3-image-highspeed",
|
|
213
|
+
"kind": "image",
|
|
214
|
+
"provider": "minimax",
|
|
215
|
+
"model": "MiniMax-H3-Image-Highspeed",
|
|
216
|
+
"label": "MiniMax H3 Image Highspeed",
|
|
217
|
+
"capabilities": ["text_to_image"],
|
|
218
|
+
"aspects": ["1:1", "3:4", "4:3", "9:16", "16:9"],
|
|
219
|
+
"areas": ["1K", "2K", "4K"],
|
|
220
|
+
"default_area": "2K",
|
|
221
|
+
"requires": ["MINIMAX_API_KEY"],
|
|
222
|
+
"adapter_ready": True,
|
|
223
|
+
"tags": ["文生图", "快速"],
|
|
224
|
+
"reason": "未配置 MINIMAX_API_KEY",
|
|
225
|
+
},
|
|
226
|
+
{
|
|
227
|
+
"id": "ark.seedream-4.0",
|
|
228
|
+
"kind": "image",
|
|
229
|
+
"provider": "ark",
|
|
230
|
+
"model": "doubao-seedream-4-0-20260415",
|
|
231
|
+
"label": "Doubao-Seedream 4.0(火山方舟)",
|
|
232
|
+
"capabilities": ["text_to_image", "image_to_image"],
|
|
233
|
+
"aspects": ["1:1", "4:3", "3:4", "16:9", "9:16"],
|
|
234
|
+
"areas": ["1K", "2K", "4K"],
|
|
235
|
+
"default_area": "2K",
|
|
236
|
+
"requires": ["ARK_API_KEY"],
|
|
237
|
+
"adapter_ready": True,
|
|
238
|
+
"tags": ["4K", "参考图生图已验证", "中文提示"],
|
|
239
|
+
"reason": "未配置 ARK_API_KEY",
|
|
240
|
+
},
|
|
241
|
+
]
|
|
242
|
+
|
|
243
|
+
TEST_ROW: dict[str, Any] = {
|
|
244
|
+
"id": "test.synthetic",
|
|
245
|
+
"kind": "video",
|
|
246
|
+
"provider": "synthetic",
|
|
247
|
+
"model": "synthetic",
|
|
248
|
+
"label": "Synthetic(测试)",
|
|
249
|
+
"capabilities": list(VIDEO_CAPABILITIES),
|
|
250
|
+
"native_audio": True,
|
|
251
|
+
"durations": [4, 5, 6, 8, 10, 12, 15, 30],
|
|
252
|
+
"resolutions": ["480p", "720p", "1080p"],
|
|
253
|
+
"aspects": ["9:16", "16:9", "1:1", "4:3", "3:4", "21:9"],
|
|
254
|
+
"max_duration_s": 30,
|
|
255
|
+
"requires": [],
|
|
256
|
+
"adapter_ready": True,
|
|
257
|
+
"tags": ["测试"],
|
|
258
|
+
"reason": "",
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
def test_mode() -> bool:
|
|
263
|
+
return os.environ.get("ADCLIP_TEST_MODE", "").strip() == "1"
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
def base_rows() -> list[dict[str, Any]]:
|
|
267
|
+
rows = [*VIDEO_ROWS, *IMAGE_ROWS]
|
|
268
|
+
if test_mode():
|
|
269
|
+
rows.append(TEST_ROW)
|
|
270
|
+
return rows
|
|
271
|
+
|
|
272
|
+
|
|
273
|
+
def evaluate(row: dict[str, Any], enabled_ids: list[str] | None = None, kind_has_ids: dict[str, bool] | None = None) -> dict[str, Any]:
|
|
274
|
+
"""Live view of one row: keys present, usable, enabled, short reason.
|
|
275
|
+
|
|
276
|
+
`enabled_ids` is the saved preference list; `None` means "no preference file
|
|
277
|
+
yet". A kind with no saved ids at all stays enabled, so a prefs file written
|
|
278
|
+
before that kind existed does not hide it.
|
|
279
|
+
"""
|
|
280
|
+
item = dict(row)
|
|
281
|
+
item.setdefault("capabilities", [])
|
|
282
|
+
if item["kind"] == "video":
|
|
283
|
+
item["modes"] = list(item["capabilities"])
|
|
284
|
+
requires = [str(name) for name in item.get("requires") or []]
|
|
285
|
+
item["key_present"] = all(bool(os.environ.get(name, "").strip()) for name in requires)
|
|
286
|
+
item["available"] = bool(item.get("adapter_ready", True)) and (not requires or item["key_present"])
|
|
287
|
+
if not item.get("adapter_ready", True):
|
|
288
|
+
item["reason"] = "适配器未接入"
|
|
289
|
+
elif requires and not item["key_present"]:
|
|
290
|
+
item["reason"] = "未配置 " + " / ".join(requires)
|
|
291
|
+
else:
|
|
292
|
+
item["reason"] = str(item.get("reason") or "")
|
|
293
|
+
if enabled_ids is None:
|
|
294
|
+
item["enabled"] = True
|
|
295
|
+
elif kind_has_ids is not None and not kind_has_ids.get(item["kind"], False):
|
|
296
|
+
item["enabled"] = True
|
|
297
|
+
else:
|
|
298
|
+
item["enabled"] = item["id"] in enabled_ids
|
|
299
|
+
item["checked_at"] = time.strftime("%Y-%m-%dT%H:%M:%S%z")
|
|
300
|
+
return item
|
|
301
|
+
|
|
302
|
+
|
|
303
|
+
def rows() -> list[dict[str, Any]]:
|
|
304
|
+
"""Every model with live availability and enablement."""
|
|
305
|
+
enabled_ids = settings.enabled_models()
|
|
306
|
+
base = base_rows()
|
|
307
|
+
kind_has_ids = {
|
|
308
|
+
kind: any(row["id"] in (enabled_ids or []) for row in base if row["kind"] == kind)
|
|
309
|
+
for kind in {row["kind"] for row in base}
|
|
310
|
+
}
|
|
311
|
+
return [evaluate(row, enabled_ids, kind_has_ids) for row in base]
|
|
312
|
+
|
|
313
|
+
|
|
314
|
+
def for_kind(kind: str) -> list[dict[str, Any]]:
|
|
315
|
+
return [row for row in rows() if row["kind"] == kind]
|
|
316
|
+
|
|
317
|
+
|
|
318
|
+
def get(model_id: str) -> dict[str, Any] | None:
|
|
319
|
+
for row in rows():
|
|
320
|
+
if row["id"] == model_id:
|
|
321
|
+
return row
|
|
322
|
+
return None
|
|
323
|
+
|
|
324
|
+
|
|
325
|
+
def with_capability(capability: str, *, kind: str = "", usable: bool = False) -> list[dict[str, Any]]:
|
|
326
|
+
rows_ = [row for row in rows() if capability in row["capabilities"]]
|
|
327
|
+
if kind:
|
|
328
|
+
rows_ = [row for row in rows_ if row["kind"] == kind]
|
|
329
|
+
if usable:
|
|
330
|
+
rows_ = [row for row in rows_ if row["available"] and row["enabled"]]
|
|
331
|
+
return rows_
|
|
332
|
+
|
|
333
|
+
|
|
334
|
+
def default_model(kind: str, capability: str = "") -> str:
|
|
335
|
+
for row in rows():
|
|
336
|
+
if row["kind"] != kind or not row["available"] or not row["enabled"]:
|
|
337
|
+
continue
|
|
338
|
+
if capability and capability not in row["capabilities"]:
|
|
339
|
+
continue
|
|
340
|
+
return row["id"]
|
|
341
|
+
return ""
|
|
@@ -1,64 +1,45 @@
|
|
|
1
|
-
"""Image-
|
|
1
|
+
"""Image-model view over the shared catalogue.
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
Image rows live in `catalog.py` next to the video rows; this module keeps the
|
|
4
|
+
image-shaped helpers the image pipeline imports.
|
|
5
5
|
"""
|
|
6
6
|
from __future__ import annotations
|
|
7
7
|
|
|
8
|
-
import os
|
|
9
|
-
import time
|
|
10
8
|
from typing import Any
|
|
11
9
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
"label": "MiniMax H3 Image",
|
|
18
|
-
"aspects": ["1:1", "3:4", "4:3", "9:16", "16:9"],
|
|
19
|
-
"areas": ["1K", "2K", "4K"],
|
|
20
|
-
"default_area": "2K",
|
|
21
|
-
"requires": ["MINIMAX_API_KEY"],
|
|
22
|
-
"available": False,
|
|
23
|
-
"reason": "配置 MINIMAX_API_KEY 后可用",
|
|
24
|
-
"tags": ["文生图", "MiniMax"],
|
|
25
|
-
},
|
|
26
|
-
{
|
|
27
|
-
"id": "minimax.h3-image-highspeed",
|
|
28
|
-
"provider": "minimax",
|
|
29
|
-
"model": "MiniMax-H3-Image-Highspeed",
|
|
30
|
-
"label": "MiniMax H3 Image Highspeed",
|
|
31
|
-
"aspects": ["1:1", "3:4", "4:3", "9:16", "16:9"],
|
|
32
|
-
"areas": ["1K", "2K", "4K"],
|
|
33
|
-
"default_area": "2K",
|
|
34
|
-
"requires": ["MINIMAX_API_KEY"],
|
|
35
|
-
"available": False,
|
|
36
|
-
"reason": "配置 MINIMAX_API_KEY 后可用",
|
|
37
|
-
"tags": ["文生图", "快速"],
|
|
38
|
-
},
|
|
39
|
-
]
|
|
10
|
+
from . import catalog as model_catalog
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def catalog_rows() -> list[dict[str, Any]]:
|
|
14
|
+
return model_catalog.for_kind("image")
|
|
40
15
|
|
|
41
16
|
|
|
42
17
|
def catalog() -> list[dict[str, Any]]:
|
|
43
|
-
|
|
44
|
-
rows = []
|
|
45
|
-
for row in IMAGE_MODELS:
|
|
46
|
-
item = dict(row)
|
|
47
|
-
item["available"] = available
|
|
48
|
-
if available:
|
|
49
|
-
item["reason"] = "MiniMax key 已配置;生成时按账号权限为准"
|
|
50
|
-
item["checked_at"] = time.strftime("%Y-%m-%dT%H:%M:%S%z")
|
|
51
|
-
rows.append(item)
|
|
52
|
-
return rows
|
|
18
|
+
return model_catalog.for_kind("image")
|
|
53
19
|
|
|
54
20
|
|
|
55
21
|
def get_model(model_id: str) -> dict[str, Any] | None:
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
return row
|
|
59
|
-
return None
|
|
22
|
+
row = model_catalog.get(model_id)
|
|
23
|
+
return row if row and row["kind"] == "image" else None
|
|
60
24
|
|
|
61
25
|
|
|
62
26
|
def default_model() -> str:
|
|
63
|
-
|
|
64
|
-
|
|
27
|
+
return model_catalog.default_model("image", "text_to_image")
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def size_for(area: str, aspect: str) -> str:
|
|
31
|
+
"""Pixel size for providers that take explicit dimensions, not presets.
|
|
32
|
+
|
|
33
|
+
The short edge follows the area (1K/2K/4K); the other edge keeps the aspect
|
|
34
|
+
ratio and lands on a multiple of 16, which every image API we target accepts.
|
|
35
|
+
"""
|
|
36
|
+
short = {"1K": 1024, "2K": 2048, "4K": 4096}.get(str(area).upper(), 2048)
|
|
37
|
+
ratios = {"1:1": (1, 1), "4:3": (4, 3), "3:4": (3, 4), "16:9": (16, 9), "9:16": (9, 16)}
|
|
38
|
+
width_units, height_units = ratios.get(aspect, (1, 1))
|
|
39
|
+
if width_units >= height_units:
|
|
40
|
+
width = short
|
|
41
|
+
height = round(short * height_units / width_units / 16) * 16
|
|
42
|
+
else:
|
|
43
|
+
height = short
|
|
44
|
+
width = round(short * width_units / height_units / 16) * 16
|
|
45
|
+
return f"{max(16, width)}x{max(16, height)}"
|
|
@@ -8,6 +8,7 @@ from __future__ import annotations
|
|
|
8
8
|
import re
|
|
9
9
|
from typing import Any
|
|
10
10
|
|
|
11
|
+
from . import catalog
|
|
11
12
|
from .models import AssistantRequest
|
|
12
13
|
|
|
13
14
|
|
|
@@ -65,15 +66,21 @@ def analyze(req: AssistantRequest) -> dict[str, Any]:
|
|
|
65
66
|
changes.append(_change("advanced.duration", advanced.get("duration"), duration, "generate", "时长"))
|
|
66
67
|
advanced["duration"] = duration
|
|
67
68
|
|
|
68
|
-
# model
|
|
69
|
+
# model: a vendor keyword selects that vendor's first usable model, never a
|
|
70
|
+
# hardcoded id, so new models from the same provider are picked up.
|
|
71
|
+
vendor = None
|
|
69
72
|
if re.search(r"可灵|kling", text, re.I):
|
|
70
|
-
|
|
71
|
-
elif re.search(r"seedance
|
|
72
|
-
|
|
73
|
-
elif re.search(r"minimax
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
73
|
+
vendor = "kling"
|
|
74
|
+
elif re.search(r"seedance|方舟|ark", text, re.I):
|
|
75
|
+
vendor = "ark"
|
|
76
|
+
elif re.search(r"minimax|海螺|hailuo", text, re.I):
|
|
77
|
+
vendor = "minimax"
|
|
78
|
+
if vendor:
|
|
79
|
+
candidate = next((row for row in catalog.rows()
|
|
80
|
+
if row["kind"] == "video" and row["provider"] == vendor
|
|
81
|
+
and row.get("available") and row.get("enabled")), None)
|
|
82
|
+
if candidate is not None:
|
|
83
|
+
changes.append(_change("advanced.model", advanced.get("model"), candidate["id"], "generate", "模型"))
|
|
77
84
|
|
|
78
85
|
# generation mode
|
|
79
86
|
if re.search(r"精细|逐镜|分段", text):
|
|
@@ -131,12 +138,24 @@ def analyze(req: AssistantRequest) -> dict[str, Any]:
|
|
|
131
138
|
changes.append(_change("persona.ethnicity", persona.get("ethnicity"), ethnicity, "generate", "模特族裔"))
|
|
132
139
|
persona["ethnicity"] = ethnicity
|
|
133
140
|
|
|
134
|
-
# post-only
|
|
135
|
-
|
|
141
|
+
# post-only: subtitle delivery is a switch, so judge on/off before the size words
|
|
142
|
+
subtitle_toggled = False
|
|
143
|
+
current_subtitle = str(advanced.get("subtitle") or "off")
|
|
144
|
+
if re.search(r"字幕", text) and re.search(r"关闭|关掉|不要|不用|去掉|取消|不启用|别加|无字幕", text):
|
|
145
|
+
subtitle_toggled = True
|
|
146
|
+
if current_subtitle != "off":
|
|
147
|
+
changes.append(_change("post.subtitle", current_subtitle, "off", "post", "字幕"))
|
|
148
|
+
advanced["subtitle"] = "off"
|
|
149
|
+
elif re.search(r"字幕", text) and re.search(r"开启|打开|加上|加个|要字幕|带字幕|加字幕|启用", text):
|
|
150
|
+
subtitle_toggled = True
|
|
151
|
+
if current_subtitle != "sidecar":
|
|
152
|
+
changes.append(_change("post.subtitle", current_subtitle, "sidecar", "post", "字幕"))
|
|
153
|
+
advanced["subtitle"] = "sidecar"
|
|
154
|
+
if not subtitle_toggled and re.search(r"字幕", text) and re.search(r"大|放大", text):
|
|
136
155
|
size = int(post.get("subtitle_size") or 32) + 4
|
|
137
156
|
changes.append(_change("post.subtitle_size", post.get("subtitle_size"), size, "post", "字幕字号"))
|
|
138
157
|
post["subtitle_size"] = size
|
|
139
|
-
if re.search(r"字幕", text) and re.search(r"小", text):
|
|
158
|
+
if not subtitle_toggled and re.search(r"字幕", text) and re.search(r"小", text):
|
|
140
159
|
size = max(16, int(post.get("subtitle_size") or 32) - 4)
|
|
141
160
|
changes.append(_change("post.subtitle_size", post.get("subtitle_size"), size, "post", "字幕字号"))
|
|
142
161
|
post["subtitle_size"] = size
|