Skip to content

Instantly share code, notes, and snippets.

@hathibelagal-dev
Created September 23, 2025 05:07
Show Gist options
  • Save hathibelagal-dev/bcc2d29fc8edab676d0f593eca069318 to your computer and use it in GitHub Desktop.
Save hathibelagal-dev/bcc2d29fc8edab676d0f593eca069318 to your computer and use it in GitHub Desktop.
A minimal script to get started with using ComfyUI as a library
import sys, os
comfy_path = "/content/ComfyUI"
sys.path.insert(0, comfy_path)
import importlib.util
utils_path = os.path.join(comfy_path, "utils")
spec = importlib.util.spec_from_file_location("utils", os.path.join(utils_path, "__init__.py") if os.path.exists(os.path.join(utils_path, "__init__.py")) else os.devnull)
utils = importlib.util.module_from_spec(spec)
sys.modules["utils"] = utils
import nodes
import asyncio
from server import PromptServer
loop = asyncio.new_event_loop()
PromptServer.instance = PromptServer(loop)
async def t():
await nodes.init_external_custom_nodes()
n = nodes.NODE_CLASS_MAPPINGS
for item in n:
if item.find("VHS_") != -1:
print(item)
asyncio.run(t())
@hathibelagal-dev
Copy link
Author

hathibelagal-dev commented Sep 27, 2025

To download models:

from huggingface_hub import hf_hub_download
def download_file(repo, filename, save_location):
  output_path = hf_hub_download(repo_id=repo, filename=filename, local_dir="/content/checkpoints")
  print(output_path)
  output_filename = output_path.split("/")[-1]
  !ln -f {output_path} /content/ComfyUI/models/{save_location}/{output_filename}
  return f"/content/ComfyUI/models/{save_location}/{output_filename}"

@hathibelagal-dev
Copy link
Author

hathibelagal-dev commented Sep 27, 2025

For example, for Wan 2.1 T2V with lightx2v LoRA:

download_file("Comfy-Org/Wan_2.1_ComfyUI_repackaged", "split_files/vae/wan_2.1_vae.safetensors", "vae")
download_file("city96/Wan2.1-T2V-14B-gguf", "wan2.1-t2v-14b-Q4_K_M.gguf", "unet")
download_file("Comfy-Org/Wan_2.1_ComfyUI_repackaged", "split_files/text_encoders/umt5_xxl_fp8_e4m3fn_scaled.safetensors", "text_encoders")
download_file("lightx2v/Wan2.1-T2V-14B-StepDistill-CfgDistill-Lightx2v", "loras/Wan21_T2V_14B_lightx2v_cfg_step_distill_lora_rank64.safetensors", "loras")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment