Created
August 21, 2025 23:30
-
-
Save safa-dayo/d9fed369feadb36aaf0e95e8c539a668 to your computer and use it in GitHub Desktop.
Qwen-Image-EditをGoogle Colab上のComfyUIで試すためのColabノートブック
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# #@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 | |
### Qwen-Image-Edit models download ### | |
#@markdown --- | |
#@markdown ### 任意:4ステップLightning LoRAを一緒に取得するか | |
DOWNLOAD_LIGHTNING_LORA = False #@param {type:"boolean"} | |
# Diffusion Model (Qwen-Image-Edit 本体・FP8) | |
# from: Comfy-Org/Qwen-Image-Edit_ComfyUI | |
!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 | |
### 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