Created
September 23, 2025 05:07
-
-
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
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
| 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()) |
Author
Author
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")
Author
Code to split a huggingface URL:
from urllib.parse import urlparse
def huggingface_url_to_repo_and_path(url: str):
"""
Convert a Hugging Face resolve URL into [repo_id, path].
Example:
https://huggingface.co/Lightricks/LTX-2/resolve/main/ltx-2-19b-distilled.safetensors
->
["Lightricks/LTX-2", "main/ltx-2-19b-distilled.safetensors"]
"""
parsed = urlparse(url)
parts = parsed.path.strip("/").split("/")
if len(parts) < 5 or parts[2] != "resolve":
raise ValueError("Not a valid Hugging Face resolve URL")
repo = f"{parts[0]}/{parts[1]}"
path = "/".join(parts[3:])
return [repo, path]
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To download models: