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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": null,
|
6 |
+
"id": "6038b6d3-baa6-4aa3-90f8-6f46bf673cdf",
|
7 |
+
"metadata": {},
|
8 |
+
"outputs": [],
|
9 |
+
"source": [
|
10 |
+
"import os\n",
|
11 |
+
"from IPython.display import clear_output\n",
|
12 |
+
"from subprocess import call, getoutput, Popen, run\n",
|
13 |
+
"import time\n",
|
14 |
+
"import ipywidgets as widgets\n",
|
15 |
+
"import requests\n",
|
16 |
+
"import sys\n",
|
17 |
+
"import fileinput\n",
|
18 |
+
"from torch.hub import download_url_to_file\n",
|
19 |
+
"from urllib.parse import urlparse, parse_qs, unquote\n",
|
20 |
+
"import re\n",
|
21 |
+
"import six\n",
|
22 |
+
"import gdown\n",
|
23 |
+
"\n",
|
24 |
+
"from urllib.request import urlopen, Request\n",
|
25 |
+
"import tempfile\n",
|
26 |
+
"from tqdm import tqdm\n",
|
27 |
+
"from bs4 import BeautifulSoup\n",
|
28 |
+
"import zipfile\n",
|
29 |
+
"\n",
|
30 |
+
"def modeldwn(model_LINK):\n",
|
31 |
+
"\n",
|
32 |
+
" if model_LINK == \"\":\n",
|
33 |
+
" print(\"[1;33mNothing to do\")\n",
|
34 |
+
" else:\n",
|
35 |
+
" os.makedirs(\n",
|
36 |
+
" \"/workspace/ComfyUI/models/checkpoints\",\n",
|
37 |
+
" exist_ok=True,\n",
|
38 |
+
" )\n",
|
39 |
+
"\n",
|
40 |
+
" src = getsrc(model_LINK)\n",
|
41 |
+
"\n",
|
42 |
+
" if src == \"civitai\":\n",
|
43 |
+
" modelname = get_name(model_LINK, False)\n",
|
44 |
+
" loramodel = f\"/workspace/ComfyUI/models/checkpoints/{modelname}\"\n",
|
45 |
+
" if not os.path.exists(loramodel):\n",
|
46 |
+
" dwn(model_LINK, loramodel, \"Downloading the checkpoint model\")\n",
|
47 |
+
" clear_output()\n",
|
48 |
+
" else:\n",
|
49 |
+
" print(\"[1;33mModel already exists\")\n",
|
50 |
+
" elif src == \"gdrive\":\n",
|
51 |
+
" modelname = get_true_name(model_LINK)\n",
|
52 |
+
" loramodel = f\"/workspace/ComfyUI/models/checkpoints/{modelname}\"\n",
|
53 |
+
" if not os.path.exists(loramodel):\n",
|
54 |
+
" gdown.download(\n",
|
55 |
+
" url=model_LINK.replace(\"/file/d/\", \"/uc?id=\").replace(\"/view\", \"\"),\n",
|
56 |
+
" output=loramodel,\n",
|
57 |
+
" quiet=False,\n",
|
58 |
+
" )\n",
|
59 |
+
" clear_output()\n",
|
60 |
+
" else:\n",
|
61 |
+
" print(\"[1;33mModel already exists\")\n",
|
62 |
+
" else:\n",
|
63 |
+
" modelname = os.path.basename(model_LINK)\n",
|
64 |
+
" loramodel = f\"/workspace/ComfyUI/models/checkpoints/{modelname}\"\n",
|
65 |
+
" if not os.path.exists(loramodel):\n",
|
66 |
+
" gdown.download(\n",
|
67 |
+
" url=model_LINK, output=loramodel, quiet=False, fuzzy=True\n",
|
68 |
+
" )\n",
|
69 |
+
" clear_output()\n",
|
70 |
+
" else:\n",
|
71 |
+
" print(\"[1;33mModel already exists\")\n",
|
72 |
+
"\n",
|
73 |
+
" if os.path.exists(loramodel):\n",
|
74 |
+
" print(\"[1;32mCheckpoints downloaded\")\n",
|
75 |
+
" else:\n",
|
76 |
+
" print(\"[1;31mWrong link, check that the link is valid\")\n",
|
77 |
+
"\n",
|
78 |
+
"def getsrc(url):\n",
|
79 |
+
"\n",
|
80 |
+
" parsed_url = urlparse(url)\n",
|
81 |
+
"\n",
|
82 |
+
" if parsed_url.netloc == \"civitai.com\":\n",
|
83 |
+
" src = \"civitai\"\n",
|
84 |
+
" elif parsed_url.netloc == \"drive.google.com\":\n",
|
85 |
+
" src = \"gdrive\"\n",
|
86 |
+
" elif parsed_url.netloc == \"huggingface.co\":\n",
|
87 |
+
" src = \"huggingface\"\n",
|
88 |
+
" else:\n",
|
89 |
+
" src = \"others\"\n",
|
90 |
+
" return src\n",
|
91 |
+
"def get_true_name(url):\n",
|
92 |
+
" response = requests.get(url)\n",
|
93 |
+
" soup = BeautifulSoup(response.text, \"html.parser\")\n",
|
94 |
+
" title_tag = soup.find(\"title\")\n",
|
95 |
+
" if title_tag:\n",
|
96 |
+
" title_text = title_tag.text\n",
|
97 |
+
" # Извлечение имени файла из тега title (предполагая, что имя файла указано в теге title)\n",
|
98 |
+
" file_name = title_text.split(\" - \")[0]\n",
|
99 |
+
" return file_name\n",
|
100 |
+
" else:\n",
|
101 |
+
" raise RuntimeError(\"Could not find the title tag in the HTML\")\n",
|
102 |
+
"\n",
|
103 |
+
"\n",
|
104 |
+
"def get_name(url, gdrive):\n",
|
105 |
+
"\n",
|
106 |
+
" from gdown.download import get_url_from_gdrive_confirmation\n",
|
107 |
+
"\n",
|
108 |
+
" if not gdrive:\n",
|
109 |
+
" response = requests.get(url, allow_redirects=False)\n",
|
110 |
+
" if \"Location\" in response.headers:\n",
|
111 |
+
" redirected_url = response.headers[\"Location\"]\n",
|
112 |
+
" quer = parse_qs(urlparse(redirected_url).query)\n",
|
113 |
+
" if \"response-content-disposition\" in quer:\n",
|
114 |
+
" disp_val = quer[\"response-content-disposition\"][0].split(\";\")\n",
|
115 |
+
" for vals in disp_val:\n",
|
116 |
+
" if vals.strip().startswith(\"filename=\"):\n",
|
117 |
+
" filenm = unquote(vals.split(\"=\", 1)[1].strip())\n",
|
118 |
+
" return filenm.replace('\"', \"\")\n",
|
119 |
+
" else:\n",
|
120 |
+
" headers = {\n",
|
121 |
+
" \"User-Agent\": \"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36\"\n",
|
122 |
+
" }\n",
|
123 |
+
" lnk = \"https://drive.google.com/uc?id={id}&export=download\".format(\n",
|
124 |
+
" id=url[url.find(\"/d/\") + 3 : url.find(\"/view\")]\n",
|
125 |
+
" )\n",
|
126 |
+
" res = requests.session().get(lnk, headers=headers, stream=True, verify=True)\n",
|
127 |
+
" res = requests.session().get(\n",
|
128 |
+
" get_url_from_gdrive_confirmation(res.text),\n",
|
129 |
+
" headers=headers,\n",
|
130 |
+
" stream=True,\n",
|
131 |
+
" verify=True,\n",
|
132 |
+
" )\n",
|
133 |
+
" content_disposition = six.moves.urllib_parse.unquote(\n",
|
134 |
+
" res.headers[\"Content-Disposition\"]\n",
|
135 |
+
" )\n",
|
136 |
+
" filenm = (\n",
|
137 |
+
" re.search(r\"filename\\*=UTF-8''(.*)\", content_disposition)\n",
|
138 |
+
" .groups()[0]\n",
|
139 |
+
" .replace(os.path.sep, \"_\")\n",
|
140 |
+
" )\n",
|
141 |
+
" return filenm\n",
|
142 |
+
"\n",
|
143 |
+
"def dwn(url, dst, msg):\n",
|
144 |
+
" file_size = None\n",
|
145 |
+
" req = Request(url, headers={\"User-Agent\": \"torch.hub\"})\n",
|
146 |
+
" u = urlopen(req)\n",
|
147 |
+
" meta = u.info()\n",
|
148 |
+
" if hasattr(meta, \"getheaders\"):\n",
|
149 |
+
" content_length = meta.getheaders(\"Content-Length\")\n",
|
150 |
+
" else:\n",
|
151 |
+
" content_length = meta.get_all(\"Content-Length\")\n",
|
152 |
+
" if content_length is not None and len(content_length) > 0:\n",
|
153 |
+
" file_size = int(content_length[0])\n",
|
154 |
+
"\n",
|
155 |
+
" with tqdm(\n",
|
156 |
+
" total=file_size,\n",
|
157 |
+
" disable=False,\n",
|
158 |
+
" mininterval=0.5,\n",
|
159 |
+
" bar_format=msg + \" |{bar:20}| {percentage:3.0f}%\",\n",
|
160 |
+
" ) as pbar:\n",
|
161 |
+
" with open(dst, \"wb\") as f:\n",
|
162 |
+
" while True:\n",
|
163 |
+
" buffer = u.read(8192)\n",
|
164 |
+
" if len(buffer) == 0:\n",
|
165 |
+
" break\n",
|
166 |
+
" f.write(buffer)\n",
|
167 |
+
" pbar.update(len(buffer))\n",
|
168 |
+
" f.close()\n",
|
169 |
+
"\n"
|
170 |
+
]
|
171 |
+
},
|
172 |
+
{
|
173 |
+
"cell_type": "code",
|
174 |
+
"execution_count": null,
|
175 |
+
"id": "61e91850-23ac-49e4-a747-0d5f1883e663",
|
176 |
+
"metadata": {},
|
177 |
+
"outputs": [],
|
178 |
+
"source": [
|
179 |
+
"modeldwn(\"https://civitai.com/api/download/models/56071\")\n",
|
180 |
+
"modeldwn(\"https://civitai.com/api/download/models/128713\")"
|
181 |
+
]
|
182 |
+
},
|
183 |
+
{
|
184 |
+
"cell_type": "code",
|
185 |
+
"execution_count": null,
|
186 |
+
"id": "17ac89a0-45ff-4a3c-8ecc-4dd4642a2e44",
|
187 |
+
"metadata": {},
|
188 |
+
"outputs": [],
|
189 |
+
"source": [
|
190 |
+
"python -m venv venv\n",
|
191 |
+
"source venv/bin/activate\n",
|
192 |
+
"cd ComfyUI\n",
|
193 |
+
"pip install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu121\n",
|
194 |
+
"\n",
|
195 |
+
"requirements.txt\n",
|
196 |
+
"torch\n",
|
197 |
+
"torchsde\n",
|
198 |
+
"einops\n",
|
199 |
+
"transformers>=4.25.1\n",
|
200 |
+
"safetensors>=0.3.0\n",
|
201 |
+
"aiohttp\n",
|
202 |
+
"accelerate\n",
|
203 |
+
"pyyaml\n",
|
204 |
+
"Pillow\n",
|
205 |
+
"scipy\n",
|
206 |
+
"tqdm\n",
|
207 |
+
"psutil\n",
|
208 |
+
"opencv-python\n",
|
209 |
+
"imageio-ffmpeg\n",
|
210 |
+
"\n",
|
211 |
+
"pip install -r requirements.txt\n",
|
212 |
+
"\n",
|
213 |
+
"cd /workspace/ComfyUI/custom_nodes\n",
|
214 |
+
"git clone https://github.com/ltdrdata/ComfyUI-Manager.git\n",
|
215 |
+
"git clone https://github.com/Kosinkadink/ComfyUI-AnimateDiff-Evolved\n",
|
216 |
+
"git clone https://github.com/Kosinkadink/ComfyUI-Advanced-ControlNet\n",
|
217 |
+
"git clone https://github.com/Kosinkadink/ComfyUI-VideoHelperSuite.git\n",
|
218 |
+
"git clone https://github.com/Fannovel16/comfyui_controlnet_aux.git\n",
|
219 |
+
"\n",
|
220 |
+
"cd /workspace/ComfyUI/models/vae\n",
|
221 |
+
"gdown https://drive.google.com/uc?id=1ukSErH_cjsgb1SzHmnMpEYGsrmwtaLGz\n",
|
222 |
+
"gdown https://drive.google.com/uc?id=1hWfed2gQABLn30v8pxSbgLWe_h2udg_R\n",
|
223 |
+
"\n",
|
224 |
+
"cd /workspace/ComfyUI/models/checkpoints\n",
|
225 |
+
"gdown https://drive.google.com/uc?id=1O0ez3jYp_u0DLcdsQ9EsIHSQZciOakWn\n",
|
226 |
+
"gdown https://drive.google.com/uc?id=1qzrSYXM-fzfcQKN0Z2bsA-Qh1zcOasPu\n",
|
227 |
+
"\n",
|
228 |
+
"cd /workspace/ComfyUI/custom_nodes/ComfyUI-AnimateDiff-Evolved/models\n",
|
229 |
+
"wget https://huggingface.co/guoyww/animatediff/resolve/main/mm_sd_v15_v2.ckpt\n",
|
230 |
+
"wget https://huggingface.co/CiaraRowles/TemporalDiff/resolve/main/temporaldiff-v1-animatediff.safetensors\n",
|
231 |
+
"\n",
|
232 |
+
"cd /workspace/ComfyUI/models/controlnet/\n",
|
233 |
+
"wget https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11f1p_sd15_depth.pth\n",
|
234 |
+
"wget https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15_lineart.pth\n",
|
235 |
+
"wget https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15_openpose.pth\n",
|
236 |
+
"wget https://huggingface.co/monster-labs/control_v1p_sd15_qrcode_monster/resolve/main/control_v1p_sd15_qrcode_monster.safetensors\n",
|
237 |
+
"\n",
|
238 |
+
"cd /workspace/ComfyUI/models/clip_vision/\n",
|
239 |
+
"wget https://huggingface.co/h94/IP-Adapter/resolve/main/models/image_encoder/model.safetensors\n",
|
240 |
+
"\n",
|
241 |
+
"cd /workspace/ComfyUI/models/upscale_models/\n",
|
242 |
+
"wget https://huggingface.co/lokCX/4x-Ultrasharp/resolve/main/4x-UltraSharp.pth\n",
|
243 |
+
"\n",
|
244 |
+
"cd /workspace/ComfyUI\n",
|
245 |
+
"python main.py --listen"
|
246 |
+
]
|
247 |
+
}
|
248 |
+
],
|
249 |
+
"metadata": {
|
250 |
+
"kernelspec": {
|
251 |
+
"display_name": "Python 3 (ipykernel)",
|
252 |
+
"language": "python",
|
253 |
+
"name": "python3"
|
254 |
+
},
|
255 |
+
"language_info": {
|
256 |
+
"codemirror_mode": {
|
257 |
+
"name": "ipython",
|
258 |
+
"version": 3
|
259 |
+
},
|
260 |
+
"file_extension": ".py",
|
261 |
+
"mimetype": "text/x-python",
|
262 |
+
"name": "python",
|
263 |
+
"nbconvert_exporter": "python",
|
264 |
+
"pygments_lexer": "ipython3",
|
265 |
+
"version": "3.10.12"
|
266 |
+
}
|
267 |
+
},
|
268 |
+
"nbformat": 4,
|
269 |
+
"nbformat_minor": 5
|
270 |
+
}
|