| | |
| | | session_id = str(int(time.time() * 1000)) |
| | | state = workflow_engine.get_or_create_state(session_id) |
| | | state.started_at = __import__('datetime').datetime.now() |
| | | state.status = "stage_completed" |
| | | if not isinstance(state.status, dict): |
| | | state.status = {} |
| | | state.status[state.current_stage.value] = "completed" |
| | | |
| | | # 保存会话元数据(未传参数时使用 config.py 中的默认值) |
| | | meta = { |
| | |
| | | if 'is_new' in shot: |
| | | shot['is_new'] = False |
| | | |
| | | # 同步到 video_generation |
| | | shot_id_to_duration = {s['shot_id']: s.get('duration', 10) for s in body['shots'] if 'shot_id' in s} |
| | | shot_id_to_plot = {s['shot_id']: s.get('plot', '') for s in body['shots'] if 'shot_id' in s} |
| | | # 从 body['segments'] 提取同步信息(修改后的逻辑按 segment 同步) |
| | | seg_info_list = [] |
| | | for seg in body.get('segments', []): |
| | | seg_id = seg.get('segment_id') |
| | | if not seg_id: continue |
| | | |
| | | shots = seg.get('shots', []) |
| | | desc_video = " ".join([sh.get("plot") or sh.get("content") or "" for sh in shots]).strip() |
| | | total_dur = seg.get("total_duration") or sum([sh.get("duration", 0) for sh in shots]) or 10 |
| | | |
| | | seg_info_list.append({ |
| | | "segment_id": seg_id, |
| | | "desc": desc_video, |
| | | "duration": total_dur |
| | | }) |
| | | |
| | | # 同步到 video_generation |
| | | video_art = state.artifacts.get('video_generation', {}) |
| | | if isinstance(video_art, dict) and 'clips' in video_art: |
| | | for clip in video_art['clips']: |
| | | shot_id = clip.get('id') |
| | | if shot_id in shot_id_to_duration: |
| | | clip['duration'] = shot_id_to_duration[shot_id] |
| | | if shot_id in shot_id_to_plot: |
| | | clip['description'] = shot_id_to_plot[shot_id] |
| | | c_id = clip.get('id') |
| | | # 匹配 segment_id |
| | | target = next((item for item in seg_info_list if item["segment_id"] == c_id), None) |
| | | if target: |
| | | clip['duration'] = target['duration'] |
| | | clip['description'] = target['desc'] |
| | | |
| | | # 移除 shots,避免覆盖 storyboard artifact |
| | | body = {k: v for k, v in body.items() if k != "shots"} |
| | | # 移除 segments,避免覆盖 storyboard artifact |
| | | body = {k: v for k, v in body.items() if k != "segments"} |
| | | |
| | | # 清除 new_shot_ids 标记 |
| | | if "new_shot_ids" in body and body.get('new_shot_ids') == []: |
| | | if "new_shot_ids" in body: |
| | | del body['new_shot_ids'] |
| | | |
| | | # ══════════════════════════════════════════════════════════════ |
| | |
| | | with open(result_file, 'r', encoding='utf-8') as f: |
| | | results = json.load(f) |
| | | |
| | | storyboard = results.get(session_id, {}).get('storyboard', {}) |
| | | # 如果 results 是列表(旧版或某些 agent 的存储方式),则不能使用 .get(session_id) |
| | | # 根据 script_agent.py 的实现,final_json 是一个包含 session_id 的字典 |
| | | if isinstance(results, dict): |
| | | # 兼容两种结构:{session_id: {...}} 或 {...} |
| | | script_data = results.get(session_id, results) if results.get(session_id) else results |
| | | else: |
| | | # 如果是列表,尝试按 session_id 过滤 |
| | | script_data = next((item for item in results if isinstance(item, dict) and item.get("session_id") == session_id), {}) |
| | | |
| | | # 尝试从 script_data 或 state.artifacts 中获取 storyboard |
| | | storyboard = script_data.get('storyboard', {}) |
| | | if not storyboard: |
| | | # 兼容旧版本可能直接存储在 results 下的情况 |
| | | storyboard = results.get('storyboard', {}) if isinstance(results, dict) else {} |
| | | |
| | | shots = storyboard.get('shots', []) |
| | | |
| | | # 筛选该场景的分镜 |
| | |
| | | shot_ids = [s.get('shot_id') for s in scene_shots if s.get('shot_id')] |
| | | |
| | | # 检查参考图 |
| | | ref_artifact = results.get(session_id, {}).get('reference_generation', {}) |
| | | ref_scenes = ref_artifact.get('scenes', []) |
| | | ref_artifact = script_data.get('reference_generation', {}) |
| | | if not ref_artifact: |
| | | ref_artifact = state.artifacts.get('reference_generation', {}) |
| | | |
| | | ref_scenes = ref_artifact.get('scenes', []) if isinstance(ref_artifact, dict) else [] |
| | | ref_image_count = 0 |
| | | for sc in ref_scenes: |
| | | if sc.get('id') in shot_ids: |
| | |
| | | ref_image_count += 1 |
| | | |
| | | # 检查视频 |
| | | video_artifact = results.get(session_id, {}).get('video_generation', {}) |
| | | video_clips = video_artifact.get('clips', []) |
| | | video_artifact = script_data.get('video_generation', {}) |
| | | if not video_artifact: |
| | | video_artifact = state.artifacts.get('video_generation', {}) |
| | | |
| | | video_clips = video_artifact.get('clips', []) if isinstance(video_artifact, dict) else [] |
| | | video_count = 0 |
| | | for vc in video_clips: |
| | | if vc.get('id') in shot_ids: |