- Created overnight generation system
- Added master character references (Gronk, Kai)
- Implemented auto-commit for all generated assets
- Created comprehensive documentation and changelogs
- Setup FULL generator (850+ assets without NPCs)
- Added progress tracking and status check scripts
Ready for overnight mass generation 🌙
162 lines
5.6 KiB
Python
162 lines
5.6 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
🚀 FRESH TEST - Generira 3 nove slike ki jih še ni
|
|
"""
|
|
|
|
import os
|
|
import sys
|
|
import json
|
|
import time
|
|
import uuid
|
|
import requests
|
|
import subprocess
|
|
from pathlib import Path
|
|
from datetime import datetime
|
|
|
|
try:
|
|
from rembg import remove
|
|
from PIL import Image
|
|
except ImportError:
|
|
print("📦 Installing rembg...")
|
|
os.system("pip3 install --user rembg pillow onnxruntime")
|
|
from rembg import remove
|
|
from PIL import Image
|
|
|
|
# Configuration
|
|
COMFYUI_URL = "http://127.0.0.1:8000"
|
|
OUTPUT_DIR = Path("/Users/davidkotnik/repos/novafarma/assets/images")
|
|
REPO_DIR = Path("/Users/davidkotnik/repos/novafarma")
|
|
|
|
STYLE = "2D indie game sprite, cartoon vector style, clean smooth lines, full body visible, isolated on pure white background"
|
|
NEGATIVE = "pixel art, pixelated, 3d, realistic, photo, blurry, watermark, text, green background"
|
|
|
|
# 🆕 NOVE SLIKE - Še ne generirane
|
|
NEW_ASSETS = [
|
|
("npcs", "gronk_front_walk1", "Gronk massive troll, PINK dreadlocks, black baggy t-shirt and pants, pink sneakers, holding vape, front view walking left leg forward"),
|
|
("npcs", "kai_front_walk1", "Kai teenage survivor, GREEN dreadlocks, blue jacket, torn jeans, boots, front view walking left leg forward"),
|
|
("zivali", "fox_red", "red fox wildlife animal, bushy tail, clever expression, side view"),
|
|
]
|
|
|
|
|
|
def log(msg):
|
|
ts = datetime.now().strftime("%H:%M:%S")
|
|
print(f"[{ts}] {msg}")
|
|
sys.stdout.flush()
|
|
|
|
|
|
def git_commit(file_path, category, name):
|
|
"""Auto-commit generated asset"""
|
|
try:
|
|
rel_path = file_path.relative_to(REPO_DIR)
|
|
subprocess.run(["git", "add", str(rel_path)], cwd=REPO_DIR, check=True, capture_output=True)
|
|
subprocess.run(["git", "commit", "-m", f"🎨 Generated: {category}/{name}"], cwd=REPO_DIR, check=True, capture_output=True)
|
|
log(f" 📝 Git committed: {rel_path}")
|
|
return True
|
|
except:
|
|
return False
|
|
|
|
|
|
def create_workflow(prompt_text, output_name, size=512):
|
|
seed = int(time.time() * 1000) % 2147483647
|
|
full_prompt = f"{STYLE}, {prompt_text}"
|
|
|
|
return {
|
|
"1": {"class_type": "CheckpointLoaderSimple", "inputs": {"ckpt_name": "dreamshaper_8.safetensors"}},
|
|
"2": {"class_type": "EmptyLatentImage", "inputs": {"width": size, "height": size, "batch_size": 1}},
|
|
"3": {"class_type": "CLIPTextEncode", "inputs": {"text": full_prompt, "clip": ["1", 1]}},
|
|
"4": {"class_type": "CLIPTextEncode", "inputs": {"text": NEGATIVE, "clip": ["1", 1]}},
|
|
"5": {
|
|
"class_type": "KSampler",
|
|
"inputs": {
|
|
"seed": seed, "steps": 30, "cfg": 7.5,
|
|
"sampler_name": "euler_ancestral", "scheduler": "karras",
|
|
"denoise": 1.0, "model": ["1", 0],
|
|
"positive": ["3", 0], "negative": ["4", 0], "latent_image": ["2", 0]
|
|
}
|
|
},
|
|
"6": {"class_type": "VAEDecode", "inputs": {"samples": ["5", 0], "vae": ["1", 2]}},
|
|
"7": {"class_type": "SaveImage", "inputs": {"filename_prefix": output_name, "images": ["6", 0]}}
|
|
}
|
|
|
|
|
|
def queue_prompt(workflow):
|
|
try:
|
|
r = requests.post(f"{COMFYUI_URL}/prompt", json={"prompt": workflow, "client_id": f"test_{uuid.uuid4().hex[:8]}"}, timeout=10)
|
|
return r.json().get("prompt_id")
|
|
except Exception as e:
|
|
log(f"❌ Queue error: {e}")
|
|
return None
|
|
|
|
|
|
def wait_completion(prompt_id, timeout=120):
|
|
start = time.time()
|
|
while time.time() - start < timeout:
|
|
try:
|
|
r = requests.get(f"{COMFYUI_URL}/history/{prompt_id}", timeout=5)
|
|
if prompt_id in r.json() and r.json()[prompt_id].get("outputs"):
|
|
return True
|
|
except:
|
|
pass
|
|
time.sleep(2)
|
|
return False
|
|
|
|
|
|
def download_and_process(prompt_id, output_path):
|
|
try:
|
|
h = requests.get(f"{COMFYUI_URL}/history/{prompt_id}").json()
|
|
for out in h.get(prompt_id, {}).get("outputs", {}).values():
|
|
for img in out.get("images", []):
|
|
r = requests.get(f"{COMFYUI_URL}/view", params={"filename": img["filename"], "subfolder": img.get("subfolder", ""), "type": "output"})
|
|
if r.status_code == 200:
|
|
output_path.parent.mkdir(parents=True, exist_ok=True)
|
|
from io import BytesIO
|
|
transparent_img = remove(Image.open(BytesIO(r.content)))
|
|
transparent_img.save(str(output_path), "PNG")
|
|
return True
|
|
return False
|
|
except Exception as e:
|
|
log(f"❌ Download error: {e}")
|
|
return False
|
|
|
|
|
|
def main():
|
|
log("="*60)
|
|
log("🚀 FRESH TEST - Generiranje Novih Slik")
|
|
log(" Z avtomatskim Git commitom")
|
|
log("="*60)
|
|
|
|
try:
|
|
r = requests.get(f"{COMFYUI_URL}/system_stats", timeout=5)
|
|
log(f"✅ ComfyUI v{r.json()['system']['comfyui_version']} running")
|
|
except:
|
|
log("❌ ComfyUI not running!")
|
|
return
|
|
|
|
log(f"\n🎯 Generating {len(NEW_ASSETS)} new assets...\n")
|
|
|
|
for i, (cat, name, prompt) in enumerate(NEW_ASSETS, 1):
|
|
path = OUTPUT_DIR / cat / f"{name}.png"
|
|
|
|
if path.exists():
|
|
log(f"[{i}/{len(NEW_ASSETS)}] ⏭️ {name} - skipping (exists)")
|
|
continue
|
|
|
|
log(f"[{i}/{len(NEW_ASSETS)}] 🎨 {name}...")
|
|
|
|
wf = create_workflow(prompt, name, 512)
|
|
pid = queue_prompt(wf)
|
|
|
|
if pid and wait_completion(pid) and download_and_process(pid, path):
|
|
log(f" ✅ Generated & transparent!")
|
|
git_commit(path, cat, name)
|
|
else:
|
|
log(f" ❌ FAILED")
|
|
|
|
log("\n" + "="*60)
|
|
log("🚀 FRESH TEST COMPLETE!")
|
|
log("="*60)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|