2 files deleted
4 files modified
| | |
| | | from concurrent.futures import ThreadPoolExecutor, as_completed |
| | | |
| | | from .base_agent import AgentInterface |
| | | from prompts.loader import load_prompt, load_style_prompt |
| | | from prompts.loader import load_prompt |
| | | |
| | | logger = logging.getLogger(__name__) |
| | | |
| | |
| | | |
| | | @staticmethod |
| | | def _char_prompt(name: str, desc: str, style: str, species: str = "") -> str: |
| | | """角色4视图提示词 - 从风格提示词文件加载""" |
| | | # 加载风格提示词模板 |
| | | template = load_style_prompt('character', style) |
| | | """角色4视图提示词 - 直接加载 character_zh 模板""" |
| | | # 加载基础角色提示词模板 |
| | | template = load_prompt('character', 'character', 'zh') |
| | | # 替换角色信息 |
| | | return template.format(name=name, desc=desc) |
| | | return template.format(name=name, desc=desc, style=style) |
| | | |
| | | @staticmethod |
| | | def _setting_prompt(name: str, desc: str, style: str) -> str: |
| | | """场景全景图提示词 - 从风格提示词文件加载""" |
| | | # 加载风格提示词模板 |
| | | template = load_style_prompt('setting', style) |
| | | """场景全景图提示词 - 直接加载 setting_zh 模板""" |
| | | # 加载基础场景提示词模板 |
| | | template = load_prompt('setting', 'setting', 'zh') |
| | | # 替换场景信息 |
| | | return template.format(name=name, desc=desc) |
| | | return template.format(name=name, desc=desc, style=style) |
| | | |
| | | # ─── 文件管理(基于唯一ID) ─── |
| | | |
| | |
| | | base_prompt = self._setting_prompt(name, desc, style) |
| | | |
| | | video_ratio = "16:9" |
| | | resolution = "1080P" |
| | | resolution = "4K" |
| | | current_prompt = base_prompt |
| | | |
| | | for iteration in range(max_iterations): |
| | |
| | | Character reference sheet, {style} style, white background, |
| | | 4 views of the same character arranged in a single row from left to right: |
| | | 1) front-facing close-up portrait (head and upper body), |
| | | 2) front-facing full body ({pose_note}), |
| | | 3) side-view full body ({pose_note}), |
| | | 4) back-view full body ({pose_note}). |
| | | All views show the SAME character with consistent appearance and outfit. |
| | | The close-up shows head-to-waist; the other three show complete body from head to feet. |
| | | Pure image only, absolutely NO text, NO labels, NO annotations, NO captions, NO watermarks on the image. |
| | | High quality, masterpiece, clean line art. |
| | | Character: {name} — {desc} |
| | | 角色设计参考图,{style} 风格,纯白背景。高画质,杰作,高画质。 |
| | | 角色描述: {name} — {desc} |
| | | 在同一排从左至右排列同一角色的 4 个视角: |
| | | 1) 正面肖像(胸部以上), |
| | | 2) 正面全身照, |
| | | 3) 侧面全身照, |
| | | 4) 背面全身照。 |
| | | 所有视角必须展示同一个角色,外貌、发型、肤色和服装保持高度一致。 |
| | | 画面纯净,绝对禁止出现任何文字、标签、标注、注释、说明或水印。 |
| | |
| | | prompt = format_prompt("Hello {name}, you are {age} years old", name="John", age=30) |
| | | """ |
| | | return template.format(**kwargs) |
| | | |
| | | |
| | | # 风格提示词缓存 |
| | | _STYLE_PROMPTS_CACHE = {} |
| | | |
| | | |
| | | def load_style_prompt(category: str, style: str) -> str: |
| | | """ |
| | | 加载指定风格的提示词 |
| | | |
| | | Args: |
| | | category: 提示词分类 (character, setting) |
| | | style: 风格名称 (realistic, anime, comic-book, 3d-disney, watercolor, oil-painting, cyberpunk, chinese-ink) |
| | | |
| | | Returns: |
| | | 风格提示词模板 |
| | | |
| | | Example: |
| | | prompt = load_style_prompt('character', 'realistic') |
| | | """ |
| | | # 先检查缓存 |
| | | cache_key = f"{category}:{style}" |
| | | if cache_key in _STYLE_PROMPTS_CACHE: |
| | | return _STYLE_PROMPTS_CACHE[cache_key] |
| | | |
| | | # 加载风格提示词文件 |
| | | file_path = os.path.join(PROMPTS_DIR, category, f"{style}_styles.txt") |
| | | if not os.path.exists(file_path): |
| | | # 回退到通用的风格文件 (character_styles.txt 或 setting_styles.txt) |
| | | fallback_file = "character_styles.txt" if category == "character" else "setting_styles.txt" |
| | | file_path = os.path.join(PROMPTS_DIR, category, fallback_file) |
| | | |
| | | if not os.path.exists(file_path): |
| | | fallback_file = "character_styles.txt" if category == "character" else "setting_styles.txt" |
| | | raise FileNotFoundError(f"Style prompt file not found: {category}/{fallback_file}") |
| | | |
| | | with open(file_path, 'r', encoding='utf-8') as f: |
| | | content = f.read() |
| | | |
| | | # 解析风格块 |
| | | current_style = None |
| | | style_templates = {} |
| | | for line in content.split('\n'): |
| | | line = line.strip() |
| | | # Skip empty lines and comment lines |
| | | if not line or line.startswith('#'): |
| | | continue |
| | | if line.startswith('[') and line.endswith(']'): |
| | | current_style = line[1:-1] |
| | | style_templates[current_style] = [] |
| | | elif current_style and line: |
| | | style_templates[current_style].append(line) |
| | | |
| | | # 转换为字符串 |
| | | for s in style_templates: |
| | | style_templates[s] = '\n'.join(style_templates[s]) |
| | | |
| | | # 缓存所有风格 |
| | | _STYLE_PROMPTS_CACHE.update(style_templates) |
| | | |
| | | # 返回指定风格的提示词 |
| | | if style in style_templates: |
| | | return style_templates[style] |
| | | |
| | | # 回退到 anime 或第一个可用风格 |
| | | if 'anime' in style_templates: |
| | | return style_templates['anime'] |
| | | |
| | | # 返回第一个可用的风格 |
| | | return list(style_templates.values())[0] if style_templates else "" |
| | |
| | | Panoramic landscape, eye-level wide shot, {style} style, |
| | | no characters, no people, no animals, |
| | | cinematic composition, establishing shot, |
| | | high quality, masterpiece, Movie picture quality. |
| | | Scene: {name} — {desc} |
| | | 全景远景,平视广角镜头,{style} 风格,电影级构图,杰作,高画质。 |
| | | 场景描述: {name} — {desc} |
| | | 画面主体区域禁止出现人物、动物或其他活体,确保环境布景完整、构图平衡。 |