Last active
March 29, 2024 13:41
-
-
Save safa-dayo/b2393d648e4703c2c8ef28082952e176 to your computer and use it in GitHub Desktop.
Google ColabからAnimateDiff / AnimateLCM / AnimateDiff LightningでAI動画を作るためのノートブック
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 ComfyUIで対象動画の動きを参照してAnimateDiff(AnimateLCM)でAI動画を作るためのノートブック | |
# こちらのColabノートブックはComfyUI Manager側で用意されているノートブックを参考にして作成しています | |
# ComfyUI Manager: https://github.com/ltdrdata/ComfyUI-Manager | |
from pathlib import Path | |
OPTIONS = {} | |
#@markdown ## 起動設定 | |
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 | |
#@markdown ---- | |
#@markdown ## AnimateDiff用のモデル設定 | |
#@markdown 利用したいAnimateDiff用のモデルを選択してください | |
#@markdown ### AnimateDiff Motion module(mm_sd15_v3) | |
use_animate_diff_mm_sd15_v3 = False #@param {type: "boolean"} | |
#@markdown ### AnimateLCM | |
use_animate_lcm = False #@param {type: "boolean"} | |
#@markdown ### AnimateDiff Lightning | |
#@markdown 2step | |
use_animatediff_lightning_2step = False #@param {type: "boolean"} | |
#@markdown 4step | |
use_animatediff_lightning_4step = False #@param {type: "boolean"} | |
#@markdown 8step | |
use_animatediff_lightning_8step = False #@param {type: "boolean"} | |
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 =- | |
#Remove cu121 as it causes issues in Colab. | |
#!pip install xformers!=0.0.18 -r requirements.txt --extra-index-url https://download.pytorch.org/whl/cu121 --extra-index-url https://download.pytorch.org/whl/cu118 --extra-index-url https://download.pytorch.org/whl/cu117 | |
!pip3 install accelerate | |
!pip3 install einops transformers>=4.25.1 safetensors>=0.3.0 aiohttp pyyaml Pillow scipy tqdm psutil | |
!pip3 install xformers!=0.0.18 torch==2.1.0 torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121 | |
!pip3 install torchsde | |
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']: | |
!pwd | |
!echo -= Install custom nodes dependencies =- | |
![ -f "custom_nodes/ComfyUI-Manager/scripts/colab-dependencies.py" ] && python "custom_nodes/ComfyUI-Manager/scripts/colab-dependencies.py" | |
### モデルやVAEなどのインストール | |
# BellyUse(checkpoint) | |
!wget https://civitai.com/api/download/models/265163 --content-disposition --directory-prefix=./models/checkpoints/ | |
# 別途モデルを導入する場合は、ここに追加すること | |
# !wget {モデルのダウンロード} --directory-prefix=./models/checkpoints/ | |
# Civitaiの場合は以下 | |
# !wget {モデルのダウンロード} --content-disposition --directory-prefix=./models/checkpoints/ | |
# EasyNegative | |
!wget https://huggingface.co/datasets/gsdf/EasyNegative/resolve/main/EasyNegative.safetensors --directory-prefix=/content/ComfyUI/models/embeddings | |
# VAE(vae-ft-mse-840000) | |
!wget -c https://huggingface.co/stabilityai/sd-vae-ft-mse-original/resolve/main/vae-ft-mse-840000-ema-pruned.safetensors -P ./models/vae/ | |
### 拡張機能のインストール | |
# animatediff | |
%cd /content/ComfyUI/custom_nodes | |
!git clone https://github.com/Kosinkadink/ComfyUI-AnimateDiff-Evolved.git | |
%cd /content/ComfyUI/ | |
if use_animate_diff_mm_sd15_v3: | |
!wget https://huggingface.co/conrevo/AnimateDiff-A1111/resolve/main/motion_module/mm_sd15_v3.safetensors --directory-prefix=/content/ComfyUI/custom_nodes/ComfyUI-AnimateDiff-Evolved/models | |
# AnimateLCM | |
if use_animate_lcm: | |
!wget https://huggingface.co/wangfuyun/AnimateLCM/resolve/main/AnimateLCM_sd15_t2v.ckpt --directory-prefix=/content/ComfyUI/custom_nodes/ComfyUI-AnimateDiff-Evolved/models | |
!wget https://huggingface.co/wangfuyun/AnimateLCM/resolve/main/AnimateLCM_sd15_t2v_lora.safetensors --directory-prefix=/content/ComfyUI/models/loras | |
# AnimateDiff Lightning | |
if use_animatediff_lightning_2step: | |
!wget https://huggingface.co/ByteDance/AnimateDiff-Lightning/resolve/main/animatediff_lightning_2step_comfyui.safetensors --directory-prefix=/content/ComfyUI/custom_nodes/ComfyUI-AnimateDiff-Evolved/models | |
if use_animatediff_lightning_4step: | |
!wget https://huggingface.co/ByteDance/AnimateDiff-Lightning/resolve/main/animatediff_lightning_4step_comfyui.safetensors --directory-prefix=/content/ComfyUI/custom_nodes/ComfyUI-AnimateDiff-Evolved/models | |
if use_animatediff_lightning_8step: | |
!wget https://huggingface.co/ByteDance/AnimateDiff-Lightning/resolve/main/animatediff_lightning_8step_comfyui.safetensors --directory-prefix=/content/ComfyUI/custom_nodes/ComfyUI-AnimateDiff-Evolved/models | |
# openpose | |
!wget https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15_openpose.pth --directory-prefix=/content/ComfyUI/models/controlnet | |
# ComfyUI-Impact-Pack | |
%cd /content/ComfyUI/custom_nodes | |
!git clone https://github.com/ltdrdata/ComfyUI-Impact-Pack.git | |
%cd /content/ComfyUI/ | |
# ComfyUI's ControlNet Auxiliary Preprocessors | |
%cd /content/ComfyUI/custom_nodes | |
!git clone https://github.com/Fannovel16/comfyui_controlnet_aux.git | |
%cd comfyui_controlnet_aux | |
!pip install -r requirements.txt | |
%cd /content/ComfyUI/ | |
# FizzNodes | |
%cd /content/ComfyUI/custom_nodes | |
!git clone https://github.com/FizzleDorf/ComfyUI_FizzNodes.git | |
%cd /content/ComfyUI/ | |
# ComfyUI-Advanced-ControlNet | |
%cd /content/ComfyUI/custom_nodes | |
!git clone https://github.com/Kosinkadink/ComfyUI-Advanced-ControlNet.git | |
%cd /content/ComfyUI/ | |
# ComfyUI-VideoHelperSuite | |
%cd /content/ComfyUI/custom_nodes | |
!git clone https://github.com/Kosinkadink/ComfyUI-VideoHelperSuite.git | |
%cd /content/ComfyUI/ | |
### ここから別のコードセル | |
# このコードセルを実行することでColab上でComfyUIを利用するためのURLが発行される | |
!wget 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