💾 Session checkpoint - 155 assets generated, style testing in progress
This commit is contained in:
Binary file not shown.
|
Before Width: | Height: | Size: 435 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 148 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 156 KiB |
BIN
assets/images/zivali/pig_normal.png
Normal file
BIN
assets/images/zivali/pig_normal.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 177 KiB |
BIN
assets/images/zivali/test_cow_stardew.png
Normal file
BIN
assets/images/zivali/test_cow_stardew.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 67 KiB |
170
scripts/test_stardew_style.py
Normal file
170
scripts/test_stardew_style.py
Normal file
@@ -0,0 +1,170 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
🧪 STARDEW VALLEY STYLE TEST
|
||||
1 slika iz vsake kategorije
|
||||
"""
|
||||
|
||||
import os
|
||||
import sys
|
||||
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:
|
||||
os.system("pip3 install --user rembg pillow onnxruntime")
|
||||
from rembg import remove
|
||||
from PIL import Image
|
||||
|
||||
COMFYUI_URL = "http://127.0.0.1:8000"
|
||||
OUTPUT_DIR = Path("/Users/davidkotnik/repos/novafarma/assets/images")
|
||||
REPO_DIR = Path("/Users/davidkotnik/repos/novafarma")
|
||||
|
||||
# STARDEW VALLEY STYLE
|
||||
STYLE = """Stardew Valley game art style, 2D pixel-perfect sprite,
|
||||
clean pixel art, vibrant colors, cute game asset,
|
||||
top-down or side view, isolated on white background"""
|
||||
|
||||
NEGATIVE = """3d render, realistic, photorealistic, blurry,
|
||||
low quality, watermark, text, green background"""
|
||||
|
||||
# TEST SAMPLES - 1 iz vsake kategorije
|
||||
TEST_SAMPLES = [
|
||||
# Živali
|
||||
("zivali", "test_cow_stardew", "dairy cow, Stardew Valley farm animal"),
|
||||
|
||||
# Items - Tool
|
||||
("items", "test_axe_stardew", "iron axe tool, Stardew Valley item"),
|
||||
|
||||
# Items - Food
|
||||
("items", "test_bread_stardew", "bread loaf, Stardew Valley food"),
|
||||
|
||||
# Buildings
|
||||
("buildings", "test_barn_stardew", "small barn building, Stardew Valley farm structure"),
|
||||
|
||||
# Environment
|
||||
("environment", "test_tree_stardew", "oak tree, Stardew Valley nature"),
|
||||
|
||||
# Crops
|
||||
("crops", "test_wheat_stardew", "wheat crop plant, Stardew Valley farming"),
|
||||
|
||||
# Workstations
|
||||
("workstations", "test_anvil_stardew", "blacksmith anvil, Stardew Valley crafting"),
|
||||
|
||||
# UI
|
||||
("ui", "test_heart_stardew", "red heart icon, Stardew Valley UI element"),
|
||||
|
||||
# Mutants
|
||||
("mutanti", "test_slime_stardew", "green slime monster, Stardew Valley enemy"),
|
||||
|
||||
# Bosses
|
||||
("bosses", "test_dragon_stardew", "small dragon boss, Stardew Valley style"),
|
||||
]
|
||||
|
||||
def log(msg):
|
||||
ts = datetime.now().strftime("%H:%M:%S")
|
||||
print(f"[{ts}] {msg}")
|
||||
sys.stdout.flush()
|
||||
|
||||
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"❌ {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"❌ {e}")
|
||||
return False
|
||||
|
||||
def main():
|
||||
log("="*70)
|
||||
log("🧪 STARDEW VALLEY STYLE TEST")
|
||||
log(" 1 slika iz vsake kategorije")
|
||||
log("="*70)
|
||||
|
||||
try:
|
||||
r = requests.get(f"{COMFYUI_URL}/system_stats", timeout=5)
|
||||
log(f"✅ ComfyUI v{r.json()['system']['comfyui_version']}")
|
||||
except:
|
||||
log("❌ ComfyUI not running!")
|
||||
return
|
||||
|
||||
log(f"\n🎨 Generating {len(TEST_SAMPLES)} test samples (Stardew Valley style)...\n")
|
||||
|
||||
for i, (cat, name, prompt) in enumerate(TEST_SAMPLES, 1):
|
||||
path = OUTPUT_DIR / cat / f"{name}.png"
|
||||
|
||||
log(f"[{i}/{len(TEST_SAMPLES)}] 🎮 {cat}/{name}")
|
||||
|
||||
size = 768 if cat == "bosses" else 512
|
||||
wf = create_workflow(prompt, name, size)
|
||||
pid = queue_prompt(wf)
|
||||
|
||||
if pid and wait_completion(pid) and download_and_process(pid, path):
|
||||
log(f" ✅ Done!")
|
||||
os.system(f"open {path}")
|
||||
else:
|
||||
log(f" ❌ Failed")
|
||||
|
||||
time.sleep(1)
|
||||
|
||||
log("\n" + "="*70)
|
||||
log("🧪 TEST COMPLETE!")
|
||||
log(" Vse slike odprte za pregled")
|
||||
log("="*70)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user