From 9665fe254ba008dfac844a6ca95c70682fbce6cf Mon Sep 17 00:00:00 2001 From: chenpipi0807 <144689950+chenpipi0807@users.noreply.github.com> Date: Thu, 21 Aug 2025 17:31:12 +0800 Subject: [PATCH] =?UTF-8?q?=E9=92=88=E5=AF=B9=E8=A7=92=E8=89=B2=E4=B8=80?= =?UTF-8?q?=E8=87=B4=E6=80=A7=E5=81=9A=E4=BA=86=E5=8A=A0=E5=BC=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- qwen_image.py | 57 ++++++++++++++++++++++++++++++++------------------- 1 file changed, 36 insertions(+), 21 deletions(-) diff --git a/qwen_image.py b/qwen_image.py index 8eeb499..986a98f 100644 --- a/qwen_image.py +++ b/qwen_image.py @@ -17,38 +17,53 @@ class QwenImageTokenizer(sd1_clip.SD1Tokenizer): def __init__(self, embedding_directory=None, tokenizer_data={}): super().__init__(embedding_directory=embedding_directory, tokenizer_data=tokenizer_data, name="qwen25_7b", tokenizer=Qwen25_7BVLITokenizer) - # Enhanced English system prompt for image editing + # Enhanced English system prompt for image editing with character consistency focus self.llama_template_images_en = """<|im_start|>system -You are a Prompt optimizer designed to rewrite user inputs into high-quality Prompts that are more complete and expressive while preserving the original meaning. -Task Requirements: -1. For overly brief user inputs, reasonably infer and add details to enhance the visual completeness without altering the core content; -2. Refine descriptions of subject characteristics, visual style, spatial relationships, and shot composition; -3. If the input requires rendering text in the image, enclose specific text in quotation marks, specify its position (e.g., top-left corner, bottom-right corner) and style. This text should remain unaltered and not translated; -4. Match the Prompt to a precise, niche style aligned with the user's intent. If unspecified, choose the most appropriate style (e.g., realistic photography style); -5. Please ensure that the Rewritten Prompt is less than 200 words. +You are a Prompt optimizer specialized in character consistency for image editing. Your primary goal is to preserve character identity while implementing requested changes. -Describe the key features of the input image (color, shape, size, texture, objects, background), then explain how the user's text instruction should alter or modify the image. Generate a new image that meets the user's requirements while maintaining consistency with the original input where appropriate. Add "Ultra HD, 4K, cinematic composition" to enhance quality.<|im_end|> +Character Consistency Priority (CRITICAL): +1. FACIAL FEATURES (HIGHEST PRIORITY): Preserve exact facial structure, face shape, jawline, cheekbones, nose shape, lip shape, eye shape and spacing +2. HAIR: Maintain hair texture, hairstyle, hair color, hair length, and any hair accessories or decorations +3. EYES: Keep exact eye color, eye shape, eyebrow shape and color, eyelash style +4. SKIN: Preserve skin tone, skin texture, any facial markings, freckles, moles, or scars +5. DISTINCTIVE FEATURES: Maintain tattoos, piercings, birthmarks, facial hair style, or unique characteristics +6. CLOTHING/STYLE: Adapt clothing and accessories as requested while keeping character recognizable + +Task Requirements: +1. When modifying the image, ALWAYS explicitly describe which facial and character features must remain unchanged +2. For brief inputs, add details that enhance the scene while strictly preserving all character-identifying features +3. If text rendering is required, enclose in quotes with position specification +4. Prioritize character recognition over scene/background changes +5. Limit response to 200 words, focusing on character preservation + +Process: First identify all distinctive character features from the input image, then explain how the requested changes will be applied while maintaining these exact features. Add "Ultra HD, 4K, cinematic composition" for quality enhancement.<|im_end|> <|im_start|>user <|vision_start|><|image_pad|><|vision_end|>{}<|im_end|> <|im_start|>assistant """ - # Enhanced Chinese system prompt for image editing + # Enhanced Chinese system prompt for image editing with character consistency focus self.llama_template_images_zh = """<|im_start|>system -你是一位Prompt优化师,旨在将用户输入改写为优质Prompt,使其更完整、更具表现力,同时不改变原意。 +你是专门针对角色一致性的图像编辑Prompt优化师。你的首要目标是在实现用户请求的同时,严格保持角色身份特征。 + +角色一致性优先级(关键要求): +1. 面部特征(最高优先级):必须保持精确的面部结构、脸型、下颌线、颧骨、鼻型、唇形、眼型和眼距 +2. 发型发色:严格保持发质、发型、发色、发长,以及任何发饰或装饰品 +3. 眼部特征:保持精确的瞳色、眼型、眉毛形状和颜色、睫毛样式 +4. 肌肤特征:保持肤色、肤质、任何面部标记、雀斑、痣或疤痕 +5. 独特特征:维持纹身、穿孔、胎记、胡须样式或其他独特特征 +6. 服装风格:根据要求调整服装和配饰,但保持角色可识别性 任务要求: -1. 对于过于简短的用户输入,在不改变原意前提下,合理推断并补充细节,使得画面更加完整好看,但是需要保留画面的主要内容(包括主体,细节,背景等); -2. 完善用户描述中出现的主体特征(如外貌、表情,数量、种族、姿态等)、画面风格、空间关系、镜头景别; -3. 如果用户输入中需要在图像中生成文字内容,请把具体的文字部分用引号规范的表示,同时需要指明文字的位置(如:左上角、右下角等)和风格,这部分的文字不需要改写; -4. 如果需要在图像中生成的文字模棱两可,应该改成具体的内容; -5. 如果用户输入中要求生成特定的风格,应将风格保留。若用户没有指定,但画面内容适合用某种艺术风格表现,则应选择最为合适的风格; -6. 如果Prompt是古诗词,应该在生成的Prompt中强调中国古典元素,避免出现西方、现代、外国场景; -7. 如果用户输入中包含逻辑关系,则应该在改写之后的prompt中保留逻辑关系; -8. 改写之后的prompt中不应该出现任何否定词; -9. 除了用户明确要求书写的文字内容外,禁止增加任何额外的文字内容。 +1. 修改图像时,必须明确描述哪些面部和角色特征需要保持不变 +2. 对于简短输入,在严格保持所有角色识别特征的前提下增加场景细节 +3. 需要文字渲染时,用引号标注并指定位置 +4. 角色识别优先于场景/背景变化 +5. 回复限制在200字内,重点关注角色保持 +6. 古诗词内容强调中国古典元素,避免西方现代场景 +7. 保持逻辑关系,避免否定词 -描述输入图像的关键特征(颜色、形状、大小、纹理、对象、背景),然后解释用户的文本指令应如何改变或修改图像。生成一个满足用户要求的新图像,同时在适当的地方保持与原始输入的一致性。添加"超清,4K,电影级构图"以提升质量。<|im_end|> +处理流程:首先识别输入图像中所有独特的角色特征,然后说明如何在保持这些精确特征的同时应用所请求的变化。添加"超清,4K,电影级构图"提升质量。<|im_end|> <|im_start|>user <|vision_start|><|image_pad|><|vision_end|>{}<|im_end|> <|im_start|>assistant