Created
November 26, 2024 00:49
-
-
Save safa-dayo/8fb8196fcef1143092c74ea7395a30a7 to your computer and use it in GitHub Desktop.
FluxのReduxを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 | |
#@markdown # Hugging FaceのAccess Tokens設定 | |
#@markdown Hugging Faceにホストされている、ダウンロードに認証が必要なモデルをダウンロードする場合はAccess Tokensが必要です。Access TokensはHugging Faceのサイトにログインした状態で以下のリンクから取得できます。 | |
#@markdown https://huggingface.co/settings/tokens | |
#@markdown **なおHugging FaceのAccess Tokensは人と共有しないようにお気をつけください** | |
hf_token = "" #@param {type:"string"} | |
### 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 | |
### setup Flux Redux ### | |
!wget https://huggingface.co/Comfy-Org/sigclip_vision_384/resolve/main/sigclip_vision_patch14_384.safetensors --directory-prefix=$WORKSPACE/models/clip_vision | |
!wget https://huggingface.co/comfyanonymous/flux_text_encoders/resolve/main/t5xxl_fp16.safetensors --directory-prefix=$WORKSPACE/models/clip | |
!wget https://huggingface.co/comfyanonymous/flux_text_encoders/resolve/main/clip_l.safetensors --content-disposition --directory-prefix=$WORKSPACE/models/clip | |
!curl -L -H "Authorization: Bearer {hf_token}" \ | |
-o $WORKSPACE/models/diffusion_models/flux1-dev.safetensors \ | |
https://huggingface.co/black-forest-labs/FLUX.1-dev/resolve/main/flux1-dev.safetensors | |
!curl -L -H "Authorization: Bearer {hf_token}" \ | |
-o $WORKSPACE/models/style_models/flux1-redux-dev.safetensors \ | |
https://huggingface.co/black-forest-labs/FLUX.1-Redux-dev/resolve/main/flux1-redux-dev.safetensors | |
!curl -L -H "Authorization: Bearer {hf_token}" \ | |
-o $WORKSPACE/models/vae/ae.safetensors \ | |
https://huggingface.co/black-forest-labs/FLUX.1-dev/resolve/main/ae.safetensors | |
### 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