Last active
July 23, 2025 13:05
-
-
Save safa-dayo/e6b02ace505d323fe6a502873b09a0cf to your computer and use it in GitHub Desktop.
Wan2.1をComfyUIで試すためのGoogle 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 Environment Setup | |
### 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 =- | |
# Correction of the issue of permissions being deleted on Google Drive. | |
![ -f ".ci/nightly/update_windows/update_comfyui_and_python_dependencies.bat" ] && chmod 755 .ci/nightly/update_windows/update_comfyui_and_python_dependencies.bat | |
![ -f ".ci/nightly/windows_base_files/run_nvidia_gpu.bat" ] && chmod 755 .ci/nightly/windows_base_files/run_nvidia_gpu.bat | |
![ -f ".ci/update_windows/update_comfyui_and_python_dependencies.bat" ] && chmod 755 .ci/update_windows/update_comfyui_and_python_dependencies.bat | |
![ -f ".ci/update_windows_cu118/update_comfyui_and_python_dependencies.bat" ] && chmod 755 .ci/update_windows_cu118/update_comfyui_and_python_dependencies.bat | |
![ -f ".ci/update_windows/update.py" ] && chmod 755 .ci/update_windows/update.py | |
![ -f ".ci/update_windows/update_comfyui.bat" ] && chmod 755 .ci/update_windows/update_comfyui.bat | |
![ -f ".ci/update_windows/README_VERY_IMPORTANT.txt" ] && chmod 755 .ci/update_windows/README_VERY_IMPORTANT.txt | |
![ -f ".ci/update_windows/run_cpu.bat" ] && chmod 755 .ci/update_windows/run_cpu.bat | |
![ -f ".ci/update_windows/run_nvidia_gpu.bat" ] && chmod 755 .ci/update_windows/run_nvidia_gpu.bat | |
!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 | |
if OPTIONS['USE_COMFYUI_MANAGER']: | |
%cd custom_nodes | |
# Correction of the issue of permissions being deleted on Google Drive. | |
![ -f "ComfyUI-Manager/check.sh" ] && chmod 755 ComfyUI-Manager/check.sh | |
![ -f "ComfyUI-Manager/scan.sh" ] && chmod 755 ComfyUI-Manager/scan.sh | |
![ -f "ComfyUI-Manager/node_db/dev/scan.sh" ] && chmod 755 ComfyUI-Manager/node_db/dev/scan.sh | |
![ -f "ComfyUI-Manager/scripts/install-comfyui-venv-linux.sh" ] && chmod 755 ComfyUI-Manager/scripts/install-comfyui-venv-linux.sh | |
![ -f "ComfyUI-Manager/scripts/install-comfyui-venv-win.bat" ] && chmod 755 ComfyUI-Manager/scripts/install-comfyui-venv-win.bat | |
![ ! -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 | |
# ModuleNotFoundError: No module named 'av'がでるため、あらかじめavをインストール | |
!pip install av | |
### setup Wan2.1 ### | |
#@markdown --- | |
#@markdown ## モデル選択 | |
#@markdown ### I2Vモデル 480p 14B | |
use_i2v_480p_14b = False #@param {type: "boolean"} | |
if use_i2v_480p_14b: | |
!wget "https://huggingface.co/Comfy-Org/Wan_2.1_ComfyUI_repackaged/resolve/main/split_files/diffusion_models/wan2.1_i2v_480p_14B_bf16.safetensors" --directory-prefix={WORKSPACE}/models/diffusion_models | |
#@markdown ### I2Vモデル 720p 14B | |
use_i2v_720p_14b = False #@param {type: "boolean"} | |
if use_i2v_720p_14b: | |
!wget "https://huggingface.co/Comfy-Org/Wan_2.1_ComfyUI_repackaged/resolve/main/split_files/diffusion_models/wan2.1_i2v_720p_14B_bf16.safetensors" --directory-prefix={WORKSPACE}/models/diffusion_models | |
#@markdown ### T2Vモデル 1.3B | |
use_t2v_1_3b = False #@param {type: "boolean"} | |
if use_t2v_1_3b: | |
!wget "https://huggingface.co/Comfy-Org/Wan_2.1_ComfyUI_repackaged/resolve/main/split_files/diffusion_models/wan2.1_t2v_1.3B_bf16.safetensors" --directory-prefix={WORKSPACE}/models/diffusion_models | |
#@markdown ### T2Vモデル 14B | |
use_t2v_14b = False #@param {type: "boolean"} | |
if use_t2v_14b: | |
!wget "https://huggingface.co/Comfy-Org/Wan_2.1_ComfyUI_repackaged/resolve/main/split_files/diffusion_models/wan2.1_t2v_14B_bf16.safetensors" --directory-prefix={WORKSPACE}/models/diffusion_models | |
#@markdown ### ani_Wan2_1_14B_fp8_e4m3fn T2Vモデル 14B | |
#@markdown [公式ページ](https://civitai.com/models/1626197) | |
use_ani_wan2_1_14b_fp8_e4m3fn_t2v = False #@param {type: "boolean"} | |
if use_ani_wan2_1_14b_fp8_e4m3fn_t2v: | |
!wget "https://civitai.com/api/download/models/1840561" --content-disposition --directory-prefix={WORKSPACE}/models/diffusion_models | |
#@markdown ### ani_Wan2_1_14B_fp8_e4m3fn I2Vモデル 14B | |
#@markdown [公式ページ](https://civitai.com/models/1626197) | |
use_ani_wan2_1_14b_fp8_e4m3fn_i2v = False #@param {type: "boolean"} | |
if use_ani_wan2_1_14b_fp8_e4m3fn_i2v: | |
!wget "https://civitai.com/api/download/models/1852433" --content-disposition --directory-prefix={WORKSPACE}/models/diffusion_models | |
#@markdown ### ani_Wan2_1_14B_fp8_e4m3fn T2Vモデル 1.3B | |
#@markdown [公式ページ](https://civitai.com/models/1626197) | |
use_ani_wan2_1_1_3b_fp8_e4m3fn_t2v = False #@param {type: "boolean"} | |
if use_ani_wan2_1_1_3b_fp8_e4m3fn_t2v: | |
!wget "https://civitai.com/api/download/models/1842026" --content-disposition --directory-prefix={WORKSPACE}/models/diffusion_models | |
#@markdown ### Wan 2.1 VACE FP16 14B | |
use_vace_14b = False #@param {type:"boolean"} | |
#@markdown ### Wan 2.1 VACE FP16 1.3B | |
use_vace_1_3b = False #@param {type:"boolean"} | |
#@markdown ### Wan2.1 1.3B + CausVid LoRA | |
use_causvid_lora_13b = False #@param {type:"boolean"} | |
VACE_REPO = "https://huggingface.co/Comfy-Org/Wan_2.1_ComfyUI_repackaged/resolve/main/split_files/diffusion_models" | |
#@markdown ### Wan2.1-Fun-Control-14B from Kijai | |
#@markdown [公式ページ](https://huggingface.co/Kijai/WanVideo_comfy) | |
use_wan_fun_control_14b = False #@param {type: "boolean"} | |
if use_wan_fun_control_14b: | |
!wget https://huggingface.co/Kijai/WanVideo_comfy/resolve/main/Wan2.1-Fun-Control-14B_fp8_e4m3fn.safetensors --directory-prefix={WORKSPACE}/models/diffusion_models | |
!wget https://huggingface.co/Kijai/WanVideo_comfy/resolve/main/open-clip-xlm-roberta-large-vit-huge-14_visual_fp16.safetensors --directory-prefix={WORKSPACE}/models/clip_vision | |
!wget https://huggingface.co/Kijai/WanVideo_comfy/resolve/main/umt5-xxl-enc-bf16.safetensors --directory-prefix={WORKSPACE}/models/text_encoders | |
!wget https://huggingface.co/Kijai/WanVideo_comfy/resolve/main/Wan2_1_VAE_bf16.safetensors --directory-prefix={WORKSPACE}/models/vae | |
install_wan_nodes = use_vace_14b or use_vace_1_3b or use_wan_fun_control_14b | |
#@markdown ### Wan2.1-Fun-Control-14Bを用いたオススメワークフロー | |
#@markdown - [Wan_Restyledfirstframe_workflow]((https://civitai.com/models/1376578?modelVersionId=1588367) | |
#@markdown ### GGUFモデル | |
#@markdown ### I2Vモデル 14B Q6 | |
use_gguf_i2v_14b_q6 = False #@param {type: "boolean"} | |
if use_gguf_i2v_14b_q6: | |
!wget "https://huggingface.co/city96/Wan2.1-I2V-14B-720P-gguf/resolve/main/wan2.1-i2v-14b-720p-Q6_K.gguf" --directory-prefix={WORKSPACE}/models/diffusion_models | |
# GGUFモデルが有効化されている場合は対応する拡張機能も併せてダウンロードする | |
if use_gguf_i2v_14b_q6: | |
%cd $WORKSPACE/custom_nodes | |
!git clone https://github.com/city96/ComfyUI-GGUF | |
!pip install -r requirements.txt | |
!pip install gguf | |
%cd $WORKSPACE | |
# CausVid LoRA | |
if use_causvid_lora_13b: | |
!wget -c "https://huggingface.co/Kijai/WanVideo_comfy/resolve/main/Wan21_CausVid_bidirect2_T2V_1_3B_lora_rank32.safetensors" \ | |
--directory-prefix={WORKSPACE}/models/loras | |
# VACE関連のセットアップ | |
if use_vace_14b: | |
!wget -c "$VACE_REPO/wan2.1_vace_14B_fp16.safetensors" \ | |
--directory-prefix={WORKSPACE}/models/diffusion_models | |
if use_vace_1_3b: | |
!wget -c "$VACE_REPO/wan2.1_vace_1.3B_fp16.safetensors" \ | |
--directory-prefix={WORKSPACE}/models/diffusion_models | |
!wget -nc "https://huggingface.co/Comfy-Org/Wan_2.1_ComfyUI_repackaged/resolve/main/split_files/text_encoders/umt5_xxl_fp8_e4m3fn_scaled.safetensors" \ | |
--directory-prefix={WORKSPACE}/models/text_encoders | |
!wget -nc "https://huggingface.co/Comfy-Org/Wan_2.1_ComfyUI_repackaged/resolve/main/split_files/vae/wan_2.1_vae.safetensors" \ | |
--directory-prefix={WORKSPACE}/models/vae | |
if install_wan_nodes: | |
%cd $WORKSPACE/custom_nodes | |
# WanVideoWrapper | |
!git clone https://github.com/kijai/ComfyUI-WanVideoWrapper.git | |
%cd ComfyUI-WanVideoWrapper | |
!pip install -r requirements.txt | |
%cd .. | |
# KJNodes | |
!git clone https://github.com/kijai/ComfyUI-KJNodes.git | |
%cd ComfyUI-KJNodes | |
!pip install -r requirements.txt | |
%cd .. | |
# VideoHelperSuite | |
!git clone https://github.com/Kosinkadink/ComfyUI-VideoHelperSuite.git | |
%cd ComfyUI-VideoHelperSuite | |
!pip install -r requirements.txt | |
%cd .. | |
# ControlNet Aux | |
!git clone https://github.com/Fannovel16/comfyui_controlnet_aux.git | |
%cd comfyui_controlnet_aux | |
!pip install -r requirements.txt | |
%cd .. | |
# Essentials | |
!git clone https://github.com/cubiq/ComfyUI_essentials.git | |
%cd ComfyUI_essentials | |
!pip install -r requirements.txt | |
%cd .. | |
# download text_encoders | |
!wget -nc "https://huggingface.co/Kijai/WanVideo_comfy/resolve/main/umt5-xxl-enc-bf16.safetensors" --directory-prefix={WORKSPACE}/models/text_encoders | |
%cd {WORKSPACE} | |
#@markdown ### Smartphone Snapshot Photo Reality LoRA (Wan2.1 T2IV 14B) | |
#@markdown [公式ページ](https://civitai.com/models/1763826) | |
use_snapshot_photo_reality = False #@param {type:"boolean"} | |
if use_snapshot_photo_reality: | |
!wget -c "https://huggingface.co/Comfy-Org/Wan_2.1_ComfyUI_repackaged/resolve/main/split_files/diffusion_models/wan2.1_t2v_14B_fp8_e4m3fn.safetensors" \ | |
--directory-prefix={WORKSPACE}/models/diffusion_models | |
!wget "https://civitai.com/api/download/models/1996092" \ | |
--content-disposition \ | |
--directory-prefix={WORKSPACE}/models/loras | |
!wget -c "https://huggingface.co/Kijai/WanVideo_comfy/resolve/main/Wan21_T2V_14B_lightx2v_cfg_step_distill_lora_rank32.safetensors" \ | |
--directory-prefix={WORKSPACE}/models/loras | |
!wget -c "https://huggingface.co/vrgamedevgirl84/Wan14BT2VFusioniX/resolve/main/FusionX_LoRa/Wan2.1_T2V_14B_FusionX_LoRA.safetensors" \ | |
--directory-prefix={WORKSPACE}/models/loras | |
# install custom nodes | |
%cd $WORKSPACE/custom_nodes | |
!git clone https://github.com/ClownsharkBatwing/RES4LYF.git | |
%cd RES4LYF | |
!if [ -f requirements.txt ]; then pip install -r requirements.txt; fi | |
%cd $WORKSPACE | |
#@markdown --- | |
!wget -nc "https://huggingface.co/Comfy-Org/Wan_2.1_ComfyUI_repackaged/resolve/main/split_files/text_encoders/umt5_xxl_fp8_e4m3fn_scaled.safetensors" --directory-prefix={WORKSPACE}/models/text_encoders | |
!wget -nc "https://huggingface.co/Comfy-Org/Wan_2.1_ComfyUI_repackaged/resolve/main/split_files/clip_vision/clip_vision_h.safetensors" --directory-prefix={WORKSPACE}/models/clip_vision | |
!wget -nc "https://huggingface.co/Comfy-Org/Wan_2.1_ComfyUI_repackaged/resolve/main/split_files/vae/wan_2.1_vae.safetensors" --directory-prefix={WORKSPACE}/models/vae | |
### start comfyui ### | |
!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='') | |
#print(l, 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