Rishi Desai commited on
Commit
ae826ca
·
1 Parent(s): 847f39e

first files

Browse files
Files changed (3) hide show
  1. install.py +277 -0
  2. main.py +3 -3
  3. utils.py +1 -1
install.py ADDED
@@ -0,0 +1,277 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+
3
+ # Define paths
4
+ BASE_PATH = "./ComfyUI"
5
+ MODEL_PATH = os.path.join(BASE_PATH, "models")
6
+ CACHE_PATH = "/workspace/huggingface_cache"
7
+
8
+ os.environ["HF_HOME"] = CACHE_PATH
9
+ os.makedirs(CACHE_PATH, exist_ok=True)
10
+
11
+
12
+ def run_command(command):
13
+ """Run a shell command using os.system() (simpler than subprocess)."""
14
+ print(f"🔄 Running: {command}")
15
+ exit_code = os.system(command)
16
+
17
+ if exit_code != 0:
18
+ print(f"❌ Command failed: {command} (Exit Code: {exit_code})")
19
+ exit(1) # Exit on failure
20
+
21
+
22
+ def install_dependencies():
23
+ """Install system dependencies and Python packages."""
24
+ print("📦 Installing dependencies...")
25
+ # run_command("apt-get update && apt-get install -y git wget curl libgl1-mesa-glx libglib2.0-0 tmux emacs git-lfs")
26
+ run_command("pip install --upgrade pip")
27
+ run_command("pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu124")
28
+ run_command("pip install xformers --index-url https://download.pytorch.org/whl/cu124")
29
+ run_command("pip install -r requirements.txt")
30
+ print("✅ Dependencies installed.")
31
+
32
+
33
+ def manage_git_repo(repo_url, install_path, requirements=False, submodules=False):
34
+ """Clone or update a git repository and handle its dependencies.
35
+
36
+ Args:
37
+ repo_url: URL of the git repository
38
+ install_path: Where to install/update the repository
39
+ requirements: Whether to install requirements.txt
40
+ submodules: Whether to update git submodules
41
+ """
42
+ if not os.path.exists(install_path) or not os.path.isdir(install_path) or not os.path.exists(
43
+ os.path.join(install_path, ".git")):
44
+ print(f"📂 Cloning {os.path.basename(install_path)}...")
45
+ run_command(f"git clone {repo_url} {install_path}")
46
+ else:
47
+ print(f"🔄 {os.path.basename(install_path)} exists. Checking for updates...")
48
+
49
+ # Change to repo directory and update
50
+ os.chdir(install_path)
51
+ run_command("git pull")
52
+
53
+ if submodules:
54
+ run_command("git submodule update --init --recursive")
55
+
56
+ if requirements:
57
+ run_command("python -m pip install -r requirements.txt")
58
+
59
+ print(f"✅ {os.path.basename(install_path)} installed and updated.")
60
+
61
+
62
+ def install_comfyui():
63
+ """Clone and set up ComfyUI if not already installed."""
64
+ manage_git_repo(
65
+ "https://github.com/comfyanonymous/ComfyUI.git",
66
+ BASE_PATH,
67
+ requirements=True
68
+ )
69
+
70
+
71
+ def download_huggingface_models():
72
+ """Download required models from Hugging Face."""
73
+ from huggingface_hub import hf_hub_download
74
+ hf_models = [
75
+ {"repo_id": "black-forest-labs/FLUX.1-dev", "filename": "flux1-dev.safetensors", "folder": "unet"},
76
+ {"repo_id": "black-forest-labs/FLUX.1-dev", "filename": "ae.safetensors", "folder": "vae"},
77
+ {"repo_id": "Shakker-Labs/FLUX.1-dev-ControlNet-Union-Pro", "filename": "diffusion_pytorch_model.safetensors",
78
+ "folder": "controlnet"},
79
+ {"repo_id": "guozinan/PuLID", "filename": "pulid_flux_v0.9.1.safetensors", "folder": "pulid"},
80
+ {"repo_id": "comfyanonymous/flux_text_encoders", "filename": "t5xxl_fp16.safetensors", "folder": "text_encoders"},
81
+ {"repo_id": "comfyanonymous/flux_text_encoders", "filename": "clip_l.safetensors", "folder": "text_encoders"},
82
+ ]
83
+
84
+ # Dictionary mapping repo_ids to specific filenames
85
+ filename_mappings = {
86
+ "Shakker-Labs/FLUX.1-dev-ControlNet-Union-Pro": "Flux_Dev_ControlNet_Union_Pro_ShakkerLabs.safetensors",
87
+ }
88
+
89
+ for model in hf_models:
90
+ try:
91
+ model_path = hf_hub_download(
92
+ repo_id=model["repo_id"],
93
+ filename=model["filename"],
94
+ cache_dir=CACHE_PATH,
95
+ repo_type=model.get("repo_type", "model")
96
+ )
97
+ target_dir = os.path.join(MODEL_PATH, model["folder"])
98
+ os.makedirs(target_dir, exist_ok=True)
99
+
100
+ # Use mapping if it exists, otherwise use original filename
101
+ file_name_only = filename_mappings.get(model["repo_id"], os.path.basename(model["filename"]))
102
+ target_path = os.path.join(target_dir, file_name_only)
103
+
104
+ if not os.path.exists(target_path):
105
+ os.symlink(model_path, target_path)
106
+ print(f"✅ Linked: {file_name_only}")
107
+ else:
108
+ print(f"✅ Already exists: {file_name_only}")
109
+ except Exception as e:
110
+ print(f"❌ Failed to download {model['filename']}: {e}")
111
+
112
+
113
+ def download_and_extract_antelopev2():
114
+ """Download and extract AntelopeV2 model for insightface."""
115
+ import zipfile, requests
116
+ base_path = os.path.join(BASE_PATH, "models/insightface/models")
117
+ download_url = "https://huggingface.co/MonsterMMORPG/tools/resolve/main/antelopev2.zip"
118
+ zip_path = os.path.join(base_path, "antelopev2.zip")
119
+ extract_path = os.path.join(base_path, "antelopev2")
120
+
121
+ os.makedirs(base_path, exist_ok=True)
122
+
123
+ if not os.path.exists(extract_path):
124
+ print(f"📥 Downloading AntelopeV2 model...")
125
+ try:
126
+ response = requests.get(download_url, stream=True)
127
+ response.raise_for_status()
128
+ with open(zip_path, "wb") as file:
129
+ for chunk in response.iter_content(chunk_size=8192):
130
+ file.write(chunk)
131
+ print("✅ Download complete.")
132
+
133
+ print("📂 Extracting AntelopeV2 model...")
134
+ with zipfile.ZipFile(zip_path, "r") as zip_ref:
135
+ zip_ref.extractall(base_path)
136
+ print("✅ Extraction complete.")
137
+
138
+ os.remove(zip_path)
139
+ print("🗑️ Cleaned up ZIP file.")
140
+ except Exception as e:
141
+ print(f"❌ Failed to download/extract AntelopeV2: {e}")
142
+ else:
143
+ print("✅ AntelopeV2 model already exists")
144
+
145
+
146
+ def install_custom_nodes():
147
+ """Install all custom nodes for ComfyUI."""
148
+ # List of custom nodes to install via comfy node install
149
+ custom_nodes = [
150
+ "comfyui_essentials",
151
+ "comfyui-detail-daemon",
152
+ "comfyui-advancedliveportrait",
153
+ "comfyui-impact-pack",
154
+ "comfyui-custom-scripts",
155
+ "rgthree-comfy",
156
+ "comfyui-easy-use",
157
+ "comfyui-florence2",
158
+ "comfyui-kjnodes",
159
+ "cg-use-everywhere",
160
+ "comfyui-impact-subpack",
161
+ "pulid_comfyui",
162
+ "comfyui_pulid_flux_ll",
163
+ "comfyui_birefnet_ll",
164
+ "comfyui_controlnet_aux"
165
+ ]
166
+
167
+ os.chdir(BASE_PATH)
168
+ # First update all existing nodes
169
+ run_command("comfy node update all")
170
+
171
+ # Then install any missing nodes
172
+ for node in custom_nodes:
173
+ run_command(f"comfy node install {node}")
174
+
175
+ print("✅ Installed and updated all ComfyUI registry nodes.")
176
+
177
+ # List of custom nodes to install from git
178
+ custom_nodes_git = [
179
+ {
180
+ "repo": "https://github.com/WASasquatch/was-node-suite-comfyui.git",
181
+ "name": "was-node-suite-comfyui",
182
+ "requirements": True
183
+ },
184
+ {
185
+ "repo": "https://github.com/ssitu/ComfyUI_UltimateSDUpscale.git",
186
+ "name": "ComfyUI_UltimateSDUpscale",
187
+ "submodules": True
188
+ },
189
+ {
190
+ "repo": "https://github.com/huanngzh/ComfyUI-MVAdapter",
191
+ "name": "ComfyUI-MVAdapter",
192
+ "requirements": True
193
+ },
194
+ {
195
+ "repo": "https://github.com/sipie800/ComfyUI-PuLID-Flux-Enhanced.git",
196
+ "name": "ComfyUI-PuLID-Flux-Enhanced",
197
+ "requirements": True
198
+ },
199
+ {
200
+ "repo": "https://github.com/liusida/ComfyUI-AutoCropFaces.git",
201
+ "name": "ComfyUI-AutoCropFaces",
202
+ "submodules": True
203
+ },
204
+ {
205
+ "repo": "https://github.com/giriss/comfy-image-saver.git",
206
+ "name": "comfy-image-saver",
207
+ "requirements": True
208
+ },
209
+ {
210
+ "repo": "https://github.com/spacepxl/ComfyUI-Image-Filters.git",
211
+ "name": "ComfyUI-Image-Filters",
212
+ "requirements": True
213
+ },
214
+ {
215
+ "repo": "https://github.com/pydn/ComfyUI-to-Python-Extension.git",
216
+ "name": "ComfyUI-to-Python-Extension",
217
+ "requirements": True
218
+ },
219
+ {
220
+ "repo": "https://github.com/Limitex/ComfyUI-Diffusers.git",
221
+ "name": "ComfyUI-Diffusers",
222
+ "requirements": True,
223
+ "post_install": [
224
+ "git clone https://github.com/cumulo-autumn/StreamDiffusion.git",
225
+ "python -m streamdiffusion.tools.install-tensorrt"
226
+ ]
227
+ },
228
+ {
229
+ "repo": "https://github.com/Vaibhavs10/ComfyUI-DDUF.git",
230
+ "name": "ComfyUI-DDUF",
231
+ "requirements": True
232
+ },
233
+ {
234
+ "repo": "https://github.com/Chaoses-Ib/ComfyScript.git",
235
+ "name": "ComfyScript",
236
+ "post_install": [
237
+ "python -m pip install -e \".[default]\""
238
+ ]
239
+ }
240
+ ]
241
+
242
+ # Install nodes from git
243
+ os.chdir(os.path.join(BASE_PATH, "custom_nodes"))
244
+ for node in custom_nodes_git:
245
+ repo_name = node["name"]
246
+ repo_path = os.path.join(BASE_PATH, "custom_nodes", repo_name)
247
+ manage_git_repo(
248
+ node["repo"],
249
+ repo_path,
250
+ requirements=node.get("requirements", False),
251
+ submodules=node.get("submodules", False)
252
+ )
253
+
254
+ # Handle any post-install commands
255
+ if "post_install" in node:
256
+ os.chdir(repo_path)
257
+ for command in node["post_install"]:
258
+ run_command(command)
259
+
260
+
261
+ def install_comfyui_manager():
262
+ """Install ComfyUI Manager."""
263
+ manager_path = os.path.join(BASE_PATH, "custom_nodes", "ComfyUI-Manager")
264
+ manage_git_repo(
265
+ "https://github.com/ltdrdata/ComfyUI-Manager",
266
+ manager_path,
267
+ requirements=True
268
+ )
269
+
270
+
271
+ if __name__ == "__main__":
272
+ # install_dependencies()
273
+ install_comfyui()
274
+ install_comfyui_manager()
275
+ # download_huggingface_models()
276
+ # install_custom_nodes()
277
+ print("🎉 Setup Complete! Run `run.py` to start ComfyUI.")
main.py CHANGED
@@ -5,6 +5,7 @@ from utils import crop_face, upscale_image
5
  def parse_args():
6
  parser = argparse.ArgumentParser(description='Face Enhancement Tool')
7
  parser.add_argument('--input', type=str, required=True, help='Path to the input image')
 
8
  parser.add_argument('--crop', action='store_true', help='Whether to crop the image')
9
  parser.add_argument('--upscale', action='store_true', help='Whether to upscale the image')
10
  parser.add_argument('--output', type=str, required=True, help='Path to save the output image')
@@ -28,9 +29,9 @@ def main():
28
  print(f"Upscale enabled: {args.upscale}")
29
  print(f"Output will be saved to: {args.output}")
30
 
31
- face_image = args.input
32
  if args.crop:
33
- crop_face(args.input, "./scratch/cropped_face.png")
34
  face_image = "./scratch/cropped_face.png"
35
 
36
  if args.upscale:
@@ -38,6 +39,5 @@ def main():
38
  face_image = "./scratch/upscaled_face.png"
39
 
40
 
41
-
42
  if __name__ == "__main__":
43
  main()
 
5
  def parse_args():
6
  parser = argparse.ArgumentParser(description='Face Enhancement Tool')
7
  parser.add_argument('--input', type=str, required=True, help='Path to the input image')
8
+ parser.add_argument('--ref', type=str, required=True, help='Path to the reference image')
9
  parser.add_argument('--crop', action='store_true', help='Whether to crop the image')
10
  parser.add_argument('--upscale', action='store_true', help='Whether to upscale the image')
11
  parser.add_argument('--output', type=str, required=True, help='Path to save the output image')
 
29
  print(f"Upscale enabled: {args.upscale}")
30
  print(f"Output will be saved to: {args.output}")
31
 
32
+ face_image = args.ref
33
  if args.crop:
34
+ crop_face(face_image, "./scratch/cropped_face.png")
35
  face_image = "./scratch/cropped_face.png"
36
 
37
  if args.upscale:
 
39
  face_image = "./scratch/upscaled_face.png"
40
 
41
 
 
42
  if __name__ == "__main__":
43
  main()
utils.py CHANGED
@@ -6,7 +6,7 @@ import sys
6
  import cv2
7
  import base64
8
  import aiohttp
9
- from fal import Client as FalClient
10
  sys.path.append('./ComfyUI_AutoCropFaces')
11
  from dotenv import load_dotenv
12
  load_dotenv()
 
6
  import cv2
7
  import base64
8
  import aiohttp
9
+ import fal_client
10
  sys.path.append('./ComfyUI_AutoCropFaces')
11
  from dotenv import load_dotenv
12
  load_dotenv()