add first-last-frame and reference-image mode in video generation
| | |
| | | "vlm_model", |
| | | "image_t2i_model", |
| | | "image_it2i_model", |
| | | "video_model", |
| | | ) |
| | | |
| | | VIDEO_MODE_TO_MODEL_FIELD = { |
| | | "first_frame": "video_first_frame_model", |
| | | "start_end_frame": "video_start_end_model", |
| | | "reference": "video_reference_model", |
| | | } |
| | | |
| | | |
| | | def _active_video_model(values: dict) -> str: |
| | | mode = values.get("video_generation_mode") or "first_frame" |
| | | model_field = VIDEO_MODE_TO_MODEL_FIELD.get(mode, "video_first_frame_model") |
| | | default_attr = { |
| | | "video_first_frame_model": "VIDEO_FIRST_FRAME_MODEL", |
| | | "video_start_end_model": "VIDEO_START_END_MODEL", |
| | | "video_reference_model": "VIDEO_REFERENCE_MODEL", |
| | | }.get(model_field, "VIDEO_MODEL") |
| | | # Legacy session compatibility: fall back to the old single video_model field when mode-specific fields are absent. |
| | | return values.get(model_field) or values.get("video_model") or getattr(settings, default_attr, "") or "" |
| | | |
| | | |
| | | def _require_model_fields(values: dict) -> None: |
| | | missing = [field for field in REQUIRED_MODEL_FIELDS if not values.get(field)] |
| | | if not _active_video_model(values): |
| | | missing.append("video_model") |
| | | if missing: |
| | | raise HTTPException( |
| | | status_code=400, |
| | |
| | | "vlm_model": req.vlm_model, |
| | | "image_t2i_model": req.image_t2i_model, |
| | | "image_it2i_model": req.image_it2i_model, |
| | | # Legacy request/session compatibility: clients created before the split only send video_model. |
| | | "video_first_frame_model": req.video_first_frame_model or req.video_model or getattr(settings, "VIDEO_FIRST_FRAME_MODEL", ""), |
| | | "video_start_end_model": req.video_start_end_model or getattr(settings, "VIDEO_START_END_MODEL", ""), |
| | | "video_reference_model": req.video_reference_model or getattr(settings, "VIDEO_REFERENCE_MODEL", ""), |
| | | "video_generation_mode": req.video_generation_mode or getattr(settings, "VIDEO_GENERATION_MODE", "first_frame"), |
| | | "video_model": req.video_model, |
| | | "enable_concurrency": req.enable_concurrency if req.enable_concurrency is not None else True, |
| | | "web_search": req.web_search if req.web_search is not None else False, |
| | | "episodes": req.episodes if req.episodes is not None else 4, |
| | | } |
| | | meta["video_model"] = _active_video_model(meta) |
| | | session = workflow_engine.create_session(session_id, meta) |
| | | |
| | | return { |
| | |
| | | "vlm_model": meta["vlm_model"], |
| | | "image_t2i_model": meta["image_t2i_model"], |
| | | "image_it2i_model": meta["image_it2i_model"], |
| | | "video_first_frame_model": meta["video_first_frame_model"], |
| | | "video_start_end_model": meta["video_start_end_model"], |
| | | "video_reference_model": meta["video_reference_model"], |
| | | "video_generation_mode": meta["video_generation_mode"], |
| | | "video_model": meta["video_model"], |
| | | "episodes": meta["episodes"], |
| | | "video_ratio": meta["video_ratio"], |
| | |
| | | @router.patch("/api/project/{session_id}/models") |
| | | async def update_models(session_id: str, request: Request): |
| | | body = await request.json() |
| | | allowed_keys = ("llm_model", "vlm_model", "image_t2i_model", "image_it2i_model", "video_model", "video_ratio", "video_resolution", "style", "enable_concurrency") |
| | | allowed_keys = ( |
| | | "llm_model", |
| | | "vlm_model", |
| | | "image_t2i_model", |
| | | "image_it2i_model", |
| | | "video_model", |
| | | "video_first_frame_model", |
| | | "video_start_end_model", |
| | | "video_reference_model", |
| | | "video_generation_mode", |
| | | "video_ratio", |
| | | "video_resolution", |
| | | "style", |
| | | "enable_concurrency", |
| | | ) |
| | | try: |
| | | return workflow_engine.update_session_meta(session_id, body if isinstance(body, dict) else {}, allowed_keys) |
| | | except KeyError: |
| | |
| | | image_t2i_model: Optional[str] = None |
| | | image_it2i_model: Optional[str] = None |
| | | video_model: Optional[str] = None |
| | | video_first_frame_model: Optional[str] = None |
| | | video_start_end_model: Optional[str] = None |
| | | video_reference_model: Optional[str] = None |
| | | video_generation_mode: Optional[str] = "first_frame" |
| | | enable_concurrency: Optional[bool] = True |
| | | web_search: Optional[bool] = False |
| | | episodes: Optional[int] = None |
| | |
| | | "image_it2i": "doubao-seedream-5-0-260128", |
| | | "image_t2i": "doubao-seedream-5-0-260128", |
| | | "video": "wan2.7-i2v", |
| | | "eval": "qwen3.5-plus", |
| | | "video_first_frame": "wan2.7-i2v", |
| | | "video_start_end": "wan2.7-i2v", |
| | | "video_reference": "wan2.7-r2v", |
| | | }, |
| | | "generation": { |
| | | "style": "realistic", |
| | | "video_ratio": "16:9", |
| | | "video_resolution": "720P", |
| | | "video_generation_mode": "first_frame", |
| | | }, |
| | | } |
| | | |
| | |
| | | legacy_models = data.get("models", {}) if isinstance(data, dict) else {} |
| | | if isinstance(legacy_models, dict): |
| | | for legacy_key in ("style", "video_ratio", "video_resolution"): |
| | | # Legacy config compatibility: older config.yaml stored generation settings under models.*. |
| | | if legacy_key in legacy_models and not _get(data, f"generation.{legacy_key}"): |
| | | clean.setdefault("generation", {})[legacy_key] = legacy_models[legacy_key] |
| | | clean["models"].pop(legacy_key, None) |
| | | if legacy_models.get("video") and not any( |
| | | legacy_models.get(key) for key in ("video_first_frame", "video_start_end", "video_reference") |
| | | ): |
| | | # Legacy config compatibility: older configs had one models.video instead of mode-specific video models. |
| | | clean["models"]["video_first_frame"] = legacy_models["video"] |
| | | # Legacy config compatibility: models.eval was never used by runtime agents; keep it out after load. |
| | | clean["models"].pop("eval", None) |
| | | |
| | | server = clean["server"] |
| | | server["host"] = str(server.get("host") or DEFAULT_CONFIG["server"]["host"]) |
| | |
| | | IMAGE_IT2I_MODEL = _get(CONFIG, "models.image_it2i") |
| | | IMAGE_T2I_MODEL = _get(CONFIG, "models.image_t2i") |
| | | VIDEO_MODEL = _get(CONFIG, "models.video") |
| | | VIDEO_FIRST_FRAME_MODEL = _get(CONFIG, "models.video_first_frame") |
| | | VIDEO_START_END_MODEL = _get(CONFIG, "models.video_start_end") |
| | | VIDEO_REFERENCE_MODEL = _get(CONFIG, "models.video_reference") |
| | | VIDEO_RATIO = _get(CONFIG, "generation.video_ratio") |
| | | VIDEO_RESOLUTION = _get(CONFIG, "generation.video_resolution") |
| | | VIDEO_GENERATION_MODE = _get(CONFIG, "generation.video_generation_mode") |
| | | STYLE = _get(CONFIG, "generation.style") |
| | | EVAL_MODEL = _get(CONFIG, "models.eval") |
| | | |
| | | BASE_DIR = str(BASE_DIR) |
| | | CODE_DIR = os.path.join(BASE_DIR, "code") |
| | |
| | | cls.IMAGE_IT2I_MODEL = _get(clean, "models.image_it2i") |
| | | cls.IMAGE_T2I_MODEL = _get(clean, "models.image_t2i") |
| | | cls.VIDEO_MODEL = _get(clean, "models.video") |
| | | cls.VIDEO_FIRST_FRAME_MODEL = _get(clean, "models.video_first_frame") |
| | | cls.VIDEO_START_END_MODEL = _get(clean, "models.video_start_end") |
| | | cls.VIDEO_REFERENCE_MODEL = _get(clean, "models.video_reference") |
| | | cls.VIDEO_RATIO = _get(clean, "generation.video_ratio") |
| | | cls.VIDEO_RESOLUTION = _get(clean, "generation.video_resolution") |
| | | cls.VIDEO_GENERATION_MODE = _get(clean, "generation.video_generation_mode") |
| | | cls.STYLE = _get(clean, "generation.style") |
| | | cls.EVAL_MODEL = _get(clean, "models.eval") |
| | | return cls.as_dict() |
| | | |
| | | @classmethod |
| | |
| | | image_it2i: doubao-seedream-5-0-260128 |
| | | image_t2i: doubao-seedream-5-0-260128 |
| | | video: wan2.7-i2v |
| | | eval: qwen3.5-plus |
| | | video_first_frame: wan2.7-i2v |
| | | video_start_end: wan2.7-i2v |
| | | video_reference: wan2.7-r2v |
| | | generation: |
| | | style: realistic |
| | | video_ratio: '16:9' |
| | | video_resolution: 720P |
| | | video_generation_mode: first_frame |
| | |
| | | "idea", "user_textbox_input", "style", "video_ratio", "video_resolution", |
| | | "llm_model", "vlm_model", |
| | | "image_t2i_model", "image_it2i_model", "video_model", |
| | | "video_first_frame_model", "video_start_end_model", "video_reference_model", |
| | | "video_generation_mode", |
| | | "video_style", "expand_idea", "enable_concurrency", "web_search", "episodes" |
| | | ] |
| | | |
| | |
| | | # ─── 视频生成 ─── |
| | | |
| | | def _generate_one(self, sid: str, segment_id: str, prompt: str, |
| | | img_path: str, video_model: str, |
| | | img_path: Optional[str], video_model: str, |
| | | duration: int = 10, sound: str = "", |
| | | shot_type: str = "multi", |
| | | video_ratio: str = "16:9", |
| | | video_resolution: str = "720P") -> tuple: |
| | | video_resolution: str = "720P", |
| | | video_generation_mode: str = "first_frame", |
| | | last_image_path: Optional[str] = None, |
| | | reference_image_paths: Optional[List[str]] = None) -> tuple: |
| | | """生成单个视频片段,返回 (segment_id, path_or_None)""" |
| | | if self.cancellation_check and self.cancellation_check(): |
| | | logger.info(f"VideoDirectorAgent: {segment_id} 跳过(用户取消)") |
| | | return segment_id, None |
| | | |
| | | if not os.path.exists(img_path): |
| | | reference_image_paths = reference_image_paths or [] |
| | | if video_generation_mode == "reference": |
| | | missing_refs = [path for path in reference_image_paths if not os.path.exists(path)] |
| | | if not reference_image_paths or missing_refs: |
| | | logger.warning("Reference images missing for %s: %s", segment_id, missing_refs or reference_image_paths) |
| | | return segment_id, None |
| | | elif not img_path or not os.path.exists(img_path): |
| | | logger.warning(f"Image missing for {segment_id}: {img_path}") |
| | | return segment_id, None |
| | | |
| | |
| | | shot_type=shot_type, |
| | | video_ratio=video_ratio, |
| | | resolution=video_resolution, |
| | | last_image_path=last_image_path if video_generation_mode == "start_end_frame" else None, |
| | | reference_image_paths=reference_image_paths if video_generation_mode == "reference" else None, |
| | | ) |
| | | return segment_id, save_path |
| | | except Exception as e: |
| | |
| | | |
| | | # 3. 默认路径 |
| | | return os.path.abspath(os.path.join('code/result/image', str(sid), 'Scenes', f"{segment_id}.jpg")) |
| | | |
| | | def _get_next_reference_image(self, sid: str, segment_index: int, segments: list, scene_map: dict) -> Optional[str]: |
| | | """首尾帧模式下,优先用下一个片段参考图作为尾帧。""" |
| | | if segment_index + 1 >= len(segments): |
| | | return None |
| | | next_segment_id = segments[segment_index + 1].get("segment_id") |
| | | if not next_segment_id: |
| | | return None |
| | | path = self._get_reference_image(sid, next_segment_id, scene_map) |
| | | return path if path and os.path.exists(path) else None |
| | | |
| | | @staticmethod |
| | | def _asset_selected_path(asset: dict) -> str: |
| | | selected = asset.get("selected") or "" |
| | | if selected and os.path.exists(selected): |
| | | return selected |
| | | # Legacy session compatibility: some old artifacts only have versions and no selected field. |
| | | for path in reversed(asset.get("versions") or []): |
| | | if path and os.path.exists(path): |
| | | return path |
| | | return "" |
| | | |
| | | @staticmethod |
| | | def _build_name_asset_map(assets: list[dict]) -> dict[str, dict]: |
| | | """Build name -> asset mapping from character_design characters/settings.""" |
| | | mapping = {} |
| | | for asset in assets: |
| | | name = str(asset.get("name") or "").strip() |
| | | asset_id = str(asset.get("id") or "").strip() |
| | | if name: |
| | | mapping[name] = asset |
| | | if asset_id: |
| | | mapping[asset_id] = asset |
| | | return mapping |
| | | |
| | | @staticmethod |
| | | def _match_asset_by_name(name: str, assets: list[dict], asset_map: Optional[dict[str, dict]] = None) -> Optional[dict]: |
| | | clean_name = (name or "").strip() |
| | | if not clean_name: |
| | | return None |
| | | if asset_map and clean_name in asset_map: |
| | | return asset_map[clean_name] |
| | | for asset in assets: |
| | | asset_name = str(asset.get("name") or "").strip() |
| | | if asset_name and asset_name == clean_name: |
| | | return asset |
| | | for asset in assets: |
| | | asset_name = str(asset.get("name") or "").strip() |
| | | if asset_name and (asset_name in clean_name or clean_name in asset_name): |
| | | return asset |
| | | return None |
| | | |
| | | def _get_segment_reference_assets(self, segment: dict, character_artifact: dict) -> List[str]: |
| | | """参考图生视频:按 segment.characters/location 读取第二阶段用户选中的人物图和场景图。""" |
| | | characters = character_artifact.get("characters", []) if isinstance(character_artifact, dict) else [] |
| | | settings = character_artifact.get("settings", []) if isinstance(character_artifact, dict) else [] |
| | | character_map = self._build_name_asset_map(characters) |
| | | setting_map = self._build_name_asset_map(settings) |
| | | reference_paths: List[str] = [] |
| | | seen = set() |
| | | |
| | | def add_asset(asset: Optional[dict]) -> None: |
| | | if not asset: |
| | | return |
| | | path = self._asset_selected_path(asset) |
| | | if path and path not in seen: |
| | | reference_paths.append(path) |
| | | seen.add(path) |
| | | |
| | | location = str(segment.get("location") or "").strip() |
| | | add_asset(self._match_asset_by_name(location, settings, setting_map)) |
| | | |
| | | for character_name in segment.get("characters") or []: |
| | | add_asset(self._match_asset_by_name(str(character_name), characters, character_map)) |
| | | |
| | | return reference_paths |
| | | |
| | | @staticmethod |
| | | def _select_video_model(input_data: dict, session_meta: dict) -> tuple[str, str]: |
| | | mode = ( |
| | | input_data.get("video_generation_mode") |
| | | or session_meta.get("video_generation_mode") |
| | | or "first_frame" |
| | | ) |
| | | model_key = { |
| | | "first_frame": "video_first_frame_model", |
| | | "start_end_frame": "video_start_end_model", |
| | | "reference": "video_reference_model", |
| | | }.get(mode, "video_first_frame_model") |
| | | model = input_data.get(model_key) or session_meta.get(model_key) |
| | | if not model: |
| | | # Legacy session compatibility: sessions created before mode-specific video models only have video_model. |
| | | model = input_data.get("video_model") or session_meta.get("video_model") |
| | | if not model: |
| | | raise ValueError("Missing required model configuration: video_model") |
| | | return mode, model |
| | | |
| | | # ─── 预览 / Payload ─── |
| | | |
| | |
| | | clip["selected"] = selected_clips[clip_id] |
| | | return payload |
| | | |
| | | video_model = self._require_input(input_data, "video_model") |
| | | session_meta = self._session_meta(input_data) |
| | | video_generation_mode, video_model = self._select_video_model(input_data, session_meta) |
| | | enable_concurrency = input_data.get("enable_concurrency", True) |
| | | from models.config_model import get_max_concurrency |
| | | concurrency = get_max_concurrency(video_model, enable_concurrency) |
| | |
| | | video_shot_type = input_data.get("video_shot_type", "multi") |
| | | |
| | | artifacts = self._session_artifacts(input_data) |
| | | session_meta = self._session_meta(input_data) |
| | | |
| | | # 1. 获取拍摄片段列表 (从 Storyboard) |
| | | episodes = artifacts.get('storyboard', {}).get('episodes', []) |
| | |
| | | ref_art = artifacts.get('reference_generation', {}) |
| | | scene_list = ref_art.get('scenes', []) |
| | | scene_map = {s['id']: s for s in scene_list if 'id' in s} |
| | | character_art = artifacts.get('character_design', {}) |
| | | |
| | | style_zh = input_data.get('style') or session_meta.get('style') or 'realistic' |
| | | # 简单映射为中文显示名 |
| | |
| | | if not seg: continue |
| | | prompt = self._assemble_prompt(seg, style_prompt, video_data=clip) |
| | | |
| | | reference_image_paths = None |
| | | if video_generation_mode == "reference": |
| | | img_path = None |
| | | reference_image_paths = self._get_segment_reference_assets(seg, character_art) |
| | | if not reference_image_paths: |
| | | logger.warning("VideoDirectorAgent: %s 参考图模式未匹配到第二阶段人物/场景图", seg_id) |
| | | else: |
| | | img_path = self._get_reference_image(sid, seg_id, scene_map) |
| | | duration = seg.get("total_duration", 10) |
| | | seg_index = segments.index(seg) |
| | | last_img_path = self._get_next_reference_image(sid, seg_index, segments, scene_map) |
| | | if video_generation_mode == "start_end_frame" and not last_img_path: |
| | | logger.warning("VideoDirectorAgent: %s 首尾帧模式缺少尾帧,回退为首帧生视频入参", seg_id) |
| | | fut = executor.submit( |
| | | self._generate_one, sid, seg_id, prompt, |
| | | img_path, video_model, duration, |
| | | "", video_shot_type, video_ratio, video_resolution |
| | | "", video_shot_type, video_ratio, video_resolution, |
| | | video_generation_mode, last_img_path, reference_image_paths |
| | | ) |
| | | futs[fut] = seg_id |
| | | for fut in as_completed(futs): |
| | |
| | | |
| | | def run(): |
| | | tasks = [] |
| | | for seg in segments: |
| | | for seg_index, seg in enumerate(segments): |
| | | seg_id = seg["segment_id"] |
| | | existing = self._list_versions(sid, seg_id) |
| | | if existing: continue |
| | | prompt = self._assemble_prompt(seg, style_prompt) |
| | | reference_image_paths = None |
| | | if video_generation_mode == "reference": |
| | | img_path = None |
| | | reference_image_paths = self._get_segment_reference_assets(seg, character_art) |
| | | if not reference_image_paths: |
| | | logger.warning("VideoDirectorAgent: %s 参考图模式未匹配到第二阶段人物/场景图", seg_id) |
| | | else: |
| | | img_path = self._get_reference_image(sid, seg_id, scene_map) |
| | | duration = seg.get("total_duration", 10) |
| | | tasks.append((seg_id, prompt, img_path, duration)) |
| | | last_img_path = self._get_next_reference_image(sid, seg_index, segments, scene_map) |
| | | if video_generation_mode == "start_end_frame" and not last_img_path: |
| | | logger.warning("VideoDirectorAgent: %s 首尾帧模式缺少尾帧,回退为首帧生视频入参", seg_id) |
| | | tasks.append((seg_id, prompt, img_path, duration, last_img_path, reference_image_paths)) |
| | | if not tasks: |
| | | self._report_progress("视频生成", "所有视频片段已存在", 95) |
| | | return |
| | | done = 0 |
| | | with ThreadPoolExecutor(max_workers=concurrency) as executor: |
| | | futs = {} |
| | | for seg_id, prompt, img_path, dur in tasks: |
| | | for seg_id, prompt, img_path, dur, last_img_path, reference_image_paths in tasks: |
| | | # 提交前立即发送正在运行的状态,让前端 UI 更新 |
| | | self._report_progress("视频生成", f"启动生成: {seg_id}", 5, data={ |
| | | "asset_complete": { |
| | |
| | | fut = executor.submit( |
| | | self._generate_one, sid, seg_id, prompt, |
| | | img_path, video_model, dur, |
| | | "", video_shot_type, video_ratio, video_resolution |
| | | "", video_shot_type, video_ratio, video_resolution, |
| | | video_generation_mode, last_img_path, reference_image_paths |
| | | ) |
| | | futs[fut] = seg_id |
| | | for fut in as_completed(futs): |
| | |
| | | "image_t2i_model", |
| | | "image_it2i_model", |
| | | "video_model", |
| | | "video_first_frame_model", |
| | | "video_start_end_model", |
| | | "video_reference_model", |
| | | "video_generation_mode", |
| | | "video_style", |
| | | "enable_concurrency", |
| | | "web_search", |
| | |
| | | nested_meta = data.get("meta") |
| | | if isinstance(nested_meta, dict): |
| | | meta.update({k: _normalize_meta_value(v) for k, v in nested_meta.items() if v is not None}) |
| | | # Legacy session compatibility: old session JSON stored these fields at the root instead of under meta. |
| | | for key in SESSION_META_KEYS: |
| | | if key not in meta and key in data and data[key] is not None: |
| | | meta[key] = _normalize_meta_value(data[key]) |
| | |
| | | if "created_at" not in data: |
| | | data["created_at"] = time.time() |
| | | |
| | | # 会话级生成参数统一保存在 meta 中;清理旧版本遗留的根字段。 |
| | | # Legacy session compatibility: clean root-level generation fields left by old session JSON. |
| | | for key in SESSION_META_KEYS: |
| | | data.pop(key, None) |
| | | |
| | |
| | | 'video_continuation', |
| | | 'audio_driven_i2v', |
| | | 'multi_shot'], |
| | | 'adapter_ability_types': ['first_frame_i2v', 'audio_driven_i2v'], |
| | | 'adapter_ability_types': ['first_frame_i2v', |
| | | 'start_end_frame_i2v', |
| | | 'audio_driven_i2v'], |
| | | 'input_modalities': ['text', 'image', 'audio', 'video'], |
| | | 'adapter_input_modalities': ['text', 'image'], |
| | | 'duration': {'min': 2, 'max': 15, 'integer': True, 'verified': True}, |
| | |
| | | watermark=watermark, |
| | | generate_audio=generate_audio, |
| | | ) |
| | | |
| | | |
| | | def _split_csv(value: Optional[str]) -> list[str]: |
| | | if not value: |
| | | return [] |
| | | return [item.strip() for item in value.split(",") if item.strip()] |
| | | |
| | | |
| | | def _str_to_bool(value: Optional[str]) -> Optional[bool]: |
| | | if value is None: |
| | | return None |
| | | normalized = value.strip().lower() |
| | | if normalized in {"1", "true", "yes", "on"}: |
| | | return True |
| | | if normalized in {"0", "false", "no", "off"}: |
| | | return False |
| | | raise ValueError(f"Invalid boolean value: {value}") |
| | | |
| | | |
| | | def _default_save_path(model: str, generation_mode: str) -> str: |
| | | safe_model = "".join(ch if ch.isalnum() or ch in {"-", "_", "."} else "_" for ch in model) |
| | | return os.path.join(Config.RESULT_DIR, "video", "test_client", f"{safe_model}_{generation_mode}.mp4") |
| | | |
| | | |
| | | def _build_cli_parser(): |
| | | import argparse |
| | | |
| | | parser = argparse.ArgumentParser(description="Test VideoClient with a selected generation mode and model.") |
| | | parser.add_argument("--generation-mode", choices=["first_frame", "start_end_frame", "reference"], default="first_frame") |
| | | parser.add_argument("--model", default="wan2.7-i2v", help="Video model id, e.g. wan2.7-i2v / wan2.7-r2v / happyhorse-1.0-r2v") |
| | | parser.add_argument("--prompt", default="电影感画面,人物自然移动,镜头稳定推进,不要字幕或水印。") |
| | | parser.add_argument("--image", help="First-frame image path for first_frame/start_end_frame, or an extra reference image for reference mode.") |
| | | parser.add_argument("--last-image", help="Last-frame image path for start_end_frame mode.") |
| | | parser.add_argument("--reference-images", help="Comma-separated reference image paths for reference mode.") |
| | | parser.add_argument("--reference-videos", help="Comma-separated reference video paths for reference mode.") |
| | | parser.add_argument("--reference-audio", help="Reference audio path for supported reference-to-video models.") |
| | | parser.add_argument("--audio", help="Driving audio path for supported image-to-video models.") |
| | | parser.add_argument("--first-clip", help="First clip path for supported video continuation models.") |
| | | parser.add_argument("--save-path", help="Output mp4 path. Defaults to code/result/video/test_client/<model>_<mode>.mp4") |
| | | parser.add_argument("--duration", type=int, default=5) |
| | | parser.add_argument("--ratio", default="16:9") |
| | | parser.add_argument("--resolution", default="720P") |
| | | parser.add_argument("--shot-type", default="multi") |
| | | parser.add_argument("--sound", default="") |
| | | parser.add_argument("--negative-prompt", default="") |
| | | parser.add_argument("--prompt-extend", choices=["true", "false"]) |
| | | parser.add_argument("--watermark", choices=["true", "false"]) |
| | | parser.add_argument("--seed", type=int) |
| | | parser.add_argument("--mode", default="pro", help="Kling mode fallback: std/pro.") |
| | | parser.add_argument("--cfg-scale", type=float, default=0.5) |
| | | parser.add_argument("--generate-audio", choices=["true", "false"]) |
| | | parser.add_argument("--audio-enabled", choices=["true", "false"], help="Pass DashScope audio boolean for supported models.") |
| | | return parser |
| | | |
| | | |
| | | def _cli_generate(args) -> str: |
| | | reference_image_paths = _split_csv(args.reference_images) |
| | | reference_video_paths = _split_csv(args.reference_videos) |
| | | image_path = args.image |
| | | last_image_path = None |
| | | |
| | | if args.generation_mode == "first_frame": |
| | | if not image_path and not args.first_clip: |
| | | raise ValueError("first_frame mode requires --image or --first-clip.") |
| | | elif args.generation_mode == "start_end_frame": |
| | | if not image_path or not args.last_image: |
| | | raise ValueError("start_end_frame mode requires --image and --last-image.") |
| | | last_image_path = args.last_image |
| | | elif args.generation_mode == "reference": |
| | | if image_path: |
| | | reference_image_paths.append(image_path) |
| | | image_path = None |
| | | if not reference_image_paths and not reference_video_paths: |
| | | raise ValueError("reference mode requires --reference-images, --reference-videos, or --image.") |
| | | |
| | | save_path = args.save_path or _default_save_path(args.model, args.generation_mode) |
| | | client = VideoClient() |
| | | return client.generate_video( |
| | | prompt=args.prompt, |
| | | image_path=image_path, |
| | | save_path=save_path, |
| | | model=args.model, |
| | | duration=args.duration, |
| | | shot_type=args.shot_type, |
| | | sound=args.sound, |
| | | video_ratio=args.ratio, |
| | | resolution=args.resolution, |
| | | last_image_path=last_image_path, |
| | | first_clip_path=args.first_clip, |
| | | reference_image_paths=reference_image_paths or None, |
| | | reference_video_paths=reference_video_paths or None, |
| | | reference_audio_path=args.reference_audio, |
| | | audio_path=args.audio, |
| | | negative_prompt=args.negative_prompt or None, |
| | | prompt_extend=_str_to_bool(args.prompt_extend), |
| | | watermark=_str_to_bool(args.watermark), |
| | | seed=args.seed, |
| | | mode=args.mode, |
| | | cfg_scale=args.cfg_scale, |
| | | generate_audio=_str_to_bool(args.generate_audio), |
| | | audio=_str_to_bool(args.audio_enabled), |
| | | ) |
| | | |
| | | |
| | | if __name__ == "__main__": |
| | | logging.basicConfig(level=logging.INFO, format="%(asctime)s %(levelname)s %(name)s: %(message)s") |
| | | parser = _build_cli_parser() |
| | | cli_args = parser.parse_args() |
| | | try: |
| | | remote_url = _cli_generate(cli_args) |
| | | output_path = cli_args.save_path or _default_save_path(cli_args.model, cli_args.generation_mode) |
| | | print("✓ Video generation completed") |
| | | print(f" Remote URL: {remote_url}") |
| | | print(f" Local file: {os.path.abspath(output_path)}") |
| | | except Exception as exc: |
| | | print(f"✗ Video generation failed: {exc}", file=sys.stderr) |
| | | sys.exit(1) |
| | |
| | | import { useEffect, useState } from 'react'; |
| | | import { CheckCircle, Loader2, Save, Settings, XCircle } from 'lucide-react'; |
| | | import BrandHeader from '@/components/BrandHeader'; |
| | | import { fetchModelGroupsByType } from '@/lib/modelRegistry'; |
| | | import { fetchModelGroupsByType, fetchVideoModelGroupsByAbility } from '@/lib/modelRegistry'; |
| | | import { |
| | | VIDEO_RATIOS, |
| | | VIDEO_RESOLUTIONS, |
| | | VIDEO_GENERATION_MODES, |
| | | STYLES, |
| | | type ProviderGroup, |
| | | } from '@/config/models'; |
| | |
| | | options?: Array<{ id: string; label: string }> | ProviderGroup[]; |
| | | }; |
| | | |
| | | type ModelSelectKey = 'llm' | 'vlm' | 'image_it2i' | 'image_t2i' | 'video' | 'eval'; |
| | | type ModelSelectKey = 'llm' | 'vlm' | 'image_it2i' | 'image_t2i' | 'video_first_frame' | 'video_start_end' | 'video_reference'; |
| | | |
| | | const EMPTY_MODEL_SELECTS: Record<ModelSelectKey, ProviderGroup[]> = { |
| | | llm: [], |
| | | vlm: [], |
| | | image_it2i: [], |
| | | image_t2i: [], |
| | | video: [], |
| | | eval: [], |
| | | video_first_frame: [], |
| | | video_start_end: [], |
| | | video_reference: [], |
| | | }; |
| | | |
| | | const LOG_LEVEL_OPTIONS = [ |
| | |
| | | { path: 'models.vlm', label: 'vlm 视觉语言模型', type: 'select', options: [] }, |
| | | { path: 'models.image_it2i', label: 'image_it2i 图生图模型', type: 'select', options: [] }, |
| | | { path: 'models.image_t2i', label: 'image_t2i 文生图模型', type: 'select', options: [] }, |
| | | { path: 'models.video', label: 'video 视频模型', type: 'select', options: [] }, |
| | | { path: 'models.eval', label: 'eval 评估模型', type: 'select', options: [] }, |
| | | { path: 'models.video_first_frame', label: 'video_first_frame 首帧生视频模型', type: 'select', options: [] }, |
| | | { path: 'models.video_start_end', label: 'video_start_end 首尾帧生视频模型', type: 'select', options: [] }, |
| | | { path: 'models.video_reference', label: 'video_reference 参考图生视频模型', type: 'select', options: [] }, |
| | | ], |
| | | }, |
| | | { |
| | | title: '视频生成配置', |
| | | description: '只对主流程生效:风格、画幅比例和视频分辨率。', |
| | | description: '只对主流程生效:选择视频生成方式、风格、画幅比例和视频分辨率。', |
| | | fields: [ |
| | | { path: 'generation.video_generation_mode', label: 'video_generation_mode 视频生成方式', type: 'select', options: VIDEO_GENERATION_MODES }, |
| | | { path: 'generation.style', label: 'style 风格', type: 'select', options: STYLES }, |
| | | { path: 'generation.video_ratio', label: 'video_ratio 视频长宽比', type: 'select', options: VIDEO_RATIOS }, |
| | | { path: 'generation.video_resolution', label: 'video_resolution 视频分辨率', type: 'select', options: VIDEO_RESOLUTIONS }, |
| | |
| | | fetchModelGroupsByType('vlm'), |
| | | fetchModelGroupsByType('i2i'), |
| | | fetchModelGroupsByType('t2i'), |
| | | fetchModelGroupsByType('video'), |
| | | fetchVideoModelGroupsByAbility('first_frame_i2v'), |
| | | fetchVideoModelGroupsByAbility('start_end_frame_i2v'), |
| | | fetchVideoModelGroupsByAbility('reference_to_video'), |
| | | ]) |
| | | .then(([llm, vlm, imageIt2i, imageT2i, video]) => { |
| | | .then(([llm, vlm, imageIt2i, imageT2i, firstFrameVideo, startEndVideo, referenceVideo]) => { |
| | | if (cancelled) return; |
| | | setModelSelects({ |
| | | llm, |
| | | vlm, |
| | | image_it2i: imageIt2i, |
| | | image_t2i: imageT2i, |
| | | video, |
| | | eval: llm, |
| | | video_first_frame: firstFrameVideo, |
| | | video_start_end: startEndVideo, |
| | | video_reference: referenceVideo, |
| | | }); |
| | | }) |
| | | .catch(() => {}); |
| | |
| | | if (field.path === 'models.vlm') return { ...field, options: modelSelects.vlm }; |
| | | if (field.path === 'models.image_it2i') return { ...field, options: modelSelects.image_it2i }; |
| | | if (field.path === 'models.image_t2i') return { ...field, options: modelSelects.image_t2i }; |
| | | if (field.path === 'models.video') return { ...field, options: modelSelects.video }; |
| | | if (field.path === 'models.eval') return { ...field, options: modelSelects.eval }; |
| | | if (field.path === 'models.video_first_frame') return { ...field, options: modelSelects.video_first_frame }; |
| | | if (field.path === 'models.video_start_end') return { ...field, options: modelSelects.video_start_end }; |
| | | if (field.path === 'models.video_reference') return { ...field, options: modelSelects.video_reference }; |
| | | return field; |
| | | }), |
| | | }; |
| | |
| | | import { Sparkles, Play, Settings2, Clock, ArrowRight, Zap, CheckCircle, Trash2, X, Lock, Globe, ListOrdered, Upload, Loader2 } from 'lucide-react'; |
| | | import clsx from 'clsx'; |
| | | import { PROMPT_EXAMPLES } from '@/config/examples'; |
| | | import { STYLES, VIDEO_RATIOS, VIDEO_RESOLUTIONS, type ProviderGroup } from '@/config/models'; |
| | | import { |
| | | STYLES, |
| | | VIDEO_RATIOS, |
| | | VIDEO_RESOLUTIONS, |
| | | VIDEO_GENERATION_MODES, |
| | | type ProviderGroup, |
| | | type VideoGenerationMode, |
| | | } from '@/config/models'; |
| | | import { STAGES } from './TopBar'; |
| | | import { fetchModelGroupsByType } from '@/lib/modelRegistry'; |
| | | import { fetchModelGroupsByType, fetchVideoModelGroupsByAbility } from '@/lib/modelRegistry'; |
| | | |
| | | export interface ProjectParams { |
| | | idea: string; |
| | |
| | | image_t2i_model: string; |
| | | image_it2i_model: string; |
| | | video_model: string; |
| | | video_first_frame_model: string; |
| | | video_start_end_model: string; |
| | | video_reference_model: string; |
| | | video_generation_mode: VideoGenerationMode; |
| | | expand_idea?: boolean; |
| | | enable_concurrency?: boolean; |
| | | web_search?: boolean; |
| | |
| | | const [selectedVLM, setSelectedVLM] = useState(''); |
| | | const [selectedT2I, setSelectedT2I] = useState(''); |
| | | const [selectedI2I, setSelectedI2I] = useState(''); |
| | | const [selectedVideo, setSelectedVideo] = useState(''); |
| | | const [selectedFirstFrameVideo, setSelectedFirstFrameVideo] = useState(''); |
| | | const [selectedStartEndVideo, setSelectedStartEndVideo] = useState(''); |
| | | const [selectedReferenceVideo, setSelectedReferenceVideo] = useState(''); |
| | | const [selectedVideoMode, setSelectedVideoMode] = useState<VideoGenerationMode>('first_frame'); |
| | | const [selectedRatio, setSelectedRatio] = useState(''); |
| | | const [selectedResolution, setSelectedResolution] = useState('720P'); |
| | | const [configLoading, setConfigLoading] = useState(true); |
| | |
| | | const [vlmProviders, setVlmProviders] = useState<ProviderGroup[]>([]); |
| | | const [t2iProviders, setT2iProviders] = useState<ProviderGroup[]>([]); |
| | | const [i2iProviders, setI2iProviders] = useState<ProviderGroup[]>([]); |
| | | const [videoProviders, setVideoProviders] = useState<ProviderGroup[]>([]); |
| | | const modelConfigReady = Boolean(selectedLLM && selectedVLM && selectedT2I && selectedI2I && selectedVideo && selectedRatio && selectedResolution); |
| | | const [firstFrameVideoProviders, setFirstFrameVideoProviders] = useState<ProviderGroup[]>([]); |
| | | const [startEndVideoProviders, setStartEndVideoProviders] = useState<ProviderGroup[]>([]); |
| | | const [referenceVideoProviders, setReferenceVideoProviders] = useState<ProviderGroup[]>([]); |
| | | const activeVideoModel = |
| | | selectedVideoMode === 'start_end_frame' |
| | | ? selectedStartEndVideo |
| | | : selectedVideoMode === 'reference' |
| | | ? selectedReferenceVideo |
| | | : selectedFirstFrameVideo; |
| | | const modelConfigReady = Boolean(selectedLLM && selectedVLM && selectedT2I && selectedI2I && activeVideoModel && selectedRatio && selectedResolution); |
| | | const canStart = Boolean((idea.trim() || uploadedFile) && modelConfigReady && !configLoading); |
| | | |
| | | useEffect(() => { |
| | |
| | | fetchModelGroupsByType('i2i') |
| | | .then(groups => { if (!cancelled) setI2iProviders(groups); }) |
| | | .catch(() => {}); |
| | | fetchModelGroupsByType('video') |
| | | .then(groups => { if (!cancelled) setVideoProviders(groups); }) |
| | | fetchVideoModelGroupsByAbility('first_frame_i2v') |
| | | .then(groups => { if (!cancelled) setFirstFrameVideoProviders(groups); }) |
| | | .catch(() => {}); |
| | | fetchVideoModelGroupsByAbility('start_end_frame_i2v') |
| | | .then(groups => { if (!cancelled) setStartEndVideoProviders(groups); }) |
| | | .catch(() => {}); |
| | | fetchVideoModelGroupsByAbility('reference_to_video') |
| | | .then(groups => { if (!cancelled) setReferenceVideoProviders(groups); }) |
| | | .catch(() => {}); |
| | | return () => { cancelled = true; }; |
| | | }, []); |
| | |
| | | const data = await resp.json(); |
| | | const models = data.config?.models || {}; |
| | | const generation = data.config?.generation || {}; |
| | | if (!models.llm || !models.vlm || !models.image_t2i || !models.image_it2i || !models.video) { |
| | | // Legacy config compatibility: older config.yaml only has models.video, so treat it as first-frame video. |
| | | const firstFrameModel = models.video_first_frame || models.video; |
| | | const startEndModel = models.video_start_end || 'wan2.7-i2v'; |
| | | const referenceModel = models.video_reference || 'wan2.7-r2v'; |
| | | const videoMode = (generation.video_generation_mode || 'first_frame') as VideoGenerationMode; |
| | | const selectedModel = videoMode === 'start_end_frame' ? startEndModel : videoMode === 'reference' ? referenceModel : firstFrameModel; |
| | | if (!models.llm || !models.vlm || !models.image_t2i || !models.image_it2i || !selectedModel) { |
| | | throw new Error('backend/config.yaml 缺少主流程默认模型'); |
| | | } |
| | | if (cancelled) return; |
| | |
| | | setSelectedVLM(models.vlm); |
| | | setSelectedT2I(models.image_t2i); |
| | | setSelectedI2I(models.image_it2i); |
| | | setSelectedVideo(models.video); |
| | | setSelectedVideoMode(videoMode); |
| | | setSelectedFirstFrameVideo(firstFrameModel); |
| | | setSelectedStartEndVideo(startEndModel); |
| | | setSelectedReferenceVideo(referenceModel); |
| | | setSelectedRatio(generation.video_ratio || '16:9'); |
| | | setSelectedResolution(generation.video_resolution || '720P'); |
| | | } catch (e: any) { |
| | |
| | | } |
| | | }; |
| | | |
| | | const activeVideoProviders = |
| | | selectedVideoMode === 'start_end_frame' |
| | | ? startEndVideoProviders |
| | | : selectedVideoMode === 'reference' |
| | | ? referenceVideoProviders |
| | | : firstFrameVideoProviders; |
| | | |
| | | const setActiveVideoModel = (value: string) => { |
| | | if (selectedVideoMode === 'start_end_frame') { |
| | | setSelectedStartEndVideo(value); |
| | | } else if (selectedVideoMode === 'reference') { |
| | | setSelectedReferenceVideo(value); |
| | | } else { |
| | | setSelectedFirstFrameVideo(value); |
| | | } |
| | | }; |
| | | |
| | | const selectedVideoModeLabel = VIDEO_GENERATION_MODES.find(item => item.id === selectedVideoMode)?.label || '首帧生视频'; |
| | | |
| | | const handleStart = (auto?: boolean) => { |
| | | if (!canStart) return; |
| | | onStartProject({ |
| | |
| | | vlm_model: selectedVLM, |
| | | image_t2i_model: selectedT2I, |
| | | image_it2i_model: selectedI2I, |
| | | video_model: selectedVideo, |
| | | video_generation_mode: selectedVideoMode, |
| | | video_first_frame_model: selectedFirstFrameVideo, |
| | | video_start_end_model: selectedStartEndVideo, |
| | | video_reference_model: selectedReferenceVideo, |
| | | video_model: activeVideoModel, |
| | | enable_concurrency: enableConcurrency, |
| | | web_search: webSearch, |
| | | episodes, |
| | |
| | | </select> |
| | | </label> |
| | | <label className="flex flex-col gap-1 col-span-2"> |
| | | <span className="text-gray-500 font-medium">视频模型</span> |
| | | <span className="text-gray-500 font-medium">视频生成方式</span> |
| | | <select |
| | | value={selectedVideo} |
| | | onChange={e => setSelectedVideo(e.target.value)} |
| | | value={selectedVideoMode} |
| | | onChange={e => setSelectedVideoMode(e.target.value as VideoGenerationMode)} |
| | | className="bg-white border border-gray-200 rounded-lg px-2.5 py-2 text-gray-700 outline-none" |
| | | > |
| | | {videoProviders.map(pg => ( |
| | | {VIDEO_GENERATION_MODES.map(item => ( |
| | | <option key={item.id} value={item.id}>{item.label}</option> |
| | | ))} |
| | | </select> |
| | | </label> |
| | | <label className="flex flex-col gap-1 col-span-2"> |
| | | <span className="text-gray-500 font-medium">{selectedVideoModeLabel}模型</span> |
| | | <select |
| | | value={activeVideoModel} |
| | | onChange={e => setActiveVideoModel(e.target.value)} |
| | | className="bg-white border border-gray-200 rounded-lg px-2.5 py-2 text-gray-700 outline-none" |
| | | > |
| | | {activeVideoProviders.map(pg => ( |
| | | <optgroup key={pg.provider} label={pg.label}> |
| | | {pg.models.map(m => ( |
| | | <option key={m.id} value={m.id}>{m.label}</option> |
| | |
| | | import React, { useState, useRef, useEffect } from 'react'; |
| | | import { CheckCircle, Circle, Loader, Edit3, AlertCircle, Square, Zap, Settings2, ChevronDown } from 'lucide-react'; |
| | | import clsx from 'clsx'; |
| | | import { VIDEO_RATIOS, VIDEO_RESOLUTIONS, type ProviderGroup } from '@/config/models'; |
| | | import { fetchModelGroupsByType } from '@/lib/modelRegistry'; |
| | | import { |
| | | VIDEO_RATIOS, |
| | | VIDEO_RESOLUTIONS, |
| | | VIDEO_GENERATION_MODES, |
| | | type ProviderGroup, |
| | | type VideoGenerationMode, |
| | | } from '@/config/models'; |
| | | import { fetchModelGroupsByType, fetchVideoModelGroupsByAbility } from '@/lib/modelRegistry'; |
| | | |
| | | export type StageStatus = 'pending' | 'running' | 'waiting' | 'completed' | 'error' | 'stopped'; |
| | | |
| | |
| | | image_t2i_model: string; |
| | | image_it2i_model: string; |
| | | video_model: string; |
| | | video_first_frame_model: string; |
| | | video_start_end_model: string; |
| | | video_reference_model: string; |
| | | video_generation_mode: VideoGenerationMode; |
| | | video_ratio: string; |
| | | video_resolution: string; |
| | | enable_concurrency: boolean; |
| | |
| | | const [vlmProviders, setVlmProviders] = useState<ProviderGroup[]>([]); |
| | | const [t2iProviders, setT2iProviders] = useState<ProviderGroup[]>([]); |
| | | const [i2iProviders, setI2iProviders] = useState<ProviderGroup[]>([]); |
| | | const [videoProviders, setVideoProviders] = useState<ProviderGroup[]>([]); |
| | | const [firstFrameVideoProviders, setFirstFrameVideoProviders] = useState<ProviderGroup[]>([]); |
| | | const [startEndVideoProviders, setStartEndVideoProviders] = useState<ProviderGroup[]>([]); |
| | | const [referenceVideoProviders, setReferenceVideoProviders] = useState<ProviderGroup[]>([]); |
| | | |
| | | useEffect(() => { |
| | | const handler = (e: MouseEvent) => { |
| | |
| | | fetchModelGroupsByType('i2i') |
| | | .then(groups => { if (!cancelled) setI2iProviders(groups); }) |
| | | .catch(() => {}); |
| | | fetchModelGroupsByType('video') |
| | | .then(groups => { if (!cancelled) setVideoProviders(groups); }) |
| | | fetchVideoModelGroupsByAbility('first_frame_i2v') |
| | | .then(groups => { if (!cancelled) setFirstFrameVideoProviders(groups); }) |
| | | .catch(() => {}); |
| | | fetchVideoModelGroupsByAbility('start_end_frame_i2v') |
| | | .then(groups => { if (!cancelled) setStartEndVideoProviders(groups); }) |
| | | .catch(() => {}); |
| | | fetchVideoModelGroupsByAbility('reference_to_video') |
| | | .then(groups => { if (!cancelled) setReferenceVideoProviders(groups); }) |
| | | .catch(() => {}); |
| | | return () => { cancelled = true; }; |
| | | }, []); |
| | | |
| | | const update = (key: keyof ModelConfig, val: string | boolean) => { |
| | | onChange({ ...config, [key]: val }); |
| | | }; |
| | | |
| | | const activeVideoModel = |
| | | config.video_generation_mode === 'start_end_frame' |
| | | ? config.video_start_end_model |
| | | : config.video_generation_mode === 'reference' |
| | | ? config.video_reference_model |
| | | : config.video_first_frame_model; |
| | | const activeVideoProviders = |
| | | config.video_generation_mode === 'start_end_frame' |
| | | ? startEndVideoProviders |
| | | : config.video_generation_mode === 'reference' |
| | | ? referenceVideoProviders |
| | | : firstFrameVideoProviders; |
| | | const activeVideoLabel = VIDEO_GENERATION_MODES.find(item => item.id === config.video_generation_mode)?.label || '首帧生视频'; |
| | | |
| | | const updateVideoMode = (mode: VideoGenerationMode) => { |
| | | const nextModel = |
| | | mode === 'start_end_frame' |
| | | ? config.video_start_end_model |
| | | : mode === 'reference' |
| | | ? config.video_reference_model |
| | | : config.video_first_frame_model; |
| | | onChange({ ...config, video_generation_mode: mode, video_model: nextModel }); |
| | | }; |
| | | |
| | | const updateActiveVideoModel = (model: string) => { |
| | | if (config.video_generation_mode === 'start_end_frame') { |
| | | onChange({ ...config, video_start_end_model: model, video_model: model }); |
| | | } else if (config.video_generation_mode === 'reference') { |
| | | onChange({ ...config, video_reference_model: model, video_model: model }); |
| | | } else { |
| | | onChange({ ...config, video_first_frame_model: model, video_model: model }); |
| | | } |
| | | }; |
| | | |
| | | return ( |
| | |
| | | <ProviderSelect value={config.image_it2i_model} providers={i2iProviders} onChange={v => update('image_it2i_model', v)} /> |
| | | </label> |
| | | <label className="flex flex-col gap-1"> |
| | | <span className="text-[10px] text-gray-400 font-medium">视频模型</span> |
| | | <ProviderSelect value={config.video_model} providers={videoProviders} onChange={v => update('video_model', v)} /> |
| | | <span className="text-[10px] text-gray-400 font-medium">视频生成方式</span> |
| | | <select |
| | | value={config.video_generation_mode} |
| | | onChange={e => updateVideoMode(e.target.value as VideoGenerationMode)} |
| | | className="bg-gray-50 border border-gray-200 rounded-lg px-2 py-1.5 text-xs text-gray-700 outline-none w-full" |
| | | > |
| | | {VIDEO_GENERATION_MODES.map(item => ( |
| | | <option key={item.id} value={item.id}>{item.label}</option> |
| | | ))} |
| | | </select> |
| | | </label> |
| | | <label className="flex flex-col gap-1"> |
| | | <span className="text-[10px] text-gray-400 font-medium">{activeVideoLabel}模型</span> |
| | | <ProviderSelect value={activeVideoModel} providers={activeVideoProviders} onChange={updateActiveVideoModel} /> |
| | | </label> |
| | | <label className="flex flex-col gap-1"> |
| | | <span className="text-[10px] text-gray-400 font-medium">视频比例</span> |
| | |
| | | vlm_model: params.vlm_model, |
| | | image_t2i_model: params.image_t2i_model, |
| | | image_it2i_model: params.image_it2i_model, |
| | | video_generation_mode: params.video_generation_mode, |
| | | video_first_frame_model: params.video_first_frame_model, |
| | | video_start_end_model: params.video_start_end_model, |
| | | video_reference_model: params.video_reference_model, |
| | | video_model: params.video_model, |
| | | enable_concurrency: params.enable_concurrency, |
| | | web_search: params.web_search, |
| | |
| | | vlm_model: params.vlm_model, |
| | | image_t2i_model: params.image_t2i_model, |
| | | image_it2i_model: params.image_it2i_model, |
| | | video_generation_mode: params.video_generation_mode, |
| | | video_first_frame_model: params.video_first_frame_model, |
| | | video_start_end_model: params.video_start_end_model, |
| | | video_reference_model: params.video_reference_model, |
| | | video_model: params.video_model, |
| | | scene_number: result.params?.scene_number, |
| | | expand_idea: params.expand_idea, |
| | |
| | | vlm_model: projectParams?.vlm_model, |
| | | image_t2i_model: projectParams?.image_t2i_model, |
| | | image_it2i_model: projectParams?.image_it2i_model, |
| | | video_generation_mode: projectParams?.video_generation_mode, |
| | | video_first_frame_model: projectParams?.video_first_frame_model, |
| | | video_start_end_model: projectParams?.video_start_end_model, |
| | | video_reference_model: projectParams?.video_reference_model, |
| | | video_model: projectParams?.video_model, |
| | | video_ratio: projectParams?.video_ratio, |
| | | video_resolution: projectParams?.video_resolution, |
| | |
| | | vlm_model: projectParams?.vlm_model, |
| | | image_t2i_model: projectParams?.image_t2i_model, |
| | | image_it2i_model: projectParams?.image_it2i_model, |
| | | video_generation_mode: projectParams?.video_generation_mode, |
| | | video_first_frame_model: projectParams?.video_first_frame_model, |
| | | video_start_end_model: projectParams?.video_start_end_model, |
| | | video_reference_model: projectParams?.video_reference_model, |
| | | video_model: projectParams?.video_model, |
| | | video_sound: videoSound, |
| | | video_shot_type: videoShotType, |
| | |
| | | vlm_model: projectParams?.vlm_model, |
| | | image_t2i_model: projectParams?.image_t2i_model, |
| | | image_it2i_model: projectParams?.image_it2i_model, |
| | | video_generation_mode: projectParams?.video_generation_mode, |
| | | video_first_frame_model: projectParams?.video_first_frame_model, |
| | | video_start_end_model: projectParams?.video_start_end_model, |
| | | video_reference_model: projectParams?.video_reference_model, |
| | | video_model: projectParams?.video_model, |
| | | video_ratio: projectParams?.video_ratio, |
| | | video_resolution: projectParams?.video_resolution, |
| | |
| | | const meta = ((status as any).meta || {}) as any; |
| | | const s = Object.keys(meta).length > 0 ? meta : (status as any); |
| | | if (s.idea || s.user_textbox_input) { |
| | | // Legacy session compatibility: old sessions only stored one video_model, so hydrate it as the first-frame model. |
| | | const restoredFirstFrameVideoModel = s.video_first_frame_model || s.video_model || ''; |
| | | setProjectParams({ |
| | | idea: s.idea || s.user_textbox_input || '', |
| | | style: s.style || '', |
| | |
| | | vlm_model: s.vlm_model || '', |
| | | image_t2i_model: s.image_t2i_model || '', |
| | | image_it2i_model: s.image_it2i_model || '', |
| | | video_generation_mode: s.video_generation_mode || 'first_frame', |
| | | video_first_frame_model: restoredFirstFrameVideoModel, |
| | | video_start_end_model: s.video_start_end_model || 'wan2.7-i2v', |
| | | video_reference_model: s.video_reference_model || 'wan2.7-r2v', |
| | | video_model: s.video_model || '', |
| | | expand_idea: s.expand_idea || false, |
| | | enable_concurrency: s.enable_concurrency || false, |
| | |
| | | vlm_model: projectParams.vlm_model, |
| | | image_t2i_model: projectParams.image_t2i_model, |
| | | image_it2i_model: projectParams.image_it2i_model, |
| | | // Legacy session compatibility: projectParams may come from an old session with only video_model. |
| | | video_generation_mode: projectParams.video_generation_mode || 'first_frame', |
| | | video_first_frame_model: projectParams.video_first_frame_model || projectParams.video_model, |
| | | video_start_end_model: projectParams.video_start_end_model || 'wan2.7-i2v', |
| | | video_reference_model: projectParams.video_reference_model || 'wan2.7-r2v', |
| | | video_model: projectParams.video_model, |
| | | video_ratio: projectParams.video_ratio, |
| | | video_resolution: projectParams.video_resolution || '720P', |
| | |
| | | models: ModelOption[]; |
| | | } |
| | | |
| | | export type VideoGenerationMode = 'first_frame' | 'start_end_frame' | 'reference'; |
| | | |
| | | export const VIDEO_GENERATION_MODES: Array<{ id: VideoGenerationMode; label: string; ability: string; modelKey: string }> = [ |
| | | { id: 'first_frame', label: '首帧生视频', ability: 'first_frame_i2v', modelKey: 'video_first_frame_model' }, |
| | | { id: 'start_end_frame', label: '首尾帧生视频', ability: 'start_end_frame_i2v', modelKey: 'video_start_end_model' }, |
| | | { id: 'reference', label: '参考图生视频', ability: 'reference_to_video', modelKey: 'video_reference_model' }, |
| | | ]; |
| | | |
| | | export function videoModeAbility(mode: string | undefined) { |
| | | return VIDEO_GENERATION_MODES.find(item => item.id === mode)?.ability || 'first_frame_i2v'; |
| | | } |
| | | |
| | | export function videoModeModelKey(mode: string | undefined) { |
| | | return VIDEO_GENERATION_MODES.find(item => item.id === mode)?.modelKey || 'video_first_frame_model'; |
| | | } |
| | | |
| | | export const STYLES = [ |
| | | { id: 'comic-book', label: 'Comic Book / 漫画' }, |
| | | { id: 'anime', label: 'Anime / 动漫' }, |
| | |
| | | const models = await fetchApiModels({ modelType }); |
| | | return groupModelOptions(models); |
| | | } |
| | | |
| | | export async function fetchVideoModelGroupsByAbility(ability: string): Promise<ProviderGroup[]> { |
| | | const models = await fetchApiModels({ mediaType: 'video', ability, verifiedOnly: true }); |
| | | return groupModelOptions(models); |
| | | } |
| | |
| | | image_t2i_model?: string; |
| | | image_it2i_model?: string; |
| | | video_model?: string; |
| | | video_first_frame_model?: string; |
| | | video_start_end_model?: string; |
| | | video_reference_model?: string; |
| | | video_generation_mode?: string; |
| | | scene_number?: number; |
| | | enable_concurrency?: boolean; |
| | | web_search?: boolean; |