Views
No views yet

models/diffusion_models/dreamcoil-anima.safetensors (Custom Civitai Fine-tune)models/text_encoders/qwen_3_06b_base.safetensors (Qwen 0.6B)models/vae/qwen_image_vae.safetensors (Qwen VAE)1import os
2import sys
3import subprocess
4
5# 1. Setup ComfyUI and requirements
6if not os.path.exists("ComfyUI"):
7 print("Cloning ComfyUI...")
8 subprocess.run(["git", "clone", "https://github.com/comfyanonymous/ComfyUI.git"])
9 subprocess.run([sys.executable, "-m", "pip", "install", "-r", "ComfyUI/requirements.txt"])
10 subprocess.run([sys.executable, "-m", "pip", "install", "huggingface_hub", "torch", "numpy", "Pillow"])
11
12sys.path.append("./ComfyUI")
13
14# 2. Download all components from this HF Repo
15from huggingface_hub import hf_hub_download
16
17
18REPO_ID = "EngineerGL/DreamCoil-Anima"
19
20print("Downloading model files from Hugging Face...")
21# This will recreate the correct folder structure inside ComfyUI/models/
22hf_hub_download(repo_id=REPO_ID, filename="diffusion_models/dreamcoil-anima.safetensors", local_dir="./ComfyUI/models")
23hf_hub_download(repo_id=REPO_ID, filename="text_encoders/qwen_3_06b_base.safetensors", local_dir="./ComfyUI/models")
24hf_hub_download(repo_id=REPO_ID, filename="vae/qwen_image_vae.safetensors", local_dir="./ComfyUI/models")
25
26# 3. Import ComfyUI nodes
27import torch
28import numpy as np
29from PIL import Image
30from nodes import NODE_CLASS_MAPPINGS
31import folder_paths
32
33# Register folders explicitly to avoid any lookup issues
34folder_paths.add_model_folder_path("clip", "./ComfyUI/models/text_encoders")
35folder_paths.add_model_folder_path("vae", "./ComfyUI/models/vae")
36folder_paths.add_model_folder_path("unet", "./ComfyUI/models/diffusion_models")
37
38UNETLoader = NODE_CLASS_MAPPINGS["UNETLoader"]()
39CLIPLoader = NODE_CLASS_MAPPINGS["CLIPLoader"]()
40VAELoader = NODE_CLASS_MAPPINGS["VAELoader"]()
41CLIPTextEncode = NODE_CLASS_MAPPINGS["CLIPTextEncode"]()
42KSampler = NODE_CLASS_MAPPINGS["KSampler"]()
43VAEDecode = NODE_CLASS_MAPPINGS["VAEDecode"]()
44EmptyLatentImage = NODE_CLASS_MAPPINGS["EmptyLatentImage"]()
45
46print("Loading weights into memory...")
47with torch.inference_mode():
48 unet = UNETLoader.load_unet("dreamcoil-anima.safetensors", "default")[0]
49
50 # Try using 'cosmos' type for Cosmos-based Qwen text encoder
51 try:
52 clip = CLIPLoader.load_clip("qwen_3_06b_base.safetensors", type="cosmos")[0]
53 except Exception:
54 clip = CLIPLoader.load_clip("qwen_3_06b_base.safetensors")[0]
55
56 vae = VAELoader.load_vae("qwen_image_vae.safetensors")[0]
57
58# 4. Generate Image
59@torch.inference_mode()
60def generate(positive_prompt, negative_prompt, seed=42):
61 print("Generating...")
62 positive = CLIPTextEncode.encode(clip, positive_prompt)[0]
63 negative = CLIPTextEncode.encode(clip, negative_prompt)[0]
64 latent = EmptyLatentImage.generate(1024, 1024, batch_size=1)[0]
65
66 samples = KSampler.sample(
67 unet, seed=seed, steps=25, cfg=5.0,
68 sampler_name="euler", scheduler="normal",
69 positive=positive, negative=negative, latent_image=latent
70 )[0]
71
72 decoded = VAEDecode.decode(vae, samples)[0].detach()
73 img_array = np.array(decoded * 255, dtype=np.uint8)[0]
74
75 output_path = "output_anima.png"
76 Image.fromarray(img_array).save(output_path)
77 print(f"Done! Image saved as {output_path}")
78
79prompt = "masterpiece, best quality, score_9, 1girl, solo, @wlop, cyberpunk city, neon lights"
80negative_prompt = "blurry, ugly, low quality, score_1, score_2"
81
82generate(prompt, negative_prompt, seed=42)