Transform your 3D texturing workflow with the power of generative AI, directly within Blender!
initial qwen-image-edit integration
sakalond1449a6062bc5
diff --git a/stablegen/__init__.py b/stablegen/__init__.pyindex 1d4cf05..6897757 100755--- a/stablegen/__init__.py+++ b/stablegen/__init__.py@@ -719,12 +719,15 @@ class RefreshCheckpointList(bpy.types.Operator):if context.scene.model_architecture == 'sdxl':model_list = fetch_from_comfyui_api(context, "/models/checkpoints")model_type_desc = "Checkpoint"- else: # flux1+ elif context.scene.model_architecture == 'flux1':model_list = fetch_from_comfyui_api(context, "/models/unet_gguf")to_extend = fetch_from_comfyui_api(context, "/models/diffusion_models")if to_extend:model_list.extend(to_extend)model_type_desc = "UNET"+ elif context.scene.model_architecture == 'qwen_image_edit':+ model_list = fetch_from_comfyui_api(context, "/models/unet_gguf")+ model_type_desc = "UNET (GGUF)"if model_list is None: # Config error_cached_checkpoint_list = [("NO_SERVER", "Set Server Address", "Cannot fetch")]@@ -1251,6 +1254,22 @@ def register():default='first',update=update_parameters)+ bpy.types.Scene.sequential_desaturate_factor = bpy.props.FloatProperty(+ name="Desaturate Recent Image",+ description="Desaturation factor for the 'most recent' image to prevent color stacking. 0.0 is no change, 1.0 is fully desaturated",+ default=0.0,+ min=0.0,+ max=1.0,+ update=update_parameters+ )+ bpy.types.Scene.sequential_contrast_factor = bpy.props.FloatProperty(+ name="Reduce Contrast of Recent Image",+ description="Contrast reduction factor for the 'most recent' image to prevent contrast stacking. 0.0 is no change, 1.0 is maximum reduction (grey)",+ default=0.0,+ min=0.0,+ max=1.0,+ update=update_parameters+ )bpy.types.Scene.sequential_ipadapter_regenerate = bpy.props.BoolProperty(name="Regenerate IPAdapter",description="IPAdapter generations may differ from the original image. This option regenerates the first viewpoint with IPAdapter to match the rest of the images.",@@ -1588,12 +1607,51 @@ def register():description="Select the model architecture to use for generation",items=[('sdxl', 'SDXL', ''),- ('flux1', 'Flux 1', '')+ ('flux1', 'Flux 1', ''),+ ('qwen_image_edit', 'Qwen Image Edit', '')],default='sdxl',update=update_combined)+ bpy.types.Scene.qwen_guidance_map_type = bpy.props.EnumProperty(+ name="Guidance Map",+ description="The type of guidance map to use for Qwen Image Edit",+ items=[+ ('depth', 'Depth Map', 'Use depth map for structural guidance'),+ ('normal', 'Normal Map', 'Use normal map for structural guidance')+ ],+ default='depth',+ update=update_parameters+ )++ bpy.types.Scene.qwen_context_render_mode = bpy.props.EnumProperty(+ name="Context Render",+ description="How to use the RGB context render in sequential mode for Qwen",+ items=[+ ('NONE', 'Disabled', 'Do not use the RGB context render'),+ ('REPLACE_STYLE', 'Replace Style Image', 'Use context render instead of the previous generated image as the style reference'),+ ('ADDITIONAL', 'Additional Context', 'Use context render as an additional image input (image 3) for context')+ ],+ default='NONE',+ update=update_parameters+ )++ bpy.types.Scene.qwen_use_external_style_image = bpy.props.BoolProperty(+ name="Use External Style Image",+ description="Use a separate, external image as the style reference for all viewpoints",+ default=False,+ update=update_parameters+ )++ bpy.types.Scene.qwen_external_style_image = bpy.props.StringProperty(+ name="Style Reference Image",+ description="Path to the external style reference image",+ default="",+ subtype='FILE_PATH',+ update=update_parameters+ )+bpy.types.Scene.output_timestamp = bpy.props.StringProperty(name="Output Timestamp",description="Timestamp for generation output directory",@@ -1798,6 +1856,8 @@ def unregister():del bpy.types.Scene.ipadapter_enddel bpy.types.Scene.sequential_ipadapterdel bpy.types.Scene.sequential_ipadapter_mode+ del bpy.types.Scene.sequential_desaturate_factor+ del bpy.types.Scene.sequential_contrast_factordel bpy.types.Scene.sequential_ipadapter_regeneratedel bpy.types.Scene.ipadapter_weight_typedel bpy.types.Scene.clip_skip@@ -1817,7 +1877,11 @@ def unregister():del bpy.types.Scene.early_priority_strengthdel bpy.types.Scene.early_prioritydel bpy.types.Scene.texture_objects-+ del bpy.types.Scene.qwen_guidance_map_type+ del bpy.types.Scene.qwen_context_render_mode+ del bpy.types.Scene.qwen_use_external_style_image+ del bpy.types.Scene.qwen_external_style_image+for cls in reversed(classes):bpy.utils.unregister_class(cls)diff --git a/stablegen/generator.py b/stablegen/generator.pyindex e831c64..8ef3f89 100644--- a/stablegen/generator.py+++ b/stablegen/generator.py@@ -13,9 +13,9 @@ import jsonfrom datetime import datetimeimport math-from PIL import Image+from PIL import Image, ImageEnhance-from .util.helpers import prompt_text, prompt_text_img2img # pylint: disable=relative-beyond-top-level+from .util.helpers import prompt_text, prompt_text_img2img, prompt_text_qwen_image_edit # pylint: disable=relative-beyond-top-levelfrom .render_tools import export_emit_image, export_visibility, export_canny, bake_texture, prepare_baking, unwrap # pylint: disable=relative-beyond-top-levelfrom .utils import get_last_material_index, get_generation_dirs, get_file_path, get_dir_path, remove_empty_dirs # pylint: disable=relative-beyond-top-levelfrom .project import project_image, reinstate_compare_nodes # pylint: disable=relative-beyond-top-level@@ -160,7 +160,7 @@ class Reproject(bpy.types.Operator)::return: {'FINISHED'}"""if context.scene.texture_objects == 'all':- to_texture = [obj for obj in bpy.context.view.objects if obj.type == 'MESH' and not obj.hide_get()]+ to_texture = [obj for obj in bpy.context.view_layer.objects if obj.type == 'MESH' and not obj.hide_get()]else: # selectedto_texture = [obj for obj in bpy.context.selected_objects if obj.type == 'MESH']@@ -541,7 +541,7 @@ class ComfyUIGenerate(bpy.types.Operator):if context.scene.generation_mode == 'standard':# If there is depth controlnet unit- if any(unit["unit_type"] == "depth" for unit in controlnet_units) or (context.scene.use_flux_lora and context.scene.model_architecture == 'flux1'):+ if any(unit["unit_type"] == "depth" for unit in controlnet_units) or (context.scene.use_flux_lora and context.scene.model_architecture == 'flux1') or (context.scene.model_architecture == 'qwen_image_edit' and context.scene.qwen_guidance_map_type == 'depth'):if context.scene.generation_method != 'uv_inpaint':# Export depth maps for each camerafor i, camera in enumerate(self._cameras):@@ -559,7 +559,7 @@ class ComfyUIGenerate(bpy.types.Operator):if context.scene.generation_method == 'grid':self.combine_maps(context, self._cameras, type="canny")# If there is normal controlnet unit- if any(unit["unit_type"] == "normal" for unit in controlnet_units):+ if any(unit["unit_type"] == "normal" for unit in controlnet_units) or (context.scene.model_architecture == 'qwen_image_edit' and context.scene.qwen_guidance_map_type == 'normal'):if context.scene.generation_method != 'uv_inpaint':# Export normal maps for each camerafor i, camera in enumerate(self._cameras):@@ -816,7 +816,7 @@ class ComfyUIGenerate(bpy.types.Operator):# End Prepare Image Info# Generate image without ControlNet if needed- if context.scene.generation_mode == 'standard' and camera_id == 0 and (context.scene.generation_method == 'sequential' or context.scene.generation_method == 'separate' or context.scene.generation_method == 'refine')\+ if context.scene.generation_mode == 'standard' and camera_id == 0 and (context.scene.generation_method == 'sequential' or context.scene.generation_method == 'refine')\and context.scene.sequential_ipadapter and context.scene.sequential_ipadapter_regenerate and not context.scene.use_ipadapter and context.scene.sequential_ipadapter_mode == 'first':self._stage = "Generating Reference Image"# Don't use ControlNet for the first image if sequential_ipadapter_regenerate_wo_controlnet is enabled@@ -843,6 +843,8 @@ class ComfyUIGenerate(bpy.types.Operator):if self._current_image == 0:if context.scene.model_architecture == 'flux1':image = self.generate_flux(context, controlnet_info=controlnet_info, ipadapter_ref_info=ipadapter_ref_info)+ elif context.scene.model_architecture == 'qwen_image_edit':+ image = self.generate_qwen_edit(context, camera_id=camera_id)else:image = self.generate(context, controlnet_info=controlnet_info, ipadapter_ref_info=ipadapter_ref_info)else:@@ -860,11 +862,15 @@ class ComfyUIGenerate(bpy.types.Operator):mask_info = self._get_uploaded_image_info(context, "inpaint", subtype="visibility", camera_id=self._current_image)if context.scene.model_architecture == 'flux1':image = self.refine_flux(context, controlnet_info=controlnet_info, render_info=render_info, mask_info=mask_info, ipadapter_ref_info=ipadapter_ref_info)+ elif context.scene.model_architecture == 'qwen_image_edit':+ image = self.generate_qwen_edit(context, camera_id=camera_id)else:image = self.refine(context, controlnet_info=controlnet_info, render_info=render_info, mask_info=mask_info, ipadapter_ref_info=ipadapter_ref_info)else: # Grid or Separateif context.scene.model_architecture == 'flux1':image = self.generate_flux(context, controlnet_info=controlnet_info, ipadapter_ref_info=ipadapter_ref_info)+ elif context.scene.model_architecture == 'qwen_image_edit':+ image = self.generate_qwen_edit(context, camera_id=camera_id)else:image = self.generate(context, controlnet_info=controlnet_info, ipadapter_ref_info=ipadapter_ref_info)@@ -1006,6 +1012,140 @@ class ComfyUIGenerate(bpy.types.Operator):elif context.scene.control_after_generate == 'randomize':context.scene.seed = np.random.randint(0, 1000000)+ def generate_qwen_edit(self, context, camera_id=None):+ """Generates an image using the Qwen-Image-Edit workflow."""+ server_address = context.preferences.addons[__package__].preferences.server_address+ client_id = str(uuid.uuid4())+ revision_dir = get_generation_dirs(context)["revision"]++ prompt = json.loads(prompt_text_qwen_image_edit)++ NODES = {+ 'sampler': "1",+ 'save_image': "5",+ 'pos_prompt': "12",+ 'neg_prompt': "11",+ 'guidance_map_loader': "14", # Image 1 (structure)+ 'style_map_loader': "15", # Image 2 (style)+ 'context_render_loader': "16", # Image 3 (context render)+ }++ # --- Configure Inputs ---+ guidance_map_type = context.scene.qwen_guidance_map_type+ guidance_map_info = self._get_uploaded_image_info(context, "controlnet", subtype=guidance_map_type, camera_id=camera_id)+ if not guidance_map_info:+ self._error = f"Could not find or upload {guidance_map_type} map for camera {camera_id}."+ return {"error": "conn_failed"}+ prompt[NODES['guidance_map_loader']]['inputs']['image'] = guidance_map_info['name']++ # --- Configure Style Image (Image 2) and Prompts ---+ user_prompt = context.scene.comfyui_prompt+ style_image_info = None+ context_render_info = None+ context_mode = context.scene.qwen_context_render_mode+ remove_context = False++ # --- Camera Prompt Injection ---+ if context.scene.use_camera_prompts and context.scene.generation_method in ['separate', 'sequential', 'refine'] and self._cameras and self._current_image < len(self._cameras):+ current_camera_name = self._cameras[self._current_image].name+ # Find the prompt in the collection+ prompt_item = next((item for item in context.scene.camera_prompts if item.name == current_camera_name), None)+ if prompt_item and prompt_item.prompt:+ view_desc = prompt_item.prompt+ # Prepend the view description+ user_prompt = f"{view_desc}, {user_prompt}"++ # --- Handle Context Render (Image 3) ---+ # This is only active in sequential mode after the first image+ if context.scene.generation_method == 'sequential' and self._current_image > 0 and context_mode != 'NONE':+ context_render_info = self._get_uploaded_image_info(context, "inpaint", subtype="render", camera_id=camera_id)+ if not context_render_info:+ self._error = f"Qwen context render enabled, but could not find context render for camera {camera_id}."+ return {"error": "conn_failed"}++ if context_mode == 'ADDITIONAL':+ # Switch context loader and style loader ids+ NODES['context_render_loader'], NODES['style_map_loader'] = NODES['style_map_loader'], NODES['context_render_loader']+ prompt[NODES['context_render_loader']]['inputs']['image'] = context_render_info['name']+ # The prompt needs to reference image 3+ prompt[NODES['pos_prompt']]['inputs']['prompt'] = f"Change and transfer the format of image 1 to '{user_prompt}'. Image 2 contains the unfinished image, where the magenta areas need to be completely filled in. Only transfer the style from the completed part of the image. Remove all the magenta areas. Make sure there are no artifacts left behind from the magenta areas. Image 3 represents the overall style of the object."+ # prompt[NODES['pos_prompt']]['inputs']['prompt'] = f"Change and transfer the format of {user_prompt} in image 1 to the style from image 2. Image 3 contains the unfinished image, where the magenta areas need to be replaced and completed."+ # If mode is REPLACE_STYLE, we will handle it in the style image section below.+ else:+ remove_context = True+ else:+ remove_context = True++ if remove_context:+ del prompt[NODES['context_render_loader']]+ del prompt[NODES['pos_prompt']]['inputs']['image3']+ del prompt[NODES['neg_prompt']]['inputs']['image3']+++ # --- Handle Style Image (Image 2) ---+ # Case 1: External Style Image for all viewpoints+ if context.scene.qwen_use_external_style_image:+ style_image_info = self._get_uploaded_image_info(context, "custom", filename=bpy.path.abspath(context.scene.qwen_external_style_image))+ if not style_image_info:+ self._error = "External style image enabled, but file not found or could not be uploaded."+ return {"error": "conn_failed"}+ if context_mode != 'ADDITIONAL':+ prompt[NODES['pos_prompt']]['inputs']['prompt'] = f"Change and transfer the format of '{user_prompt}' in image 1 to the style from image 2"++ # Case 2: Sequential generation (after first image)+ elif context.scene.generation_method == 'sequential' and self._current_image > 0:+ if context_mode == 'REPLACE_STYLE':+ # The context render becomes the style image+ style_image_info = context_render_info+ prompt[NODES['pos_prompt']]['inputs']['prompt'] = f"Change and transfer the format of image 1 to '{user_prompt}'. Replace all solid magenta areas in image 2. Replace the background with solid gray. The style from image 2 should smoothly continue into the previously magenta areas."+ elif context.scene.sequential_ipadapter: # Use previous generated image+ ref_cam_id = 0 if context.scene.sequential_ipadapter_mode == 'first' else self._current_image - 1+ style_image_info = self._get_uploaded_image_info(context, "generated", camera_id=ref_cam_id, material_id=self._material_id)+ if not style_image_info:+ self._error = f"Sequential mode error: Could not find previous image for camera {ref_cam_id} to use as style."+ return {"error": "conn_failed"}+ if context_mode != 'ADDITIONAL':+ prompt[NODES['pos_prompt']]['inputs']['prompt'] = f"Change and transfer the format of '{user_prompt}' in image 1 to the style from image 2"+ # If neither of the above, style_image_info remains None, handled below++ # Case 3: First image of a sequence, or separate generation, or no style source in sequential+ if style_image_info is None:+ # No style image is provided. For the first image, we remove image2 entirely.+ del prompt[NODES['style_map_loader']]+ del prompt[NODES['pos_prompt']]['inputs']['image2']+ del prompt[NODES['neg_prompt']]['inputs']['image2']+ prompt[NODES['pos_prompt']]['inputs']['prompt'] = f"Change the format of image 1 to '{user_prompt}'"+ else:+ # A style image is provided, so set the loader input.+ prompt[NODES['style_map_loader']]['inputs']['image'] = style_image_info['name']++ # --- Configure Sampler ---+ prompt[NODES['sampler']]['inputs']['seed'] = context.scene.seed+ prompt[NODES['sampler']]['inputs']['steps'] = context.scene.steps+ prompt[NODES['sampler']]['inputs']['cfg'] = context.scene.cfg+ prompt[NODES['sampler']]['inputs']['sampler_name'] = context.scene.sampler+ prompt[NODES['sampler']]['inputs']['scheduler'] = context.scene.scheduler+ prompt[NODES['sampler']]['inputs']['denoise'] = 1.0 # Typically 1.0 for this kind of edit++ # --- Execute ---+ self._save_prompt_to_file(prompt, revision_dir)+ ws = self._connect_to_websocket(server_address, client_id)+ if ws is None:+ return {"error": "conn_failed"}++ images = None+ try:+ images = self._execute_prompt_and_get_images(ws, prompt, client_id, server_address, NODES)+ finally:+ if ws:+ ws.close()++ if images is None or (isinstance(images, dict) and "error" in images):+ return {"error": "conn_failed"}++ print(f"Qwen image generated with prompt: {prompt[NODES['pos_prompt']]['inputs']['prompt']}")+ return images[NODES['save_image']][0]+def _get_uploaded_image_info(self, context, file_type, subtype=None, filename=None, camera_id=None, object_name=None, material_id=None):"""Gets local path, uploads if needed, caches, and returns ComfyUI upload info.@@ -1034,6 +1174,43 @@ class ComfyUIGenerate(bpy.types.Operator):else:local_path = filename+ # --- Image Modification for 'recent' sequential mode ---+ # Check if we need to modify the image before uploading+ is_recent_mode_ref = (+ file_type == "generated" and+ context.scene.sequential_ipadapter_mode == 'recent' and+ (context.scene.sequential_ipadapter or context.scene.model_architecture == 'qwen_image_edit')+ )++ temp_image_path = None+ upload_path = local_path++ if is_recent_mode_ref:+ desaturate = context.scene.sequential_desaturate_factor+ contrast = context.scene.sequential_contrast_factor++ if desaturate > 0.0 or contrast > 0.0:+ try:+ with Image.open(local_path) as img:+ if desaturate > 0.0:+ enhancer = ImageEnhance.Color(img)+ img = enhancer.enhance(1.0 - desaturate)++ if contrast > 0.0:+ enhancer = ImageEnhance.Contrast(img)+ img = enhancer.enhance(1.0 - contrast)++ # Save to a temporary file for upload+ temp_dir = get_dir_path(context, "temp")+ os.makedirs(temp_dir, exist_ok=True)+ temp_image_path = os.path.join(temp_dir, f"temp_{os.path.basename(local_path)}")+ img.save(temp_image_path)+ upload_path = temp_image_path+ except Exception as e:+ print(f"Error modifying image {local_path}: {e}. Uploading original.")+ upload_path = local_path # Fallback to original on error+ # --- End Image Modification ---+# Use the operator's instance cache variable (self._uploaded_images_cache)if not hasattr(self, '_uploaded_images_cache') or self._uploaded_images_cache is None:# Initialize cache if it doesn't exist (e.g., first call in execute)@@ -1043,7 +1220,7 @@ class ComfyUIGenerate(bpy.types.Operator):# Check cache first using the absolute local path as the key- absolute_local_path = os.path.abspath(local_path)+ absolute_local_path = os.path.abspath(upload_path)cached_info = self._uploaded_images_cache.get(absolute_local_path)if cached_info is not None: # Can be None if previous upload failed# print(f"Debug: Using cached upload info for: {absolute_local_path}")@@ -1062,6 +1239,10 @@ class ComfyUIGenerate(bpy.types.Operator):# Store result (the info dict or None if upload failed) in cacheself._uploaded_images_cache[absolute_local_path] = uploaded_info+ # Clean up the temporary file after upload+ if temp_image_path and os.path.exists(temp_image_path):+ os.remove(temp_image_path)+if uploaded_info:return uploaded_infoelse:diff --git a/stablegen/stablegen.py b/stablegen/stablegen.pyindex 7035e12..232d179 100755--- a/stablegen/stablegen.py+++ b/stablegen/stablegen.py@@ -14,6 +14,7 @@ PRESETS = {"QUICK DRAFT": {"description": "Optimized for speed", "control_after_generate": "fixed", "model_architecture": "sdxl", "steps": 4, "cfg": 1.0, "sampler": "dpmpp_2s_ancestral", "scheduler": "sgm_uniform", "fallback_color": mathutils.Color((0.0, 0.0, 0.0)), "discard_factor": 70.0, "weight_exponent": 3.0, "clip_skip": 1, "auto_rescale": True, "overwrite_material": True, "bake_texture": False, "bake_texture_size": 2048, "bake_unwrap_method": "none", "bake_unwrap_overlap_only": True, "generation_method": "grid", "refine_images": False, "refine_steps": 8, "refine_sampler": "dpmpp_2s_ancestral", "refine_scheduler": "sgm_uniform", "denoise": 1.0, "refine_cfg": 1.5, "refine_prompt": "", "refine_upscale_method": "lanczos", "sequential_smooth": True, "sequential_custom_camera_order": "", "sequential_factor": 0.7, "sequential_factor_smooth": 0.1, "sequential_ipadapter": True, "sequential_ipadapter_mode": "first", "sequential_ipadapter_regenerate": False, "ipadapter_weight_type": "style", "ipadapter_strength": 1.0, "ipadapter_start": 0.0, "ipadapter_end": 1.0, "differential_diffusion": True, "differential_noise": True, "blur_mask": True, "blur_mask_radius": 2, "blur_mask_sigma": 1.0, "grow_mask_by": 2, "canny_threshold_low": 0, "canny_threshold_high": 80, "controlnet_units": [{'unit_type': 'depth', 'model_name': 'controlnet_depth_sdxl.safetensors', 'strength': 0.5, 'start_percent': 0.0, 'end_percent': 1.0, 'is_union': False, 'use_union_type': True}], "lora_units": [{'model_name': 'Hyper-SDXL-4steps-lora.safetensors', 'model_strength': 1.0, 'clip_strength': 1.0}]},"UV INPAINTING": {"description": "Recommended UV Inpainting setup. It is recommended to bake texutures manually before running the generation to fine-tune unwrapping and avoid lag when generating.", "control_after_generate": "fixed", "model_architecture": "sdxl", "steps": 10, "cfg": 1.5, "sampler": "dpmpp_2s_ancestral", "scheduler": "sgm_uniform", "fallback_color": mathutils.Color((0.0, 0.0, 0.0)), "discard_factor": 80.0, "clip_skip": 1, "auto_rescale": True, "overwrite_material": True, "bake_texture": False, "bake_texture_size": 2048, "bake_unwrap_method": "none", "bake_unwrap_overlap_only": True, "generation_method": "uv_inpaint", "refine_images": False, "refine_steps": 8, "refine_sampler": "dpmpp_2s_ancestral", "refine_scheduler": "sgm_uniform", "denoise": 1.0, "refine_cfg": 1.5, "refine_prompt": "", "refine_upscale_method": "lanczos", "sequential_smooth": True, "sequential_custom_camera_order": "3,0,1,2", "sequential_factor": 0.6000000238418579, "sequential_factor_smooth": 0.11000001430511475, "sequential_factor_smooth_2": 1.0, "sequential_ipadapter": True, "sequential_ipadapter_mode": "first", "sequential_ipadapter_regenerate": False, "ipadapter_weight_type": "style", "ipadapter_strength": 1.0, "ipadapter_start": 0.0, "ipadapter_end": 1.0, "differential_diffusion": True, "differential_noise": True, "blur_mask": True, "blur_mask_radius": 3, "blur_mask_sigma": 1.0, "grow_mask_by": 3, "canny_threshold_low": 0, "canny_threshold_high": 80, "lora_units": [{'model_name': 'sdxl_lightning_8step_lora.safetensors', 'model_strength': 1.0, 'clip_strength': 1.0}]}, # No ControlNet for UV Inpainting by default"ARCHITECTURE": {"description": "Prioritizes only the most straight-on camera for each point. This means details generated on flat surfaces will not get blurred by getting generated differently from two or more viewpoints. Does not use visibility masking. Each picture will get generated as new, consistency depends on IPAdapter + geometry.", "control_after_generate": "fixed", "model_architecture": "sdxl", "steps": 8, "cfg": 1.5, "sampler": "dpmpp_2s_ancestral", "scheduler": "sgm_uniform", "fallback_color": mathutils.Color((0.0, 0.0, 0.0)), "discard_factor": 80.0, "weight_exponent": 10.0, "clip_skip": 1, "auto_rescale": True, "overwrite_material": True, "bake_texture": False, "bake_texture_size": 2048, "bake_unwrap_method": "none", "bake_unwrap_overlap_only": True, "generation_method": "separate", "refine_images": False, "refine_steps": 8, "refine_sampler": "dpmpp_2s_ancestral", "refine_scheduler": "sgm_uniform", "denoise": 1.0, "refine_cfg": 1.5, "refine_prompt": "", "refine_upscale_method": "lanczos", "sequential_smooth": False, "sequential_custom_camera_order": "", "sequential_factor": 0.75, "sequential_factor_smooth": 0.15000000596046448, "sequential_factor_smooth_2": 1.0, "sequential_ipadapter": True, "sequential_ipadapter_mode": "first", "ipadapter_weight_type": "style", "ipadapter_strength": 0.800000011920929, "ipadapter_start": 0.0, "ipadapter_end": 1.0, "differential_diffusion": True, "differential_noise": False, "blur_mask": True, "blur_mask_radius": 3, "blur_mask_sigma": 1.0, "grow_mask_by": 3, "canny_threshold_low": 0, "canny_threshold_high": 80, "controlnet_units": [{'unit_type': 'depth', 'model_name': 'controlnet_depth_sdxl.safetensors', 'strength': 0.6000000238418579, 'start_percent': 0.0, 'end_percent': 1.0, 'is_union': False, 'use_union_type': True}], "lora_units": [{'model_name': 'sdxl_lightning_8step_lora.safetensors', 'model_strength': 1.0, 'clip_strength': 1.0}]},+ "QWEN IMAGE EDIT": {"description": "Recommended settings for Qwen Image Edit. Uses depth map for guidance and sequential mode for consistency.", "control_after_generate": "fixed", "model_architecture": "qwen_image_edit", "steps": 4, "cfg": 1.0, "sampler": "euler", "scheduler": "simple", "fallback_color": mathutils.Color((0.0, 0.0, 0.0)), "discard_factor": 90.0, "weight_exponent": 3.0, "clip_skip": 1, "auto_rescale": True, "overwrite_material": True, "bake_texture": False, "bake_texture_size": 2048, "bake_unwrap_method": "none", "bake_unwrap_overlap_only": True, "generation_method": "sequential", "refine_images": False, "refine_steps": 8, "refine_sampler": "dpmpp_2s_ancestral", "refine_scheduler": "sgm_uniform", "denoise": 1.0, "refine_cfg": 1.5, "refine_prompt": "", "refine_upscale_method": "lanczos", "sequential_smooth": True, "sequential_custom_camera_order": "", "sequential_factor": 0.7, "sequential_factor_smooth": 0.15, "sequential_factor_smooth_2": 1.0, "sequential_ipadapter": True, "sequential_ipadapter_mode": "first", "sequential_ipadapter_regenerate": False, "ipadapter_weight_type": "style", "ipadapter_strength": 1.0, "ipadapter_start": 0.0, "ipadapter_end": 1.0, "differential_diffusion": True, "differential_noise": True, "blur_mask": True, "blur_mask_radius": 1, "blur_mask_sigma": 1.0, "grow_mask_by": 3, "canny_threshold_low": 0, "canny_threshold_high": 80, "qwen_guidance_map_type": "depth", "qwen_use_external_style_image": False, "qwen_external_style_image": "", "qwen_context_render_mode": "NONE"},}# Global list of all generation parameter names to check for a preset.@@ -50,6 +51,8 @@ GEN_PARAMETERS = ["sequential_factor_smooth_2","sequential_ipadapter","sequential_ipadapter_mode",+ "sequential_desaturate_factor",+ "sequential_contrast_factor","sequential_ipadapter_regenerate","ipadapter_weight_type","ipadapter_strength",@@ -63,6 +66,10 @@ GEN_PARAMETERS = ["grow_mask_by","canny_threshold_low","canny_threshold_high",+ "qwen_guidance_map_type",+ "qwen_use_external_style_image",+ "qwen_external_style_image",+ "qwen_context_render_mode",]def get_preset_items(self, context):@@ -506,8 +513,41 @@ class StableGenPanel(bpy.types.Panel):# --- Image Guidance (IPAdapter & ControlNet) ---content_box = draw_collapsible_section(advanced_params_box, "show_image_guidance_settings", "Image Guidance (IPAdapter & ControlNet)", icon="MODIFIER")if content_box:+ if scene.model_architecture == 'qwen_image_edit':+ qwen_box = content_box.box()+ row = qwen_box.row()+ row.alignment = 'CENTER'+ row.label(text="Qwen Image Edit Guidance", icon="IMAGE_DATA")++ split = qwen_box.split(factor=0.5)+ split.label(text="Guidance Map:")+ split.prop(scene, "qwen_guidance_map_type", text="")++ row = qwen_box.row()+ row.prop(scene, "qwen_use_external_style_image", text="Use External Style Image", toggle=True, icon="FILE_IMAGE")++ if scene.qwen_use_external_style_image:+ row = qwen_box.row()+ row.prop(scene, "qwen_external_style_image", text="Style Image")++ if scene.generation_method == 'sequential':+ split = qwen_box.split(factor=0.5)+ split.label(text="Context Render:")+ split.prop(scene, "qwen_context_render_mode", text="")++ if scene.generation_method in ['sequential', 'separate']:+ row = qwen_box.row()+ row.prop(scene, "sequential_ipadapter", text="Use Previous Image as Style", toggle=True, icon="MODIFIER")+ if scene.sequential_ipadapter:+ sub_box = qwen_box.box()+ split = sub_box.split(factor=0.5)+ split.label(text="Mode:")+ split.prop(scene, "sequential_ipadapter_mode", text="")+ if scene.sequential_ipadapter_mode == 'recent':+ sub_box.prop(scene, "sequential_desaturate_factor", text="Desaturate")+ sub_box.prop(scene, "sequential_contrast_factor", text="Reduce Contrast")# IPAdapter Parameters- if not scene.generation_method == 'uv_inpaint':+ if not scene.generation_method == 'uv_inpaint' and not scene.model_architecture == 'qwen_image_edit':ipadapter_main_box = content_box.box() # Group IPAdapter settings togetherif scene.model_architecture == 'flux1':row = ipadapter_main_box.row()@@ -531,9 +571,10 @@ class StableGenPanel(bpy.types.Panel):split.label(text="Weight Type:")split.prop(scene, "ipadapter_weight_type", text="")- content_box.separator() # Separator between IPAdapter and ControlNet if both are shown+ if not scene.model_architecture == 'qwen_image_edit':+ content_box.separator() # Separator between IPAdapter and ControlNet if both are shown# ControlNet Parameters- if not (scene.model_architecture == 'flux1' and scene.use_flux_lora):+ if not (scene.model_architecture == 'flux1' and scene.use_flux_lora) and not scene.model_architecture == 'qwen_image_edit':ctrl_box_group = content_box.box() # Group ControlNet settings togetherrow = ctrl_box_group.row()row.alignment = 'CENTER'@@ -665,10 +706,15 @@ class StableGenPanel(bpy.types.Panel):split.label(text="Mode:")split.prop(scene, "sequential_ipadapter_mode", text="")- split = sub_ip_box_separate.split(factor=0.5)- if context.scene.model_architecture == 'sdxl':- split.label(text="Weight Type:")- split.prop(scene, "ipadapter_weight_type", text="")+ if scene.sequential_ipadapter_mode == 'recent':+ sub_ip_box_separate.prop(scene, "sequential_desaturate_factor", text="Desaturate")+ sub_ip_box_separate.prop(scene, "sequential_contrast_factor", text="Reduce Contrast")++ if context.scene.model_architecture != 'qwen_image_edit':+ split = sub_ip_box_separate.split(factor=0.5)+ if context.scene.model_architecture == 'sdxl':+ split.label(text="Weight Type:")+ split.prop(scene, "ipadapter_weight_type", text="")row = sub_ip_box_separate.row()row.prop(scene, "ipadapter_strength", text="Strength")@@ -771,11 +817,16 @@ class StableGenPanel(bpy.types.Panel):split.label(text="Mode:")split.prop(scene, "sequential_ipadapter_mode", text="")- split = sub_ip_seq_box.split(factor=0.5)- if context.scene.model_architecture == 'sdxl':- split.label(text="Weight Type:")- split.prop(scene, "ipadapter_weight_type", text="")+ if scene.sequential_ipadapter_mode == 'recent':+ sub_ip_seq_box.prop(scene, "sequential_desaturate_factor", text="Desaturate")+ sub_ip_seq_box.prop(scene, "sequential_contrast_factor", text="Reduce Contrast")+ if context.scene.model_architecture != 'qwen_image_edit':+ split = sub_ip_seq_box.split(factor=0.5)+ if context.scene.model_architecture == 'sdxl':+ split.label(text="Weight Type:")+ split.prop(scene, "ipadapter_weight_type", text="")+row = sub_ip_seq_box.row()row.prop(scene, "ipadapter_strength", text="Strength")if width_mode == 'narrow':diff --git a/stablegen/util/helpers.py b/stablegen/util/helpers.pyindex 13711b0..2c2a97b 100755--- a/stablegen/util/helpers.py+++ b/stablegen/util/helpers.py@@ -1282,3 +1282,250 @@ gguf_unet_loader = """}"""+prompt_text_qwen_image_edit = """+{+ "1": {+ "inputs": {+ "seed": 157165768450326,+ "steps": 4,+ "cfg": 1,+ "sampler_name": "euler",+ "scheduler": "simple",+ "denoise": 1,+ "model": [+ "7",+ 0+ ],+ "positive": [+ "12",+ 0+ ],+ "negative": [+ "11",+ 0+ ],+ "latent_image": [+ "8",+ 0+ ]+ },+ "class_type": "KSampler",+ "_meta": {+ "title": "KSampler"+ }+ },+ "2": {+ "inputs": {+ "samples": [+ "1",+ 0+ ],+ "vae": [+ "4",+ 0+ ]+ },+ "class_type": "VAEDecode",+ "_meta": {+ "title": "VAE Decode"+ }+ },+ "3": {+ "inputs": {+ "clip_name": "qwen_2.5_vl_7b_fp8_scaled.safetensors",+ "type": "qwen_image",+ "device": "default"+ },+ "class_type": "CLIPLoader",+ "_meta": {+ "title": "Load CLIP"+ }+ },+ "4": {+ "inputs": {+ "vae_name": "qwen_image_vae.safetensors"+ },+ "class_type": "VAELoader",+ "_meta": {+ "title": "Load VAE"+ }+ },+ "5": {+ "inputs": {+ "images": [+ "2",+ 0+ ]+ },+ "class_type": "SaveImageWebsocket",+ "_meta": {+ "title": "SaveImageWebsocket"+ }+ },+ "6": {+ "inputs": {+ "shift": 3,+ "model": [+ "9",+ 0+ ]+ },+ "class_type": "ModelSamplingAuraFlow",+ "_meta": {+ "title": "ModelSamplingAuraFlow"+ }+ },+ "7": {+ "inputs": {+ "strength": 1,+ "model": [+ "6",+ 0+ ]+ },+ "class_type": "CFGNorm",+ "_meta": {+ "title": "CFGNorm"+ }+ },+ "8": {+ "inputs": {+ "pixels": [+ "10",+ 0+ ],+ "vae": [+ "4",+ 0+ ]+ },+ "class_type": "VAEEncode",+ "_meta": {+ "title": "VAE Encode"+ }+ },+ "9": {+ "inputs": {+ "lora_name": "Qwen-Image-Lightning-4steps-V1.0.safetensors",+ "strength_model": 1,+ "model": [+ "13",+ 0+ ]+ },+ "class_type": "LoraLoaderModelOnly",+ "_meta": {+ "title": "LoraLoaderModelOnly"+ }+ },+ "10": {+ "inputs": {+ "upscale_method": "lanczos",+ "megapixels": 1,+ "image": [+ "14",+ 0+ ]+ },+ "class_type": "ImageScaleToTotalPixels",+ "_meta": {+ "title": "Scale Image to Total Pixels"+ }+ },+ "11": {+ "inputs": {+ "prompt": "",+ "clip": [+ "3",+ 0+ ],+ "vae": [+ "4",+ 0+ ],+ "image1": [+ "10",+ 0+ ],+ "image2": [+ "15",+ 0+ ],+ "image3": [+ "16",+ 0+ ]+ },+ "class_type": "TextEncodeQwenImageEditPlus",+ "_meta": {+ "title": "TextEncodeQwenImageEditPlus"+ }+ },+ "12": {+ "inputs": {+ "prompt": "a monkey",+ "clip": [+ "3",+ 0+ ],+ "vae": [+ "4",+ 0+ ],+ "image1": [+ "10",+ 0+ ],+ "image2": [+ "15",+ 0+ ],+ "image3": [+ "16",+ 0+ ]+ },+ "class_type": "TextEncodeQwenImageEditPlus",+ "_meta": {+ "title": "TextEncodeQwenImageEditPlus"+ }+ },+ "13": {+ "inputs": {+ "unet_name": "Qwen-Image-Edit-2509-Q3_K_M.gguf"+ },+ "class_type": "UnetLoaderGGUF",+ "_meta": {+ "title": "Unet Loader (GGUF)"+ }+ },+ "14": {+ "inputs": {+ "image": ""+ },+ "class_type": "LoadImage",+ "_meta": {+ "title": "Load Image"+ }+ },+ "15": {+ "inputs": {+ "image": ""+ },+ "class_type": "LoadImage",+ "_meta": {+ "title": "Load Image"+ }+ },+ "16": {+ "inputs": {+ "image": ""+ },+ "class_type": "LoadImage",+ "_meta": {+ "title": "Load Image"+ }+ }+}+"""+