RioShiina commited on
Commit
1062edc
·
verified ·
1 Parent(s): 266f72f

refactor: simplify Qwen-Image-2.1 prompt enhancer and update dependencies

Browse files
chain_injectors/qwen_image_2_1_prompt_enhancer_injector.py CHANGED
@@ -9,8 +9,8 @@ the generation workflow:
9
  - I2I / Reference: qwen3.5_9b_qwen_image_2.1_pe_i2i.int8_convrot.safetensors
10
  - Handles single or multi-reference inputs: multiple reference images are stitched into
11
  a structured grid layout via ComfyUI native ImageStitch nodes and scaled via ImageScaleToTotalPixels.
12
- - Supports reasoning mode (thinking=True) with automatic reasoning tag stripping via RegexReplace
13
- (^.*?</think>\\s*) to prevent thought chain text from contaminating downstream image conditioning.
14
  """
15
 
16
  try:
@@ -238,22 +238,8 @@ def inject(assembler, chain_definition, chain_items):
238
  text_gen_node['inputs'] = text_gen_inputs
239
  assembler.workflow[text_gen_node_id] = text_gen_node
240
 
241
- # 4. Insert Replace Text (Regex) node if thinking is enabled to strip reasoning tags
242
- if thinking_enabled:
243
- regex_node_id = assembler._get_unique_id()
244
- regex_node = create_node(assembler, "RegexReplace", "Replace Text (Regex)")
245
- regex_node['inputs'] = {
246
- "string": [text_gen_node_id, 0],
247
- "regex_pattern": "^.*?</think>\\s*",
248
- "replace": "",
249
- "case_insensitive": True,
250
- "multiline": False,
251
- "dotall": True,
252
- "count": 0
253
- }
254
- assembler.workflow[regex_node_id] = regex_node
255
- target_node['inputs']['prompt'] = [regex_node_id, 0]
256
- print(f"[Injector] Qwen-Image-2.1 Prompt Enhancer applied successfully with RegexReplace ({'I2I' if has_load_image else 'T2I'}, clip='{clip_model_name}', thinking=True).")
257
- else:
258
- target_node['inputs']['prompt'] = [text_gen_node_id, 0]
259
- print(f"[Injector] Qwen-Image-2.1 Prompt Enhancer applied successfully ({'I2I' if has_load_image else 'T2I'}, clip='{clip_model_name}', thinking=False).")
 
9
  - I2I / Reference: qwen3.5_9b_qwen_image_2.1_pe_i2i.int8_convrot.safetensors
10
  - Handles single or multi-reference inputs: multiple reference images are stitched into
11
  a structured grid layout via ComfyUI native ImageStitch nodes and scaled via ImageScaleToTotalPixels.
12
+ - Supports reasoning mode (thinking=True) leveraging ComfyUI TextGenerate native reasoning separation
13
+ (output slot 0 outputs clean prompt text, while output slot 1 isolates reasoning chain).
14
  """
15
 
16
  try:
 
238
  text_gen_node['inputs'] = text_gen_inputs
239
  assembler.workflow[text_gen_node_id] = text_gen_node
240
 
241
+ # 4. Connect TextGenerate output directly to target node prompt
242
+ # ComfyUI TextGenerate node natively strips reasoning tags (<think>...</think>) into output slot 1,
243
+ # leaving clean enhanced prompt in output slot 0.
244
+ target_node['inputs']['prompt'] = [text_gen_node_id, 0]
245
+ print(f"[Injector] Qwen-Image-2.1 Prompt Enhancer applied successfully ({'I2I' if has_load_image else 'T2I'}, clip='{clip_model_name}', thinking={thinking_enabled}).")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
requirements.txt CHANGED
@@ -1,10 +1,9 @@
1
  comfyui-frontend-package==1.53.6
2
- comfyui-workflow-templates==0.11.66
3
  comfyui-embedded-docs==0.5.12
4
  torch
5
  torchsde
6
  torchvision
7
- torchaudio
8
  numpy>=1.25.0
9
  einops
10
  transformers>=4.50.3
 
1
  comfyui-frontend-package==1.53.6
2
+ comfyui-workflow-templates==0.11.68
3
  comfyui-embedded-docs==0.5.12
4
  torch
5
  torchsde
6
  torchvision
 
7
  numpy>=1.25.0
8
  einops
9
  transformers>=4.50.3