Skip to content

Instantly share code, notes, and snippets.

@safa-dayo
Last active January 12, 2026 01:31
Show Gist options
  • Select an option

  • Save safa-dayo/d9fed369feadb36aaf0e95e8c539a668 to your computer and use it in GitHub Desktop.

Select an option

Save safa-dayo/d9fed369feadb36aaf0e95e8c539a668 to your computer and use it in GitHub Desktop.
Qwen-Image-EditをGoogle Colab上のComfyUIで試すためのColabノートブック
# #@title Qwen-Image-Edit with ComfyUI
#@markdown ---
### setup ComfyUI ###
from pathlib import Path
OPTIONS = {}
USE_GOOGLE_DRIVE = False #@param {type:"boolean"}
UPDATE_COMFY_UI = True #@param {type:"boolean"}
USE_COMFYUI_MANAGER = True #@param {type:"boolean"}
INSTALL_CUSTOM_NODES_DEPENDENCIES = True #@param {type:"boolean"}
OPTIONS['USE_GOOGLE_DRIVE'] = USE_GOOGLE_DRIVE
OPTIONS['UPDATE_COMFY_UI'] = UPDATE_COMFY_UI
OPTIONS['USE_COMFYUI_MANAGER'] = USE_COMFYUI_MANAGER
OPTIONS['INSTALL_CUSTOM_NODES_DEPENDENCIES'] = INSTALL_CUSTOM_NODES_DEPENDENCIES
current_dir = !pwd
WORKSPACE = f"{current_dir[0]}/ComfyUI"
if OPTIONS['USE_GOOGLE_DRIVE']:
!echo "Mounting Google Drive..."
%cd /
from google.colab import drive
drive.mount('/content/drive')
WORKSPACE = "/content/drive/MyDrive/ComfyUI"
%cd /content/drive/MyDrive
![ ! -d $WORKSPACE ] && echo -= Initial setup ComfyUI =- && git clone https://github.com/comfyanonymous/ComfyUI
%cd $WORKSPACE
if OPTIONS['UPDATE_COMFY_UI']:
!echo -= Updating ComfyUI =-
!git pull
!echo -= Install dependencies =-
!pip3 install accelerate
!pip3 install einops transformers>=4.28.1 safetensors>=0.4.2 aiohttp pyyaml Pillow scipy tqdm psutil tokenizers>=0.13.3
!pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121
!pip3 install torchsde
!pip3 install kornia>=0.7.1 spandrel soundfile sentencepiece
!pip3 install av
if OPTIONS['USE_COMFYUI_MANAGER']:
%cd custom_nodes
![ ! -d ComfyUI-Manager ] && echo -= Initial setup ComfyUI-Manager =- && git clone https://github.com/ltdrdata/ComfyUI-Manager
%cd ComfyUI-Manager
!git pull
%cd $WORKSPACE
if OPTIONS['INSTALL_CUSTOM_NODES_DEPENDENCIES']:
!echo -= Install custom nodes dependencies =-
!pip install GitPython
!python custom_nodes/ComfyUI-Manager/cm-cli.py restore-dependencies
# 生成時にエラーになるため以下を事前にインストール
!pip install comfy-kitchen>=0.2.0
### Qwen-Image / Qwen-Image-Edit models download ###
#@markdown ---
#@markdown ### どのQwenモデルを使うか選択(※いずれか1つだけTrueにしてください)
#@markdown - Qwen-Image 2512(fp8: 推奨)
use_qwen_image_2512_fp8 = False #@param {type:"boolean"}
#@markdown - Qwen-Image 2512(bf16: VRAMに余裕がある場合)
use_qwen_image_2512_bf16 = False #@param {type:"boolean"}
#@markdown - Qwen-Image-Edit 2511(最新)
use_qwen_image_edit_2511 = True #@param {type:"boolean"}
#@markdown - Qwen-Image-Edit 2509
use_qwen_image_edit_2509 = False #@param {type:"boolean"}
#@markdown - Qwen-Image-Edit Default
use_qwen_image_edit_default = False #@param {type:"boolean"}
#@markdown - Qwen-Image Default(fp8)
use_qwen_image_default = False #@param {type:"boolean"}
#@markdown ---
#@markdown ### 任意:4ステップLightning LoRAを一緒に取得するか
DOWNLOAD_LIGHTNING_LORA = False #@param {type:"boolean"}
#@markdown ### 任意:Anything2Real 2601 LoRAを取得するか
DOWNLOAD_ANYTHING2REAL_LORA = False #@param {type:"boolean"}
#@markdown ### 任意:Multiple Angles LoRA(Qwen-Image-Edit-2511向け)を取得するか
DOWNLOAD_MULTIPLE_ANGLES_LORA = False #@param {type:"boolean"}
# Diffusion Model
# from: Comfy-Org/Qwen-Image_ComfyUI / Comfy-Org/Qwen-Image-Edit_ComfyUI
if use_qwen_image_2512_fp8:
!wget -c -O $WORKSPACE/models/diffusion_models/qwen_image_2512_fp8_e4m3fn.safetensors \
"https://huggingface.co/Comfy-Org/Qwen-Image_ComfyUI/resolve/main/split_files/diffusion_models/qwen_image_2512_fp8_e4m3fn.safetensors"
elif use_qwen_image_2512_bf16:
!wget -c -O $WORKSPACE/models/diffusion_models/qwen_image_2512_bf16.safetensors \
"https://huggingface.co/Comfy-Org/Qwen-Image_ComfyUI/resolve/main/split_files/diffusion_models/qwen_image_2512_bf16.safetensors"
elif use_qwen_image_edit_2511:
!wget -c -O $WORKSPACE/models/diffusion_models/qwen_image_edit_2511_bf16.safetensors \
"https://huggingface.co/Comfy-Org/Qwen-Image-Edit_ComfyUI/resolve/main/split_files/diffusion_models/qwen_image_edit_2511_bf16.safetensors"
!wget -c https://huggingface.co/lightx2v/Qwen-Image-Edit-2511-Lightning/resolve/main/Qwen-Image-Edit-2511-Lightning-4steps-V1.0-bf16.safetensors \
--directory-prefix=$WORKSPACE/models/loras || true
elif use_qwen_image_edit_2509:
!wget -c -O $WORKSPACE/models/diffusion_models/qwen_image_edit_2509_fp8_e4m3fn.safetensors \
"https://huggingface.co/Comfy-Org/Qwen-Image-Edit_ComfyUI/resolve/main/split_files/diffusion_models/qwen_image_edit_2509_fp8_e4m3fn.safetensors?download=1"
elif use_qwen_image_edit_default:
!wget -c https://huggingface.co/Comfy-Org/Qwen-Image-Edit_ComfyUI/resolve/main/split_files/diffusion_models/qwen_image_edit_fp8_e4m3fn.safetensors \
--directory-prefix=$WORKSPACE/models/diffusion_models
elif use_qwen_image_default:
!wget -c https://huggingface.co/Comfy-Org/Qwen-Image_ComfyUI/resolve/main/split_files/diffusion_models/qwen_image_fp8_e4m3fn.safetensors \
--directory-prefix=$WORKSPACE/models/diffusion_models
else:
!wget -c https://huggingface.co/Comfy-Org/Qwen-Image-Edit_ComfyUI/resolve/main/split_files/diffusion_models/qwen_image_edit_fp8_e4m3fn.safetensors \
--directory-prefix=$WORKSPACE/models/diffusion_models
# Text Encoder (Qwen2.5-VL 7B・FP8)
# from: Comfy-Org/Qwen-Image_ComfyUI
!wget -c https://huggingface.co/Comfy-Org/Qwen-Image_ComfyUI/resolve/main/split_files/text_encoders/qwen_2.5_vl_7b_fp8_scaled.safetensors \
--directory-prefix=$WORKSPACE/models/text_encoders
# VAE
# from: Comfy-Org/Qwen-Image_ComfyUI
!wget -c https://huggingface.co/Comfy-Org/Qwen-Image_ComfyUI/resolve/main/split_files/vae/qwen_image_vae.safetensors \
--directory-prefix=$WORKSPACE/models/vae
# Optional: 4-step Lightning LoRA(高速化用、必要なときだけ)
if DOWNLOAD_LIGHTNING_LORA:
!wget -c https://huggingface.co/lightx2v/Qwen-Image-Lightning/resolve/main/Qwen-Image-Lightning-4steps-V1.0.safetensors \
--directory-prefix=$WORKSPACE/models/loras || true
# Optional: Anything2Real 2601 LoRA(Qwen Edit 2511向け)
if DOWNLOAD_ANYTHING2REAL_LORA:
!wget -c -O $WORKSPACE/models/loras/anything2real_2601.safetensors \
"https://huggingface.co/lrzjason/Anything2Real_2601/resolve/main/anything2real_2601.safetensors" || true
# Optional: Multiple Angles LoRA(Qwen Image Edit 2511向け)
if DOWNLOAD_MULTIPLE_ANGLES_LORA:
%cd $WORKSPACE/custom_nodes
![ ! -d ComfyUI-qwenmultiangle ] && echo -= Initial setup ComfyUI-qwenmultiangle =- && git clone https://github.com/jtydhr88/ComfyUI-qwenmultiangle
%cd ComfyUI-qwenmultiangle
!git pull
%cd $WORKSPACE
!wget -c -O $WORKSPACE/models/loras/qwen-image-edit-2511-multiple-angles-lora.safetensors \
"https://huggingface.co/fal/Qwen-Image-Edit-2511-Multiple-Angles-LoRA/resolve/main/qwen-image-edit-2511-multiple-angles-lora.safetensors" || true
### start ComfyUI with cloudflared ###
!wget -P ~ https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64.deb
!dpkg -i ~/cloudflared-linux-amd64.deb
import subprocess
import threading
import time
import socket
import urllib.request
def iframe_thread(port):
while True:
time.sleep(0.5)
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
result = sock.connect_ex(('127.0.0.1', port))
if result == 0:
break
sock.close()
print("\nComfyUI finished loading, trying to launch cloudflared (if it gets stuck here cloudflared is having issues)\n")
p = subprocess.Popen(["cloudflared", "tunnel", "--url", "http://127.0.0.1:{}".format(port)], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
for line in p.stderr:
l = line.decode()
if "trycloudflare.com " in l:
print("This is the URL to access ComfyUI:", l[l.find("http"):], end='')
threading.Thread(target=iframe_thread, daemon=True, args=(8188,)).start()
!python main.py --dont-print-server
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment