import json import uuid from pathlib import Path import numpy as np from PIL import Image import folder_paths def comfy_batch_to_temp_images(image_batch, prefix="fl_vlm"): if image_batch is None: raise ValueError("FL VLM Image Inference requires an IMAGE input.") temp_dir = Path(folder_paths.temp_directory) / "fl_vlm" temp_dir.mkdir(parents=True, exist_ok=True) paths = [] for idx in range(int(image_batch.shape[0])): array = image_batch[idx].detach().cpu().numpy() array = np.clip(array * 255.0, 0, 255).astype(np.uint8) path = temp_dir / f"{prefix}_{idx}_{uuid.uuid4().hex}.png" Image.fromarray(array).save(path) paths.append(path) return paths def remove_temp_images(paths): for path in paths: try: Path(path).unlink(missing_ok=True) except Exception: pass def compact_json(data): return json.dumps(data, ensure_ascii=False, indent=2)