Update installer.sh
Browse files- installer.sh +155 -0
installer.sh
CHANGED
|
@@ -38,6 +38,7 @@ NODES=(
|
|
| 38 |
|
| 39 |
WORKFLOWS=(
|
| 40 |
"https://huggingface.co/nathanglm/sofia/resolve/main/ZIT%20v6.json"
|
|
|
|
| 41 |
)
|
| 42 |
|
| 43 |
SAMS=(
|
|
@@ -196,6 +197,160 @@ function provisioning_create_nanobananapro() {
|
|
| 196 |
printf "Creating NanoBananaPro custom nodes...\n"
|
| 197 |
mkdir -p "${NBP_DIR}"
|
| 198 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 199 |
# ββ anya_prompt_extractor_node.py ββββββββββββββββββββββββββββββββββββββββββ
|
| 200 |
cat > "${NBP_DIR}/anya_prompt_extractor_node.py" << 'ENDOFFILE'
|
| 201 |
import torch, numpy as np, io, json
|
|
|
|
| 38 |
|
| 39 |
WORKFLOWS=(
|
| 40 |
"https://huggingface.co/nathanglm/sofia/resolve/main/ZIT%20v6.json"
|
| 41 |
+
"https://huggingface.co/nathanglm/sofia/resolve/main/EXTRACTOR%20v1.json"
|
| 42 |
)
|
| 43 |
|
| 44 |
SAMS=(
|
|
|
|
| 197 |
printf "Creating NanoBananaPro custom nodes...\n"
|
| 198 |
mkdir -p "${NBP_DIR}"
|
| 199 |
|
| 200 |
+
# ββ nano_banana_pro_node.py ββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 201 |
+
cat > "${NBP_DIR}/nano_banana_pro_node.py" << 'ENDOFFILE'
|
| 202 |
+
import torch, numpy as np, io, random
|
| 203 |
+
from PIL import Image, ImageEnhance
|
| 204 |
+
|
| 205 |
+
def pil_to_tensor(image):
|
| 206 |
+
img = image.convert("RGB")
|
| 207 |
+
arr = np.array(img).astype(np.float32) / 255.0
|
| 208 |
+
return torch.from_numpy(arr).unsqueeze(0)
|
| 209 |
+
|
| 210 |
+
def tensor_to_pil(tensor):
|
| 211 |
+
arr = tensor.squeeze(0).numpy()
|
| 212 |
+
arr = (arr * 255).clip(0, 255).astype(np.uint8)
|
| 213 |
+
return Image.fromarray(arr)
|
| 214 |
+
|
| 215 |
+
def pil_to_bytes(image):
|
| 216 |
+
buf = io.BytesIO()
|
| 217 |
+
image.save(buf, format="PNG")
|
| 218 |
+
return buf.getvalue()
|
| 219 |
+
|
| 220 |
+
def apply_color_grade(image, brightness, contrast, saturation, temperature, sharpness):
|
| 221 |
+
img = image.convert("RGB")
|
| 222 |
+
if brightness != 1.0:
|
| 223 |
+
img = ImageEnhance.Brightness(img).enhance(brightness)
|
| 224 |
+
if contrast != 1.0:
|
| 225 |
+
img = ImageEnhance.Contrast(img).enhance(contrast)
|
| 226 |
+
if saturation != 1.0:
|
| 227 |
+
img = ImageEnhance.Color(img).enhance(saturation)
|
| 228 |
+
if temperature != 0.0:
|
| 229 |
+
r, g, b = img.split()
|
| 230 |
+
r_arr = np.array(r, dtype=np.float32)
|
| 231 |
+
b_arr = np.array(b, dtype=np.float32)
|
| 232 |
+
strength = abs(temperature) * 30
|
| 233 |
+
if temperature > 0:
|
| 234 |
+
r_arr = np.clip(r_arr + strength, 0, 255)
|
| 235 |
+
b_arr = np.clip(b_arr - strength * 0.5, 0, 255)
|
| 236 |
+
else:
|
| 237 |
+
r_arr = np.clip(r_arr - strength * 0.5, 0, 255)
|
| 238 |
+
b_arr = np.clip(b_arr + strength, 0, 255)
|
| 239 |
+
img = Image.merge("RGB", (Image.fromarray(r_arr.astype(np.uint8)), g, Image.fromarray(b_arr.astype(np.uint8))))
|
| 240 |
+
if sharpness != 1.0:
|
| 241 |
+
img = ImageEnhance.Sharpness(img).enhance(sharpness)
|
| 242 |
+
return img
|
| 243 |
+
|
| 244 |
+
class NanaBananaProNode:
|
| 245 |
+
MODELS = ["gemini-3-pro-image-preview", "gemini-2.5-flash-image"]
|
| 246 |
+
SAFETY = ["OFF", "BLOCK_ONLY_HIGH", "BLOCK_MEDIUM_AND_ABOVE", "BLOCK_LOW_AND_ABOVE"]
|
| 247 |
+
RATIOS = ["1:1", "2:3", "3:2", "16:9", "9:16", "4:3", "3:4", "21:9"]
|
| 248 |
+
QUALITY = ["1K", "2K", "4K"]
|
| 249 |
+
MEDIA_RES = ["HIGH", "MEDIUM", "LOW"]
|
| 250 |
+
AFTER_GEN = ["randomize", "fixed", "increment"]
|
| 251 |
+
|
| 252 |
+
@classmethod
|
| 253 |
+
def INPUT_TYPES(cls):
|
| 254 |
+
return {
|
| 255 |
+
"required": {
|
| 256 |
+
"prompt": ("STRING", {"default": "A stunning landscape, ultra detailed", "multiline": True}),
|
| 257 |
+
"model": (cls.MODELS,),
|
| 258 |
+
"aspect_ratio": (cls.RATIOS,),
|
| 259 |
+
"quality": (cls.QUALITY,),
|
| 260 |
+
"temperature": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 2.0, "step": 0.05}),
|
| 261 |
+
"top_p": ("FLOAT", {"default": 0.95, "min": 0.0, "max": 1.0, "step": 0.01}),
|
| 262 |
+
"top_k": ("INT", {"default": 0, "min": 0, "max": 100, "step": 1}),
|
| 263 |
+
"seed": ("INT", {"default": -1, "min": -1, "max": 2**31,"step": 1}),
|
| 264 |
+
"control_after_generate": (cls.AFTER_GEN,),
|
| 265 |
+
"safety_threshold": (cls.SAFETY,),
|
| 266 |
+
"use_images": ("BOOLEAN", {"default": False}),
|
| 267 |
+
"media_resolution": (cls.MEDIA_RES,),
|
| 268 |
+
"api_key": ("STRING", {"default": "YOUR_GEMINI_API_KEY"}),
|
| 269 |
+
"cg_brightness": ("FLOAT", {"default": 1.0, "min": 0.1, "max": 3.0, "step": 0.05}),
|
| 270 |
+
"cg_contrast": ("FLOAT", {"default": 1.0, "min": 0.1, "max": 3.0, "step": 0.05}),
|
| 271 |
+
"cg_saturation": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 3.0, "step": 0.05}),
|
| 272 |
+
"cg_temperature": ("FLOAT", {"default": 0.0, "min": -1.0,"max": 1.0, "step": 0.05}),
|
| 273 |
+
"cg_sharpness": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 3.0, "step": 0.05}),
|
| 274 |
+
},
|
| 275 |
+
"optional": {
|
| 276 |
+
"batch_images": ("IMAGE",),
|
| 277 |
+
"image_1": ("IMAGE",),
|
| 278 |
+
"image_2": ("IMAGE",),
|
| 279 |
+
"image_3": ("IMAGE",),
|
| 280 |
+
"image_4": ("IMAGE",),
|
| 281 |
+
"image_5": ("IMAGE",),
|
| 282 |
+
}
|
| 283 |
+
}
|
| 284 |
+
|
| 285 |
+
RETURN_TYPES = ("IMAGE", "STRING")
|
| 286 |
+
RETURN_NAMES = ("image", "metadata")
|
| 287 |
+
FUNCTION = "generate"
|
| 288 |
+
CATEGORY = "π Nano Banana Pro"
|
| 289 |
+
|
| 290 |
+
def generate(self, prompt, model, aspect_ratio, quality, temperature, top_p, top_k,
|
| 291 |
+
seed, control_after_generate, safety_threshold, use_images,
|
| 292 |
+
media_resolution, api_key,
|
| 293 |
+
cg_brightness, cg_contrast, cg_saturation, cg_temperature, cg_sharpness,
|
| 294 |
+
batch_images=None, image_1=None, image_2=None, image_3=None,
|
| 295 |
+
image_4=None, image_5=None):
|
| 296 |
+
try:
|
| 297 |
+
from google import genai
|
| 298 |
+
from google.genai import types
|
| 299 |
+
except ImportError:
|
| 300 |
+
raise ImportError("Lance : pip install google-genai")
|
| 301 |
+
if seed == -1 or control_after_generate == "randomize":
|
| 302 |
+
actual_seed = random.randint(0, 2**31)
|
| 303 |
+
elif control_after_generate == "increment":
|
| 304 |
+
actual_seed = seed + 1
|
| 305 |
+
else:
|
| 306 |
+
actual_seed = seed
|
| 307 |
+
client = genai.Client(api_key=api_key)
|
| 308 |
+
safety_settings = []
|
| 309 |
+
if safety_threshold != "OFF":
|
| 310 |
+
harm_categories = ["HARM_CATEGORY_HARASSMENT","HARM_CATEGORY_HATE_SPEECH","HARM_CATEGORY_SEXUALLY_EXPLICIT","HARM_CATEGORY_DANGEROUS_CONTENT"]
|
| 311 |
+
safety_settings = [types.SafetySetting(category=cat, threshold=safety_threshold) for cat in harm_categories]
|
| 312 |
+
parts = []
|
| 313 |
+
if use_images:
|
| 314 |
+
for ref in [batch_images, image_1, image_2, image_3, image_4, image_5]:
|
| 315 |
+
if ref is not None:
|
| 316 |
+
if ref.shape[0] > 1:
|
| 317 |
+
for i in range(ref.shape[0]):
|
| 318 |
+
parts.append(types.Part.from_bytes(data=pil_to_bytes(tensor_to_pil(ref[i].unsqueeze(0))), mime_type="image/png"))
|
| 319 |
+
else:
|
| 320 |
+
parts.append(types.Part.from_bytes(data=pil_to_bytes(tensor_to_pil(ref)), mime_type="image/png"))
|
| 321 |
+
parts.append(types.Part.from_text(text=prompt))
|
| 322 |
+
gen_config_kwargs = dict(response_modalities=["TEXT", "IMAGE"], temperature=temperature, top_p=top_p, image_config=types.ImageConfig(aspect_ratio=aspect_ratio, image_size=quality))
|
| 323 |
+
if top_k > 0: gen_config_kwargs["top_k"] = top_k
|
| 324 |
+
if safety_settings: gen_config_kwargs["safety_settings"] = safety_settings
|
| 325 |
+
gen_config = types.GenerateContentConfig(**gen_config_kwargs)
|
| 326 |
+
print(f"[NanaBanana] -> {model} | safety: {safety_threshold}")
|
| 327 |
+
response = client.models.generate_content(model=model, contents=parts, config=gen_config)
|
| 328 |
+
if not response.candidates:
|
| 329 |
+
raise RuntimeError(f"[NanaBanana] Aucun candidat: {response}")
|
| 330 |
+
candidate = response.candidates[0]
|
| 331 |
+
finish_reason = str(getattr(candidate, "finish_reason", ""))
|
| 332 |
+
if "SAFETY" in finish_reason:
|
| 333 |
+
raise RuntimeError("[NanaBanana] Bloque par IMAGE_SAFETY. Reformule le prompt.")
|
| 334 |
+
content = getattr(candidate, "content", None)
|
| 335 |
+
if content is None or not getattr(content, "parts", None):
|
| 336 |
+
raise RuntimeError(f"[NanaBanana] Content vide. finish_reason: {finish_reason}")
|
| 337 |
+
result_image, info_text = None, ""
|
| 338 |
+
for part in content.parts:
|
| 339 |
+
if hasattr(part, "text") and part.text:
|
| 340 |
+
info_text += part.text + "\n"
|
| 341 |
+
elif hasattr(part, "inline_data") and part.inline_data:
|
| 342 |
+
result_image = Image.open(io.BytesIO(part.inline_data.data)).convert("RGB")
|
| 343 |
+
if result_image is None:
|
| 344 |
+
raise RuntimeError(f"[NanaBanana] Aucune image. Texte: {info_text or '(aucun)'}")
|
| 345 |
+
result_image = apply_color_grade(result_image, cg_brightness, cg_contrast, cg_saturation, cg_temperature, cg_sharpness)
|
| 346 |
+
metadata = f"model: {model}\nseed: {actual_seed}\ntemperature: {temperature} | top_p: {top_p} | top_k: {top_k}\naspect_ratio: {aspect_ratio} | quality: {quality}\nsafety: {safety_threshold}\n{info_text.strip()}"
|
| 347 |
+
print("[NanaBanana] Succes !")
|
| 348 |
+
return (pil_to_tensor(result_image), metadata)
|
| 349 |
+
|
| 350 |
+
NODE_CLASS_MAPPINGS = {"NanaBananaProNode": NanaBananaProNode}
|
| 351 |
+
NODE_DISPLAY_NAME_MAPPINGS = {"NanaBananaProNode": "π Nano Banana Pro"}
|
| 352 |
+
ENDOFFILE
|
| 353 |
+
|
| 354 |
# ββ anya_prompt_extractor_node.py ββββββββββββββββββββββββββββββββββββββββββ
|
| 355 |
cat > "${NBP_DIR}/anya_prompt_extractor_node.py" << 'ENDOFFILE'
|
| 356 |
import torch, numpy as np, io, json
|