Spaces:
Running
Running
Upload comfyui_colab.py
Browse files- comfyui_colab.py +177 -0
comfyui_colab.py
ADDED
@@ -0,0 +1,177 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# -*- coding: utf-8 -*-
|
2 |
+
"""comfyui_colab.ipynb
|
3 |
+
|
4 |
+
Automatically generated by Colab.
|
5 |
+
|
6 |
+
Original file is located at
|
7 |
+
https://colab.research.google.com/#fileId=https%3A//huggingface.co/spaces/thamnt/COMFY_WINDOW/blob/main/comfyui_colab.ipynb
|
8 |
+
|
9 |
+
Git clone the repo and install the requirements. (ignore the pip errors about protobuf)
|
10 |
+
"""
|
11 |
+
|
12 |
+
# Commented out IPython magic to ensure Python compatibility.
|
13 |
+
#@title Environment Setup
|
14 |
+
|
15 |
+
|
16 |
+
OPTIONS = {}
|
17 |
+
|
18 |
+
USE_GOOGLE_DRIVE = False #@param {type:"boolean"}
|
19 |
+
UPDATE_COMFY_UI = True #@param {type:"boolean"}
|
20 |
+
WORKSPACE = 'ComfyUI'
|
21 |
+
OPTIONS['USE_GOOGLE_DRIVE'] = USE_GOOGLE_DRIVE
|
22 |
+
OPTIONS['UPDATE_COMFY_UI'] = UPDATE_COMFY_UI
|
23 |
+
|
24 |
+
if OPTIONS['USE_GOOGLE_DRIVE']:
|
25 |
+
!echo "Mounting Google Drive..."
|
26 |
+
# %cd /
|
27 |
+
|
28 |
+
from google.colab import drive
|
29 |
+
drive.mount('/content/drive')
|
30 |
+
|
31 |
+
WORKSPACE = "/content/drive/MyDrive/ComfyUI"
|
32 |
+
# %cd /content/drive/MyDrive
|
33 |
+
|
34 |
+
![ ! -d $WORKSPACE ] && echo -= Initial setup ComfyUI =- && git clone https://github.com/comfyanonymous/ComfyUI
|
35 |
+
# %cd $WORKSPACE
|
36 |
+
|
37 |
+
if OPTIONS['UPDATE_COMFY_UI']:
|
38 |
+
!echo -= Updating ComfyUI =-
|
39 |
+
!git pull
|
40 |
+
|
41 |
+
!echo -= Install dependencies =-
|
42 |
+
!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
|
43 |
+
|
44 |
+
"""Download some models/checkpoints/vae or custom comfyui nodes (uncomment the commands for the ones you want)"""
|
45 |
+
|
46 |
+
# Checkpoints
|
47 |
+
|
48 |
+
### SDXL
|
49 |
+
### I recommend these workflow examples: https://comfyanonymous.github.io/ComfyUI_examples/sdxl/
|
50 |
+
|
51 |
+
#!wget -c https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0/resolve/main/sd_xl_base_1.0.safetensors -P ./models/checkpoints/
|
52 |
+
#!wget -c https://huggingface.co/stabilityai/stable-diffusion-xl-refiner-1.0/resolve/main/sd_xl_refiner_1.0.safetensors -P ./models/checkpoints/
|
53 |
+
|
54 |
+
# SDXL ReVision
|
55 |
+
#!wget -c https://huggingface.co/comfyanonymous/clip_vision_g/resolve/main/clip_vision_g.safetensors -P ./models/clip_vision/
|
56 |
+
|
57 |
+
# SD1.5
|
58 |
+
!wget -c https://huggingface.co/Comfy-Org/stable-diffusion-v1-5-archive/resolve/main/v1-5-pruned-emaonly-fp16.safetensors -P ./models/checkpoints/
|
59 |
+
|
60 |
+
# SD2
|
61 |
+
#!wget -c https://huggingface.co/stabilityai/stable-diffusion-2-1-base/resolve/main/v2-1_512-ema-pruned.safetensors -P ./models/checkpoints/
|
62 |
+
#!wget -c https://huggingface.co/stabilityai/stable-diffusion-2-1/resolve/main/v2-1_768-ema-pruned.safetensors -P ./models/checkpoints/
|
63 |
+
|
64 |
+
# Some SD1.5 anime style
|
65 |
+
#!wget -c https://huggingface.co/WarriorMama777/OrangeMixs/resolve/main/Models/AbyssOrangeMix2/AbyssOrangeMix2_hard.safetensors -P ./models/checkpoints/
|
66 |
+
#!wget -c https://huggingface.co/WarriorMama777/OrangeMixs/resolve/main/Models/AbyssOrangeMix3/AOM3A1_orangemixs.safetensors -P ./models/checkpoints/
|
67 |
+
#!wget -c https://huggingface.co/WarriorMama777/OrangeMixs/resolve/main/Models/AbyssOrangeMix3/AOM3A3_orangemixs.safetensors -P ./models/checkpoints/
|
68 |
+
#!wget -c https://huggingface.co/Linaqruf/anything-v3.0/resolve/main/anything-v3-fp16-pruned.safetensors -P ./models/checkpoints/
|
69 |
+
|
70 |
+
# Waifu Diffusion 1.5 (anime style SD2.x 768-v)
|
71 |
+
#!wget -c https://huggingface.co/waifu-diffusion/wd-1-5-beta3/resolve/main/wd-illusion-fp16.safetensors -P ./models/checkpoints/
|
72 |
+
|
73 |
+
|
74 |
+
# unCLIP models
|
75 |
+
#!wget -c https://huggingface.co/comfyanonymous/illuminatiDiffusionV1_v11_unCLIP/resolve/main/illuminatiDiffusionV1_v11-unclip-h-fp16.safetensors -P ./models/checkpoints/
|
76 |
+
#!wget -c https://huggingface.co/comfyanonymous/wd-1.5-beta2_unCLIP/resolve/main/wd-1-5-beta2-aesthetic-unclip-h-fp16.safetensors -P ./models/checkpoints/
|
77 |
+
|
78 |
+
|
79 |
+
# VAE
|
80 |
+
!wget -c https://huggingface.co/stabilityai/sd-vae-ft-mse-original/resolve/main/vae-ft-mse-840000-ema-pruned.safetensors -P ./models/vae/
|
81 |
+
#!wget -c https://huggingface.co/WarriorMama777/OrangeMixs/resolve/main/VAEs/orangemix.vae.pt -P ./models/vae/
|
82 |
+
#!wget -c https://huggingface.co/hakurei/waifu-diffusion-v1-4/resolve/main/vae/kl-f8-anime2.ckpt -P ./models/vae/
|
83 |
+
|
84 |
+
|
85 |
+
# Loras
|
86 |
+
#!wget -c https://civitai.com/api/download/models/10350 -O ./models/loras/theovercomer8sContrastFix_sd21768.safetensors #theovercomer8sContrastFix SD2.x 768-v
|
87 |
+
#!wget -c https://civitai.com/api/download/models/10638 -O ./models/loras/theovercomer8sContrastFix_sd15.safetensors #theovercomer8sContrastFix SD1.x
|
88 |
+
#!wget -c https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0/resolve/main/sd_xl_offset_example-lora_1.0.safetensors -P ./models/loras/ #SDXL offset noise lora
|
89 |
+
|
90 |
+
|
91 |
+
# T2I-Adapter
|
92 |
+
#!wget -c https://huggingface.co/TencentARC/T2I-Adapter/resolve/main/models/t2iadapter_depth_sd14v1.pth -P ./models/controlnet/
|
93 |
+
#!wget -c https://huggingface.co/TencentARC/T2I-Adapter/resolve/main/models/t2iadapter_seg_sd14v1.pth -P ./models/controlnet/
|
94 |
+
#!wget -c https://huggingface.co/TencentARC/T2I-Adapter/resolve/main/models/t2iadapter_sketch_sd14v1.pth -P ./models/controlnet/
|
95 |
+
#!wget -c https://huggingface.co/TencentARC/T2I-Adapter/resolve/main/models/t2iadapter_keypose_sd14v1.pth -P ./models/controlnet/
|
96 |
+
#!wget -c https://huggingface.co/TencentARC/T2I-Adapter/resolve/main/models/t2iadapter_openpose_sd14v1.pth -P ./models/controlnet/
|
97 |
+
#!wget -c https://huggingface.co/TencentARC/T2I-Adapter/resolve/main/models/t2iadapter_color_sd14v1.pth -P ./models/controlnet/
|
98 |
+
#!wget -c https://huggingface.co/TencentARC/T2I-Adapter/resolve/main/models/t2iadapter_canny_sd14v1.pth -P ./models/controlnet/
|
99 |
+
|
100 |
+
# T2I Styles Model
|
101 |
+
#!wget -c https://huggingface.co/TencentARC/T2I-Adapter/resolve/main/models/t2iadapter_style_sd14v1.pth -P ./models/style_models/
|
102 |
+
|
103 |
+
# CLIPVision model (needed for styles model)
|
104 |
+
#!wget -c https://huggingface.co/openai/clip-vit-large-patch14/resolve/main/pytorch_model.bin -O ./models/clip_vision/clip_vit14.bin
|
105 |
+
|
106 |
+
|
107 |
+
# ControlNet
|
108 |
+
#!wget -c https://huggingface.co/comfyanonymous/ControlNet-v1-1_fp16_safetensors/resolve/main/control_v11e_sd15_ip2p_fp16.safetensors -P ./models/controlnet/
|
109 |
+
#!wget -c https://huggingface.co/comfyanonymous/ControlNet-v1-1_fp16_safetensors/resolve/main/control_v11e_sd15_shuffle_fp16.safetensors -P ./models/controlnet/
|
110 |
+
#!wget -c https://huggingface.co/comfyanonymous/ControlNet-v1-1_fp16_safetensors/resolve/main/control_v11p_sd15_canny_fp16.safetensors -P ./models/controlnet/
|
111 |
+
#!wget -c https://huggingface.co/comfyanonymous/ControlNet-v1-1_fp16_safetensors/resolve/main/control_v11f1p_sd15_depth_fp16.safetensors -P ./models/controlnet/
|
112 |
+
#!wget -c https://huggingface.co/comfyanonymous/ControlNet-v1-1_fp16_safetensors/resolve/main/control_v11p_sd15_inpaint_fp16.safetensors -P ./models/controlnet/
|
113 |
+
#!wget -c https://huggingface.co/comfyanonymous/ControlNet-v1-1_fp16_safetensors/resolve/main/control_v11p_sd15_lineart_fp16.safetensors -P ./models/controlnet/
|
114 |
+
#!wget -c https://huggingface.co/comfyanonymous/ControlNet-v1-1_fp16_safetensors/resolve/main/control_v11p_sd15_mlsd_fp16.safetensors -P ./models/controlnet/
|
115 |
+
#!wget -c https://huggingface.co/comfyanonymous/ControlNet-v1-1_fp16_safetensors/resolve/main/control_v11p_sd15_normalbae_fp16.safetensors -P ./models/controlnet/
|
116 |
+
#!wget -c https://huggingface.co/comfyanonymous/ControlNet-v1-1_fp16_safetensors/resolve/main/control_v11p_sd15_openpose_fp16.safetensors -P ./models/controlnet/
|
117 |
+
#!wget -c https://huggingface.co/comfyanonymous/ControlNet-v1-1_fp16_safetensors/resolve/main/control_v11p_sd15_scribble_fp16.safetensors -P ./models/controlnet/
|
118 |
+
#!wget -c https://huggingface.co/comfyanonymous/ControlNet-v1-1_fp16_safetensors/resolve/main/control_v11p_sd15_seg_fp16.safetensors -P ./models/controlnet/
|
119 |
+
#!wget -c https://huggingface.co/comfyanonymous/ControlNet-v1-1_fp16_safetensors/resolve/main/control_v11p_sd15_softedge_fp16.safetensors -P ./models/controlnet/
|
120 |
+
#!wget -c https://huggingface.co/comfyanonymous/ControlNet-v1-1_fp16_safetensors/resolve/main/control_v11p_sd15s2_lineart_anime_fp16.safetensors -P ./models/controlnet/
|
121 |
+
#!wget -c https://huggingface.co/comfyanonymous/ControlNet-v1-1_fp16_safetensors/resolve/main/control_v11u_sd15_tile_fp16.safetensors -P ./models/controlnet/
|
122 |
+
|
123 |
+
# ControlNet SDXL
|
124 |
+
#!wget -c https://huggingface.co/stabilityai/control-lora/resolve/main/control-LoRAs-rank256/control-lora-canny-rank256.safetensors -P ./models/controlnet/
|
125 |
+
#!wget -c https://huggingface.co/stabilityai/control-lora/resolve/main/control-LoRAs-rank256/control-lora-depth-rank256.safetensors -P ./models/controlnet/
|
126 |
+
#!wget -c https://huggingface.co/stabilityai/control-lora/resolve/main/control-LoRAs-rank256/control-lora-recolor-rank256.safetensors -P ./models/controlnet/
|
127 |
+
#!wget -c https://huggingface.co/stabilityai/control-lora/resolve/main/control-LoRAs-rank256/control-lora-sketch-rank256.safetensors -P ./models/controlnet/
|
128 |
+
|
129 |
+
# Controlnet Preprocessor nodes by Fannovel16
|
130 |
+
#!cd custom_nodes && git clone https://github.com/Fannovel16/comfy_controlnet_preprocessors; cd comfy_controlnet_preprocessors && python install.py
|
131 |
+
|
132 |
+
|
133 |
+
# GLIGEN
|
134 |
+
#!wget -c https://huggingface.co/comfyanonymous/GLIGEN_pruned_safetensors/resolve/main/gligen_sd14_textbox_pruned_fp16.safetensors -P ./models/gligen/
|
135 |
+
|
136 |
+
|
137 |
+
# ESRGAN upscale model
|
138 |
+
#!wget -c https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.0/RealESRGAN_x4plus.pth -P ./models/upscale_models/
|
139 |
+
#!wget -c https://huggingface.co/sberbank-ai/Real-ESRGAN/resolve/main/RealESRGAN_x2.pth -P ./models/upscale_models/
|
140 |
+
#!wget -c https://huggingface.co/sberbank-ai/Real-ESRGAN/resolve/main/RealESRGAN_x4.pth -P ./models/upscale_models/
|
141 |
+
|
142 |
+
"""### Run ComfyUI with cloudflared (Recommended Way)
|
143 |
+
|
144 |
+
|
145 |
+
|
146 |
+
"""
|
147 |
+
|
148 |
+
!wget https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64.deb
|
149 |
+
!dpkg -i cloudflared-linux-amd64.deb
|
150 |
+
|
151 |
+
import subprocess
|
152 |
+
import threading
|
153 |
+
import time
|
154 |
+
import socket
|
155 |
+
import urllib.request
|
156 |
+
|
157 |
+
def iframe_thread(port):
|
158 |
+
while True:
|
159 |
+
time.sleep(0.5)
|
160 |
+
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
161 |
+
result = sock.connect_ex(('127.0.0.1', port))
|
162 |
+
if result == 0:
|
163 |
+
break
|
164 |
+
sock.close()
|
165 |
+
print("\nComfyUI finished loading, trying to launch cloudflared (if it gets stuck here cloudflared is having issues)\n")
|
166 |
+
|
167 |
+
p = subprocess.Popen(["cloudflared", "tunnel", "--url", "http://127.0.0.1:{}".format(port)], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
168 |
+
for line in p.stderr:
|
169 |
+
l = line.decode()
|
170 |
+
if "trycloudflare.com " in l:
|
171 |
+
print("This is the URL to access ComfyUI:", l[l.find("http"):], end='')
|
172 |
+
#print(l, end='')
|
173 |
+
|
174 |
+
|
175 |
+
threading.Thread(target=iframe_thread, daemon=True, args=(8188,)).start()
|
176 |
+
|
177 |
+
!python main.py --dont-print-server
|