Update runpod.io.sh
Browse files- runpod.io.sh +633 -25
runpod.io.sh
CHANGED
|
@@ -11,18 +11,35 @@ APT_PACKAGES=(
|
|
| 11 |
)
|
| 12 |
|
| 13 |
PIP_PACKAGES=(
|
| 14 |
-
|
| 15 |
-
|
| 16 |
)
|
| 17 |
|
| 18 |
NODES=(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
"https://github.com/city96/ComfyUI-GGUF"
|
| 20 |
"https://github.com/kijai/ComfyUI-KJNodes"
|
| 21 |
"https://github.com/Suzie1/ComfyUI_Comfyroll_CustomNodes"
|
|
|
|
| 22 |
)
|
| 23 |
|
| 24 |
WORKFLOWS=(
|
| 25 |
-
|
|
|
|
|
|
|
| 26 |
)
|
| 27 |
|
| 28 |
SAMS=(
|
|
@@ -61,6 +78,7 @@ LORA_MODELS=(
|
|
| 61 |
"https://civitai.com/api/download/models/2617751?type=Model&format=SafeTensor&size=full&fp=fp16|ZIT-Realistic-Snapshot-v5.safetensors"
|
| 62 |
"https://civitai.com/api/download/models/2513043?type=Model&format=SafeTensor&size=full&fp=fp16|ZIT-Hip-Slider-v1.safetensors"
|
| 63 |
"https://civitai.com/api/download/models/2510875?type=Model&format=SafeTensor&size=full&fp=fp16|ZIT-Breast-Slider-v1.safetensors"
|
|
|
|
| 64 |
#"https://civitai.com/api/download/models/550216?type=Model&format=SafeTensor&size=full&fp=fp16|SDXL-Lady-Hands-v1.safetensors"
|
| 65 |
#"https://civitai.com/api/download/models/139194?type=Model&format=SafeTensor&size=full&fp=fp16|SDXL-Real-Feet-v1.safetensors"
|
| 66 |
"https://civitai.com/api/download/models/368603?type=Model&format=SafeTensor&size=full&fp=fp16|SDXL-Detailed-Nipples-v1.safetensors"
|
|
@@ -104,6 +122,7 @@ function provisioning_start() {
|
|
| 104 |
provisioning_get_apt_packages
|
| 105 |
provisioning_get_nodes
|
| 106 |
provisioning_get_pip_packages
|
|
|
|
| 107 |
provisioning_get_files \
|
| 108 |
"${COMFYUI_DIR}/models/sams" \
|
| 109 |
"${SAMS[@]}"
|
|
@@ -131,6 +150,9 @@ function provisioning_start() {
|
|
| 131 |
provisioning_get_files \
|
| 132 |
"${COMFYUI_DIR}/models/vae" \
|
| 133 |
"${VAE_MODELS[@]}"
|
|
|
|
|
|
|
|
|
|
| 134 |
provisioning_get_files \
|
| 135 |
"${COMFYUI_DIR}/models/esrgan" \
|
| 136 |
"${ESRGAN_MODELS[@]}"
|
|
@@ -172,6 +194,580 @@ function provisioning_get_nodes() {
|
|
| 172 |
done
|
| 173 |
}
|
| 174 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 175 |
function provisioning_get_files() {
|
| 176 |
if [[ -z $2 ]]; then return 1; fi
|
| 177 |
|
|
@@ -203,6 +799,36 @@ function provisioning_print_end() {
|
|
| 203 |
printf "\nProvisioning complete: Application will start now\n\n"
|
| 204 |
}
|
| 205 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 206 |
# Download CivitAI models with curl (pure bash)
|
| 207 |
function download_civitai_bash() {
|
| 208 |
local url="$1"
|
|
@@ -210,7 +836,6 @@ function download_civitai_bash() {
|
|
| 210 |
local forced_filename="$3"
|
| 211 |
local model_id=""
|
| 212 |
|
| 213 |
-
# Extract model ID from URL
|
| 214 |
if [[ $url =~ /models/([0-9]+) ]]; then
|
| 215 |
model_id="${BASH_REMATCH[1]}"
|
| 216 |
else
|
|
@@ -220,7 +845,6 @@ function download_civitai_bash() {
|
|
| 220 |
|
| 221 |
printf "Downloading CivitAI model %s...\n" "$model_id"
|
| 222 |
|
| 223 |
-
# If a forced filename was provided, use it directly
|
| 224 |
if [[ -n "$forced_filename" ]]; then
|
| 225 |
local output_file="${output_dir}/${forced_filename}"
|
| 226 |
if [[ -f "$output_file" ]]; then
|
|
@@ -228,8 +852,8 @@ function download_civitai_bash() {
|
|
| 228 |
return 0
|
| 229 |
fi
|
| 230 |
printf "Downloading to: %s\n" "$forced_filename"
|
| 231 |
-
if [[ -n "
|
| 232 |
-
curl -L -o "$output_file" --progress-bar -H "Authorization: Bearer
|
| 233 |
else
|
| 234 |
curl -L -o "$output_file" --progress-bar "$url"
|
| 235 |
fi
|
|
@@ -242,10 +866,9 @@ function download_civitai_bash() {
|
|
| 242 |
fi
|
| 243 |
fi
|
| 244 |
|
| 245 |
-
# Get redirect location with curl
|
| 246 |
local redirect_url=""
|
| 247 |
-
if [[ -n "
|
| 248 |
-
redirect_url=$(curl -s -I -L -H "Authorization: Bearer
|
| 249 |
else
|
| 250 |
redirect_url=$(curl -s -I -L "$url" | grep -i "^location:" | tail -1 | sed 's/location: //i' | tr -d '\r\n')
|
| 251 |
fi
|
|
@@ -255,49 +878,36 @@ function download_civitai_bash() {
|
|
| 255 |
return 1
|
| 256 |
fi
|
| 257 |
|
| 258 |
-
# Extract filename from redirect URL - improved method
|
| 259 |
local filename=""
|
| 260 |
|
| 261 |
-
# Method 1: Try to extract from response-content-disposition parameter (URL encoded)
|
| 262 |
if [[ $redirect_url =~ response-content-disposition=attachment.*filename%3D%22([^%\"]+) ]]; then
|
| 263 |
filename="${BASH_REMATCH[1]}"
|
| 264 |
-
# URL decode %20 to space, %2D to -, etc.
|
| 265 |
filename=$(echo "$filename" | sed 's/%20/ /g; s/%2D/-/g; s/%2E/./g; s/%5F/_/g')
|
| 266 |
-
# Method 2: Try filename=" pattern
|
| 267 |
elif [[ $redirect_url =~ filename=\"([^\"]+)\" ]]; then
|
| 268 |
filename="${BASH_REMATCH[1]}"
|
| 269 |
-
# Method 3: Try filename= without quotes
|
| 270 |
elif [[ $redirect_url =~ filename=([^&]+) ]]; then
|
| 271 |
filename="${BASH_REMATCH[1]}"
|
| 272 |
-
# Method 4: Extract from URL path before query string
|
| 273 |
else
|
| 274 |
-
# Remove query string and get the last part of the path
|
| 275 |
local path_part=$(echo "$redirect_url" | sed 's/?.*//')
|
| 276 |
filename=$(basename "$path_part")
|
| 277 |
-
|
| 278 |
-
# If filename doesn't have an extension, add .safetensors
|
| 279 |
if [[ ! "$filename" =~ \.(safetensors|pt|pth|ckpt|bin)$ ]]; then
|
| 280 |
filename="${filename}.safetensors"
|
| 281 |
fi
|
| 282 |
fi
|
| 283 |
|
| 284 |
-
# Clean up the filename - remove any remaining % encodings
|
| 285 |
filename=$(printf '%b' "${filename//%/\\x}")
|
| 286 |
|
| 287 |
-
# If still no valid filename, use fallback
|
| 288 |
if [[ -z "$filename" ]] || [[ "$filename" == "." ]] || [[ "$filename" == ".safetensors" ]]; then
|
| 289 |
filename="civitai_${model_id}.safetensors"
|
| 290 |
fi
|
| 291 |
|
| 292 |
local output_file="${output_dir}/${filename}"
|
| 293 |
|
| 294 |
-
# Check if file already exists
|
| 295 |
if [[ -f "$output_file" ]]; then
|
| 296 |
printf "File already exists: %s\n" "$filename"
|
| 297 |
return 0
|
| 298 |
fi
|
| 299 |
|
| 300 |
-
# Download with curl
|
| 301 |
printf "Downloading to: %s\n" "$filename"
|
| 302 |
curl -L -o "$output_file" --progress-bar "$redirect_url"
|
| 303 |
|
|
@@ -316,10 +926,8 @@ function provisioning_download() {
|
|
| 316 |
local dir="$2"
|
| 317 |
local forced_filename="$3"
|
| 318 |
|
| 319 |
-
# Check if it's a CivitAI URL
|
| 320 |
if [[ $url =~ ^https://civitai\.com/api/download/models/([0-9]+) ]]; then
|
| 321 |
download_civitai_bash "$url" "$dir" "$forced_filename"
|
| 322 |
-
# HuggingFace or other URLs
|
| 323 |
else
|
| 324 |
if [[ -n "$forced_filename" ]]; then
|
| 325 |
wget -qnc --show-progress -e dotbytes="${4:-4M}" -O "${dir}/${forced_filename}" "$url"
|
|
|
|
| 11 |
)
|
| 12 |
|
| 13 |
PIP_PACKAGES=(
|
| 14 |
+
"google-genai"
|
| 15 |
+
"xai-sdk"
|
| 16 |
)
|
| 17 |
|
| 18 |
NODES=(
|
| 19 |
+
"https://github.com/ltdrdata/ComfyUI-Manager"
|
| 20 |
+
"https://github.com/rgthree/rgthree-comfy"
|
| 21 |
+
"https://github.com/ltdrdata/ComfyUI-Impact-Pack"
|
| 22 |
+
"https://github.com/yolain/ComfyUI-Easy-Use"
|
| 23 |
+
"https://github.com/ssitu/ComfyUI_UltimateSDUpscale"
|
| 24 |
+
"https://github.com/sipherxyz/comfyui-art-venture"
|
| 25 |
+
"https://github.com/ltdrdata/ComfyUI-Impact-Subpack"
|
| 26 |
+
"https://github.com/moonwhaler/comfyui-moonpack"
|
| 27 |
+
"https://github.com/gseth/ControlAltAI-Nodes"
|
| 28 |
+
"https://github.com/vrgamegirl19/comfyui-vrgamedevgirl"
|
| 29 |
+
"https://github.com/numz/ComfyUI-SeedVR2_VideoUpscaler"
|
| 30 |
+
"https://github.com/robertvoy/ComfyUI-Flux-Continuum"
|
| 31 |
+
"https://github.com/ltdrdata/was-node-suite-comfyui"
|
| 32 |
+
"https://github.com/ChangeTheConstants/SeedVarianceEnhancer"
|
| 33 |
"https://github.com/city96/ComfyUI-GGUF"
|
| 34 |
"https://github.com/kijai/ComfyUI-KJNodes"
|
| 35 |
"https://github.com/Suzie1/ComfyUI_Comfyroll_CustomNodes"
|
| 36 |
+
"https://github.com/pythongosssss/ComfyUI-Custom-Scripts"
|
| 37 |
)
|
| 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 |
+
"https://huggingface.co/nathanglm/sofia/resolve/main/NANO%20BANANA%20v1.json"
|
| 43 |
)
|
| 44 |
|
| 45 |
SAMS=(
|
|
|
|
| 78 |
"https://civitai.com/api/download/models/2617751?type=Model&format=SafeTensor&size=full&fp=fp16|ZIT-Realistic-Snapshot-v5.safetensors"
|
| 79 |
"https://civitai.com/api/download/models/2513043?type=Model&format=SafeTensor&size=full&fp=fp16|ZIT-Hip-Slider-v1.safetensors"
|
| 80 |
"https://civitai.com/api/download/models/2510875?type=Model&format=SafeTensor&size=full&fp=fp16|ZIT-Breast-Slider-v1.safetensors"
|
| 81 |
+
"https://civitai.com/api/download/models/2088956?type=Model&format=SafeTensor&size=full&fp=fp16|ZIT-Famegird-2nd-Gen-Spicy.safetensors"
|
| 82 |
#"https://civitai.com/api/download/models/550216?type=Model&format=SafeTensor&size=full&fp=fp16|SDXL-Lady-Hands-v1.safetensors"
|
| 83 |
#"https://civitai.com/api/download/models/139194?type=Model&format=SafeTensor&size=full&fp=fp16|SDXL-Real-Feet-v1.safetensors"
|
| 84 |
"https://civitai.com/api/download/models/368603?type=Model&format=SafeTensor&size=full&fp=fp16|SDXL-Detailed-Nipples-v1.safetensors"
|
|
|
|
| 122 |
provisioning_get_apt_packages
|
| 123 |
provisioning_get_nodes
|
| 124 |
provisioning_get_pip_packages
|
| 125 |
+
provisioning_create_nanobananapro
|
| 126 |
provisioning_get_files \
|
| 127 |
"${COMFYUI_DIR}/models/sams" \
|
| 128 |
"${SAMS[@]}"
|
|
|
|
| 150 |
provisioning_get_files \
|
| 151 |
"${COMFYUI_DIR}/models/vae" \
|
| 152 |
"${VAE_MODELS[@]}"
|
| 153 |
+
provisioning_get_files \
|
| 154 |
+
"${COMFYUI_DIR}/user/default/workflows" \
|
| 155 |
+
"${WORKFLOWS[@]}"
|
| 156 |
provisioning_get_files \
|
| 157 |
"${COMFYUI_DIR}/models/esrgan" \
|
| 158 |
"${ESRGAN_MODELS[@]}"
|
|
|
|
| 194 |
done
|
| 195 |
}
|
| 196 |
|
| 197 |
+
function provisioning_create_nanobananapro() {
|
| 198 |
+
local NBP_DIR="${COMFYUI_DIR}/custom_nodes/NanoBananaPro"
|
| 199 |
+
printf "Creating NanoBananaPro custom nodes...\n"
|
| 200 |
+
mkdir -p "${NBP_DIR}"
|
| 201 |
+
|
| 202 |
+
# ββ nano_banana_pro_node.py ββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 203 |
+
cat > "${NBP_DIR}/nano_banana_pro_node.py" << 'ENDOFFILE'
|
| 204 |
+
"""
|
| 205 |
+
π Nano Banana Pro Node β ComfyUI
|
| 206 |
+
Supporte :
|
| 207 |
+
- Nano Banana 2 = gemini-3.1-flash-image-preview (NOUVEAU, recommandΓ©)
|
| 208 |
+
- Nano Banana Pro = gemini-3-pro-image-preview (β οΈ dΓ©prΓ©ciΓ© le 9 mars 2026)
|
| 209 |
+
- Nano Banana = gemini-2.5-flash-image (stable, rapide)
|
| 210 |
+
Modes :
|
| 211 |
+
- generate : text-to-image pur
|
| 212 |
+
- edit : image editing (envoyer une image + prompt)
|
| 213 |
+
RΓ©solutions : 0.5K, 1K, 2K, 4K
|
| 214 |
+
"""
|
| 215 |
+
|
| 216 |
+
import torch, numpy as np, io, random
|
| 217 |
+
from PIL import Image, ImageEnhance
|
| 218 |
+
|
| 219 |
+
def pil_to_tensor(image):
|
| 220 |
+
img = image.convert("RGB")
|
| 221 |
+
arr = np.array(img).astype(np.float32) / 255.0
|
| 222 |
+
return torch.from_numpy(arr).unsqueeze(0)
|
| 223 |
+
|
| 224 |
+
def tensor_to_pil(tensor):
|
| 225 |
+
arr = tensor.squeeze(0).numpy()
|
| 226 |
+
arr = (arr * 255).clip(0, 255).astype(np.uint8)
|
| 227 |
+
return Image.fromarray(arr)
|
| 228 |
+
|
| 229 |
+
def pil_to_bytes(image):
|
| 230 |
+
buf = io.BytesIO()
|
| 231 |
+
image.save(buf, format="PNG")
|
| 232 |
+
return buf.getvalue()
|
| 233 |
+
|
| 234 |
+
def apply_color_grade(image, brightness, contrast, saturation, temperature, sharpness):
|
| 235 |
+
img = image.convert("RGB")
|
| 236 |
+
if brightness != 1.0:
|
| 237 |
+
img = ImageEnhance.Brightness(img).enhance(brightness)
|
| 238 |
+
if contrast != 1.0:
|
| 239 |
+
img = ImageEnhance.Contrast(img).enhance(contrast)
|
| 240 |
+
if saturation != 1.0:
|
| 241 |
+
img = ImageEnhance.Color(img).enhance(saturation)
|
| 242 |
+
if temperature != 0.0:
|
| 243 |
+
r, g, b = img.split()
|
| 244 |
+
r_arr = np.array(r, dtype=np.float32)
|
| 245 |
+
b_arr = np.array(b, dtype=np.float32)
|
| 246 |
+
strength = abs(temperature) * 30
|
| 247 |
+
if temperature > 0:
|
| 248 |
+
r_arr = np.clip(r_arr + strength, 0, 255)
|
| 249 |
+
b_arr = np.clip(b_arr - strength * 0.5, 0, 255)
|
| 250 |
+
else:
|
| 251 |
+
r_arr = np.clip(r_arr - strength * 0.5, 0, 255)
|
| 252 |
+
b_arr = np.clip(b_arr + strength, 0, 255)
|
| 253 |
+
img = Image.merge("RGB", (
|
| 254 |
+
Image.fromarray(r_arr.astype(np.uint8)),
|
| 255 |
+
g,
|
| 256 |
+
Image.fromarray(b_arr.astype(np.uint8))
|
| 257 |
+
))
|
| 258 |
+
if sharpness != 1.0:
|
| 259 |
+
img = ImageEnhance.Sharpness(img).enhance(sharpness)
|
| 260 |
+
return img
|
| 261 |
+
|
| 262 |
+
|
| 263 |
+
class NanaBananaProNode:
|
| 264 |
+
MODELS = [
|
| 265 |
+
"gemini-3.1-flash-image-preview",
|
| 266 |
+
"gemini-2.5-flash-image",
|
| 267 |
+
"gemini-3-pro-image-preview",
|
| 268 |
+
]
|
| 269 |
+
MODES = ["generate", "edit"]
|
| 270 |
+
SAFETY = ["OFF", "BLOCK_ONLY_HIGH", "BLOCK_MEDIUM_AND_ABOVE", "BLOCK_LOW_AND_ABOVE"]
|
| 271 |
+
RATIOS = ["1:1", "9:16", "16:9", "2:3", "3:2", "4:3", "3:4", "21:9", "1:4", "4:1"]
|
| 272 |
+
QUALITY = ["1K", "2K", "4K", "0.5K"]
|
| 273 |
+
AFTER_GEN = ["randomize", "fixed", "increment"]
|
| 274 |
+
|
| 275 |
+
@classmethod
|
| 276 |
+
def INPUT_TYPES(cls):
|
| 277 |
+
return {
|
| 278 |
+
"required": {
|
| 279 |
+
"prompt": ("STRING", {"default": "A stunning photorealistic portrait, ultra detailed", "multiline": True}),
|
| 280 |
+
"model": (cls.MODELS,),
|
| 281 |
+
"mode": (cls.MODES,),
|
| 282 |
+
"aspect_ratio": (cls.RATIOS,),
|
| 283 |
+
"quality": (cls.QUALITY,),
|
| 284 |
+
"temperature": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 2.0, "step": 0.05}),
|
| 285 |
+
"top_p": ("FLOAT", {"default": 0.95, "min": 0.0, "max": 1.0, "step": 0.01}),
|
| 286 |
+
"top_k": ("INT", {"default": 0, "min": 0, "max": 100, "step": 1}),
|
| 287 |
+
"seed": ("INT", {"default": -1, "min": -1, "max": 2**31,"step": 1}),
|
| 288 |
+
"control_after_generate": (cls.AFTER_GEN,),
|
| 289 |
+
"safety_threshold": (cls.SAFETY,),
|
| 290 |
+
"api_key": ("STRING", {"default": "YOUR_GEMINI_API_KEY"}),
|
| 291 |
+
"cg_brightness": ("FLOAT", {"default": 1.0, "min": 0.1, "max": 3.0, "step": 0.05}),
|
| 292 |
+
"cg_contrast": ("FLOAT", {"default": 1.0, "min": 0.1, "max": 3.0, "step": 0.05}),
|
| 293 |
+
"cg_saturation": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 3.0, "step": 0.05}),
|
| 294 |
+
"cg_temperature": ("FLOAT", {"default": 0.0, "min": -1.0,"max": 1.0, "step": 0.05}),
|
| 295 |
+
"cg_sharpness": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 3.0, "step": 0.05}),
|
| 296 |
+
},
|
| 297 |
+
"optional": {
|
| 298 |
+
"edit_image": ("IMAGE",),
|
| 299 |
+
"ref_image_1": ("IMAGE",),
|
| 300 |
+
"ref_image_2": ("IMAGE",),
|
| 301 |
+
"ref_image_3": ("IMAGE",),
|
| 302 |
+
"ref_image_4": ("IMAGE",),
|
| 303 |
+
"ref_image_5": ("IMAGE",),
|
| 304 |
+
"ref_image_6": ("IMAGE",),
|
| 305 |
+
"ref_image_7": ("IMAGE",),
|
| 306 |
+
}
|
| 307 |
+
}
|
| 308 |
+
|
| 309 |
+
RETURN_TYPES = ("IMAGE", "STRING")
|
| 310 |
+
RETURN_NAMES = ("image", "metadata")
|
| 311 |
+
FUNCTION = "generate"
|
| 312 |
+
CATEGORY = "π Nano Banana Pro"
|
| 313 |
+
|
| 314 |
+
def generate(self, prompt, model, mode, aspect_ratio, quality, temperature, top_p, top_k,
|
| 315 |
+
seed, control_after_generate, safety_threshold, api_key,
|
| 316 |
+
cg_brightness, cg_contrast, cg_saturation, cg_temperature, cg_sharpness,
|
| 317 |
+
edit_image=None, ref_image_1=None, ref_image_2=None, ref_image_3=None,
|
| 318 |
+
ref_image_4=None, ref_image_5=None, ref_image_6=None, ref_image_7=None):
|
| 319 |
+
try:
|
| 320 |
+
from google import genai
|
| 321 |
+
from google.genai import types
|
| 322 |
+
except ImportError:
|
| 323 |
+
raise ImportError("Lance : pip install google-genai")
|
| 324 |
+
|
| 325 |
+
if seed == -1 or control_after_generate == "randomize":
|
| 326 |
+
actual_seed = random.randint(0, 2**31)
|
| 327 |
+
elif control_after_generate == "increment":
|
| 328 |
+
actual_seed = seed + 1
|
| 329 |
+
else:
|
| 330 |
+
actual_seed = seed
|
| 331 |
+
|
| 332 |
+
client = genai.Client(api_key=api_key)
|
| 333 |
+
|
| 334 |
+
safety_settings = []
|
| 335 |
+
if safety_threshold != "OFF":
|
| 336 |
+
harm_categories = [
|
| 337 |
+
"HARM_CATEGORY_HARASSMENT",
|
| 338 |
+
"HARM_CATEGORY_HATE_SPEECH",
|
| 339 |
+
"HARM_CATEGORY_SEXUALLY_EXPLICIT",
|
| 340 |
+
"HARM_CATEGORY_DANGEROUS_CONTENT"
|
| 341 |
+
]
|
| 342 |
+
safety_settings = [types.SafetySetting(category=cat, threshold=safety_threshold) for cat in harm_categories]
|
| 343 |
+
|
| 344 |
+
parts = []
|
| 345 |
+
|
| 346 |
+
if mode == "edit" and edit_image is not None:
|
| 347 |
+
parts.append(types.Part.from_bytes(
|
| 348 |
+
data=pil_to_bytes(tensor_to_pil(edit_image)),
|
| 349 |
+
mime_type="image/png"
|
| 350 |
+
))
|
| 351 |
+
|
| 352 |
+
ref_images = [ref_image_1, ref_image_2, ref_image_3, ref_image_4,
|
| 353 |
+
ref_image_5, ref_image_6, ref_image_7]
|
| 354 |
+
for ref in ref_images:
|
| 355 |
+
if ref is not None:
|
| 356 |
+
parts.append(types.Part.from_bytes(
|
| 357 |
+
data=pil_to_bytes(tensor_to_pil(ref)),
|
| 358 |
+
mime_type="image/png"
|
| 359 |
+
))
|
| 360 |
+
|
| 361 |
+
parts.append(types.Part.from_text(text=prompt))
|
| 362 |
+
|
| 363 |
+
gen_config_kwargs = dict(
|
| 364 |
+
response_modalities=["TEXT", "IMAGE"],
|
| 365 |
+
temperature=temperature,
|
| 366 |
+
top_p=top_p,
|
| 367 |
+
image_config=types.ImageConfig(
|
| 368 |
+
aspect_ratio=aspect_ratio,
|
| 369 |
+
image_size=quality
|
| 370 |
+
),
|
| 371 |
+
)
|
| 372 |
+
if top_k > 0:
|
| 373 |
+
gen_config_kwargs["top_k"] = top_k
|
| 374 |
+
if safety_settings:
|
| 375 |
+
gen_config_kwargs["safety_settings"] = safety_settings
|
| 376 |
+
|
| 377 |
+
gen_config = types.GenerateContentConfig(**gen_config_kwargs)
|
| 378 |
+
|
| 379 |
+
print(f"[NanaBanana] -> {model} | mode:{mode} | quality:{quality} | safety:{safety_threshold}")
|
| 380 |
+
|
| 381 |
+
response = client.models.generate_content(
|
| 382 |
+
model=model,
|
| 383 |
+
contents=parts,
|
| 384 |
+
config=gen_config
|
| 385 |
+
)
|
| 386 |
+
|
| 387 |
+
if not response.candidates:
|
| 388 |
+
raise RuntimeError(f"[NanaBanana] Aucun candidat: {response}")
|
| 389 |
+
|
| 390 |
+
candidate = response.candidates[0]
|
| 391 |
+
finish_reason = str(getattr(candidate, "finish_reason", ""))
|
| 392 |
+
if "SAFETY" in finish_reason:
|
| 393 |
+
raise RuntimeError("[NanaBanana] Bloque par IMAGE_SAFETY. Reformule le prompt.")
|
| 394 |
+
|
| 395 |
+
content = getattr(candidate, "content", None)
|
| 396 |
+
if content is None or not getattr(content, "parts", None):
|
| 397 |
+
raise RuntimeError(f"[NanaBanana] Content vide. finish_reason: {finish_reason}")
|
| 398 |
+
|
| 399 |
+
result_image, info_text = None, ""
|
| 400 |
+
for part in content.parts:
|
| 401 |
+
if hasattr(part, "text") and part.text:
|
| 402 |
+
info_text += part.text + "\n"
|
| 403 |
+
elif hasattr(part, "inline_data") and part.inline_data:
|
| 404 |
+
result_image = Image.open(io.BytesIO(part.inline_data.data)).convert("RGB")
|
| 405 |
+
|
| 406 |
+
if result_image is None:
|
| 407 |
+
raise RuntimeError(f"[NanaBanana] Aucune image generee. Texte: {info_text or '(aucun)'}")
|
| 408 |
+
|
| 409 |
+
result_image = apply_color_grade(
|
| 410 |
+
result_image,
|
| 411 |
+
cg_brightness, cg_contrast, cg_saturation, cg_temperature, cg_sharpness
|
| 412 |
+
)
|
| 413 |
+
|
| 414 |
+
metadata = (
|
| 415 |
+
f"model: {model}\n"
|
| 416 |
+
f"mode: {mode}\n"
|
| 417 |
+
f"seed: {actual_seed}\n"
|
| 418 |
+
f"temperature: {temperature} | top_p: {top_p} | top_k: {top_k}\n"
|
| 419 |
+
f"aspect_ratio: {aspect_ratio} | quality: {quality}\n"
|
| 420 |
+
f"safety: {safety_threshold}\n"
|
| 421 |
+
f"{info_text.strip()}"
|
| 422 |
+
)
|
| 423 |
+
print(f"[NanaBanana] Succes ! ({quality})")
|
| 424 |
+
return (pil_to_tensor(result_image), metadata)
|
| 425 |
+
|
| 426 |
+
|
| 427 |
+
NODE_CLASS_MAPPINGS = {"NanaBananaProNode": NanaBananaProNode}
|
| 428 |
+
NODE_DISPLAY_NAME_MAPPINGS = {"NanaBananaProNode": "π Nano Banana Pro"}
|
| 429 |
+
ENDOFFILE
|
| 430 |
+
|
| 431 |
+
# ββ anya_prompt_extractor_node.py ββββββββββββββββββββββββββββββββββββββββββ
|
| 432 |
+
cat > "${NBP_DIR}/anya_prompt_extractor_node.py" << 'ENDOFFILE'
|
| 433 |
+
import torch, numpy as np, io, json
|
| 434 |
+
from PIL import Image
|
| 435 |
+
|
| 436 |
+
def tensor_to_pil(tensor):
|
| 437 |
+
arr = tensor.squeeze(0).numpy()
|
| 438 |
+
arr = (arr * 255).clip(0, 255).astype(np.uint8)
|
| 439 |
+
return Image.fromarray(arr)
|
| 440 |
+
|
| 441 |
+
def pil_to_bytes(image):
|
| 442 |
+
buf = io.BytesIO()
|
| 443 |
+
image.save(buf, format="PNG")
|
| 444 |
+
return buf.getvalue()
|
| 445 |
+
|
| 446 |
+
def build_system_prompt(anya_desc, include_anya, include_l3n0v0, breast_size, style_hint, use_ref_images, num_refs, ref_descs_list):
|
| 447 |
+
breast_map = {"small": "small perky breasts", "medium": "medium-sized natural breasts, visible cleavage", "large": "large full breasts with natural weight", "huge": "very large breasts, voluptuous silhouette"}
|
| 448 |
+
breast_desc = breast_map.get(breast_size, "medium-sized natural breasts")
|
| 449 |
+
triggers = []
|
| 450 |
+
if include_anya: triggers.append("Anya")
|
| 451 |
+
if include_l3n0v0: triggers.append("l3n0v0")
|
| 452 |
+
triggers_str = json.dumps(triggers)
|
| 453 |
+
if include_anya:
|
| 454 |
+
subject_block = f' "subject": {{"name": "Anya", "ethnicity": "Asian", "hair": "...", "skin_tone": "...", "breast_size": "{breast_desc}", "body": "wide hips, prominent round BBL-style butt, thick thighs, hourglass figure", "face": "full lips, almond-shaped eyes, long lashes, natural makeup", "jewelry": "...", "pose": "...", "expression": "...", "gaze": "..."}}'
|
| 455 |
+
subject_instruction = f"## ANYA FIXED CHARACTER\n{anya_desc}\nBreast size: {breast_desc}\nHips: wide hips, prominent round BBL-style butt, thick thighs\nInject into subject section, never modify physical traits."
|
| 456 |
+
else:
|
| 457 |
+
subject_block = ' "subject": {"description": "...", "pose": "...", "expression": "...", "gaze": "..."}'
|
| 458 |
+
subject_instruction = "## SUBJECT\nDescribe the subject from the reference image exactly. Reproduce face, hair, skin tone, body proportions 1:1. No changes, no beautification."
|
| 459 |
+
if use_ref_images and num_refs > 0:
|
| 460 |
+
ref_labels = ["subject_identity"] + [f"reference_image_{i}" for i in range(2, num_refs+1)]
|
| 461 |
+
ref_entries = []
|
| 462 |
+
for i in range(num_refs):
|
| 463 |
+
label = ref_labels[i] if i < len(ref_labels) else f"reference_image_{i+1}"
|
| 464 |
+
desc = ref_descs_list[i] if i < len(ref_descs_list) and ref_descs_list[i].strip() else f"uploaded_reference_image_{i+1}"
|
| 465 |
+
ref_entries.append(f' "{label}": "{desc}"')
|
| 466 |
+
ref_block = ' "reference_images": {\n' + ',\n'.join(ref_entries) + '\n },'
|
| 467 |
+
ref_instruction = f"## REFERENCE IMAGES\n{num_refs} reference image(s):\n" + "\n".join([f"- Image {i+1}: {ref_descs_list[i] if i < len(ref_descs_list) else 'reference'}" for i in range(num_refs)])
|
| 468 |
+
else:
|
| 469 |
+
ref_block = ""
|
| 470 |
+
ref_instruction = "## REFERENCE IMAGES\nNo reference images."
|
| 471 |
+
ref_section = f"\n{ref_block}" if ref_block else ""
|
| 472 |
+
inject_note = "Inject the fixed Anya character description into subject." if include_anya else "Describe subject exactly as seen in the reference image, 1:1 accuracy."
|
| 473 |
+
return f"""You are an expert AI image prompt engineer specializing in structured JSON prompts.
|
| 474 |
+
{subject_instruction}
|
| 475 |
+
{ref_instruction}
|
| 476 |
+
## OUTPUT RULES
|
| 477 |
+
- Return ONLY valid JSON, no markdown, no backticks, no explanation
|
| 478 |
+
- trigger_words must be exactly: {triggers_str}
|
| 479 |
+
{{
|
| 480 |
+
"trigger_words": {triggers_str},{ref_section}
|
| 481 |
+
"output_quality": {{"resolution": "4K", "definition": "ultra high resolution", "sharpness": "natural realistic detail, not overprocessed"}},
|
| 482 |
+
{subject_block},
|
| 483 |
+
"outfit": {{"description": "...", "colors": [...], "fit": "...", "fabric": "..."}},
|
| 484 |
+
"location": {{"setting": "...", "environment": [...], "time_of_day": "...", "lighting": "...", "atmosphere": "..."}},
|
| 485 |
+
"image_type": {{"orientation": "...", "aspect_ratio": "...", "style": "{style_hint}", "camera_feel": "...", "color_grading": "..."}},
|
| 486 |
+
"identity_preservation": {{"facial_identity": "...", "no_changes": ["bone_structure", "facial_proportions", "skin_tone", "hairline", "facial_features"], "no_beautification": true, "no_stylization": true}},
|
| 487 |
+
"realism_constraints": {{"no_extra_limbs": true, "no_ai_symmetry_correction": true, "natural_skin_texture": true, "natural_light_behavior": true, "no_heavy_color_grading": true}},
|
| 488 |
+
"image_feel": [...]
|
| 489 |
+
}}
|
| 490 |
+
Analyze the provided image(s): extract scene, lighting, pose, outfit, mood. {inject_note} Return ONLY the JSON."""
|
| 491 |
+
|
| 492 |
+
class AnyaPromptExtractor:
|
| 493 |
+
MODELS = ["gemini-2.5-flash-preview-05-20", "gemini-2.5-flash", "gemini-2.5-pro", "gemini-3-pro-image-preview"]
|
| 494 |
+
BREAST_SIZES = ["small", "medium", "large", "huge"]
|
| 495 |
+
NUM_REFS = ["0", "1", "2", "3", "4", "5"]
|
| 496 |
+
|
| 497 |
+
@classmethod
|
| 498 |
+
def INPUT_TYPES(cls):
|
| 499 |
+
return {
|
| 500 |
+
"required": {
|
| 501 |
+
"api_key": ("STRING", {"default": "YOUR_GEMINI_API_KEY"}),
|
| 502 |
+
"model": (cls.MODELS,),
|
| 503 |
+
"include_trigger_anya": ("BOOLEAN", {"default": True}),
|
| 504 |
+
"include_trigger_l3n0v0": ("BOOLEAN", {"default": True}),
|
| 505 |
+
"breast_size_override": (cls.BREAST_SIZES,),
|
| 506 |
+
"anya_base_description": ("STRING", {"default": "Anya is an Asian woman with long straight black hair, medium-sized natural breasts, wide hips and a prominent BBL-style butt, thick thighs. She has full lips, almond-shaped eyes with long lashes, tan warm skin tone, and usually wears gold jewelry.", "multiline": True}),
|
| 507 |
+
"style_hint": ("STRING", {"default": "natural high-end lifestyle, candid editorial"}),
|
| 508 |
+
"json_indent": ("INT", {"default": 4, "min": 0, "max": 8, "step": 1}),
|
| 509 |
+
"use_reference_images": ("BOOLEAN", {"default": True}),
|
| 510 |
+
"num_reference_images": (cls.NUM_REFS,),
|
| 511 |
+
"ref_1_description": ("STRING", {"default": "subject identity β main model reference"}),
|
| 512 |
+
"ref_2_description": ("STRING", {"default": "outfit reference"}),
|
| 513 |
+
"ref_3_description": ("STRING", {"default": "location or background reference"}),
|
| 514 |
+
"ref_4_description": ("STRING", {"default": "style or mood reference"}),
|
| 515 |
+
"ref_5_description": ("STRING", {"default": "additional reference"}),
|
| 516 |
+
},
|
| 517 |
+
"optional": {
|
| 518 |
+
"scene_image": ("IMAGE",),
|
| 519 |
+
"ref_image_1": ("IMAGE",),
|
| 520 |
+
"ref_image_2": ("IMAGE",),
|
| 521 |
+
"ref_image_3": ("IMAGE",),
|
| 522 |
+
"ref_image_4": ("IMAGE",),
|
| 523 |
+
"ref_image_5": ("IMAGE",),
|
| 524 |
+
}
|
| 525 |
+
}
|
| 526 |
+
|
| 527 |
+
RETURN_TYPES = ("STRING", "IMAGE", "IMAGE", "IMAGE", "IMAGE", "IMAGE", "IMAGE")
|
| 528 |
+
RETURN_NAMES = ("prompt_json", "scene_passthrough", "ref_1_passthrough", "ref_2_passthrough", "ref_3_passthrough", "ref_4_passthrough", "ref_5_passthrough")
|
| 529 |
+
FUNCTION = "extract"
|
| 530 |
+
CATEGORY = "π Nano Banana Pro"
|
| 531 |
+
OUTPUT_NODE = True
|
| 532 |
+
|
| 533 |
+
def extract(self, api_key, model, include_trigger_anya, include_trigger_l3n0v0,
|
| 534 |
+
breast_size_override, anya_base_description, style_hint, json_indent,
|
| 535 |
+
use_reference_images, num_reference_images,
|
| 536 |
+
ref_1_description, ref_2_description, ref_3_description,
|
| 537 |
+
ref_4_description, ref_5_description,
|
| 538 |
+
scene_image=None, ref_image_1=None, ref_image_2=None,
|
| 539 |
+
ref_image_3=None, ref_image_4=None, ref_image_5=None):
|
| 540 |
+
try:
|
| 541 |
+
from google import genai
|
| 542 |
+
from google.genai import types
|
| 543 |
+
except ImportError:
|
| 544 |
+
raise ImportError("Lance : pip install google-genai")
|
| 545 |
+
num_refs = int(num_reference_images)
|
| 546 |
+
ref_descs_list = [ref_1_description, ref_2_description, ref_3_description, ref_4_description, ref_5_description]
|
| 547 |
+
system_prompt = build_system_prompt(anya_base_description, include_trigger_anya, include_trigger_l3n0v0, breast_size_override, style_hint, use_reference_images, num_refs, ref_descs_list)
|
| 548 |
+
client = genai.Client(api_key=api_key)
|
| 549 |
+
parts = []
|
| 550 |
+
if scene_image is not None:
|
| 551 |
+
parts.append(types.Part.from_bytes(data=pil_to_bytes(tensor_to_pil(scene_image)), mime_type="image/png"))
|
| 552 |
+
if use_reference_images and num_refs > 0:
|
| 553 |
+
ref_images_list = [ref_image_1, ref_image_2, ref_image_3, ref_image_4, ref_image_5]
|
| 554 |
+
for i in range(min(num_refs, 5)):
|
| 555 |
+
ref = ref_images_list[i]
|
| 556 |
+
if ref is not None:
|
| 557 |
+
desc = ref_descs_list[i] if ref_descs_list[i].strip() else f"reference image {i+1}"
|
| 558 |
+
parts.append(types.Part.from_text(text=f"[Reference image {i+1}: {desc}]"))
|
| 559 |
+
parts.append(types.Part.from_bytes(data=pil_to_bytes(tensor_to_pil(ref)), mime_type="image/png"))
|
| 560 |
+
if not parts:
|
| 561 |
+
parts.append(types.Part.from_text(text="No image provided. Generate a generic lifestyle JSON prompt. Return ONLY the JSON."))
|
| 562 |
+
else:
|
| 563 |
+
parts.append(types.Part.from_text(text="Analyze the provided image(s) and generate the structured JSON prompt. Return ONLY the JSON."))
|
| 564 |
+
config = types.GenerateContentConfig(system_instruction=system_prompt, response_modalities=["TEXT"], temperature=0.4, top_p=0.9)
|
| 565 |
+
print(f"[AnyaExtractor] -> {model} | Anya:{include_trigger_anya} | l3n0v0:{include_trigger_l3n0v0} | refs:{num_refs if use_reference_images else 0}")
|
| 566 |
+
response = client.models.generate_content(model=model, contents=parts, config=config)
|
| 567 |
+
raw_parts = response.parts or []
|
| 568 |
+
raw_text = "".join(part.text for part in raw_parts if hasattr(part, "text") and part.text).strip()
|
| 569 |
+
if not raw_text and hasattr(response, "candidates") and response.candidates:
|
| 570 |
+
raw_text = "".join(part.text for part in (response.candidates[0].content.parts or []) if hasattr(part, "text") and part.text).strip()
|
| 571 |
+
if not raw_text:
|
| 572 |
+
raise RuntimeError(f"[AnyaExtractor] Reponse vide. Modele: {model} | Verifier la cle API ou changer de modele.")
|
| 573 |
+
if raw_text.startswith("```"):
|
| 574 |
+
lines = raw_text.split("\n")
|
| 575 |
+
raw_text = "\n".join(lines[1:-1] if lines[-1].strip() == "```" else lines[1:]).strip()
|
| 576 |
+
try:
|
| 577 |
+
parsed = json.loads(raw_text)
|
| 578 |
+
tw = parsed.get("trigger_words", [])
|
| 579 |
+
if include_trigger_anya and "Anya" not in tw: tw.insert(0, "Anya")
|
| 580 |
+
if not include_trigger_anya and "Anya" in tw: tw.remove("Anya")
|
| 581 |
+
if include_trigger_l3n0v0 and "l3n0v0" not in tw: tw.append("l3n0v0")
|
| 582 |
+
if not include_trigger_l3n0v0 and "l3n0v0" in tw: tw.remove("l3n0v0")
|
| 583 |
+
parsed["trigger_words"] = tw
|
| 584 |
+
output_json = json.dumps(parsed, indent=json_indent, ensure_ascii=False)
|
| 585 |
+
except json.JSONDecodeError as e:
|
| 586 |
+
print(f"[AnyaExtractor] JSON invalide: {e}")
|
| 587 |
+
output_json = raw_text
|
| 588 |
+
print(f"[AnyaExtractor] Succes ({len(output_json)} chars)")
|
| 589 |
+
empty = torch.zeros(1, 64, 64, 3)
|
| 590 |
+
return (output_json, scene_image if scene_image is not None else empty, ref_image_1 if ref_image_1 is not None else empty, ref_image_2 if ref_image_2 is not None else empty, ref_image_3 if ref_image_3 is not None else empty, ref_image_4 if ref_image_4 is not None else empty, ref_image_5 if ref_image_5 is not None else empty)
|
| 591 |
+
|
| 592 |
+
NODE_CLASS_MAPPINGS = {"AnyaPromptExtractor": AnyaPromptExtractor}
|
| 593 |
+
NODE_DISPLAY_NAME_MAPPINGS = {"AnyaPromptExtractor": "π Anya Prompt Extractor"}
|
| 594 |
+
ENDOFFILE
|
| 595 |
+
|
| 596 |
+
# ββ grok_prompt_extractor_node.py ββββββββββββββββββββββββββββββββββββββββββ
|
| 597 |
+
cat > "${NBP_DIR}/grok_prompt_extractor_node.py" << 'ENDOFFILE'
|
| 598 |
+
import torch, numpy as np, io, base64
|
| 599 |
+
from PIL import Image
|
| 600 |
+
|
| 601 |
+
def tensor_to_pil(tensor):
|
| 602 |
+
arr = tensor.squeeze(0).numpy()
|
| 603 |
+
arr = (arr * 255).clip(0, 255).astype(np.uint8)
|
| 604 |
+
return Image.fromarray(arr)
|
| 605 |
+
|
| 606 |
+
def pil_to_bytes(image):
|
| 607 |
+
buf = io.BytesIO()
|
| 608 |
+
image.save(buf, format="PNG")
|
| 609 |
+
return buf.getvalue()
|
| 610 |
+
|
| 611 |
+
def image_to_base64(image):
|
| 612 |
+
return base64.b64encode(pil_to_bytes(image)).decode("utf-8")
|
| 613 |
+
|
| 614 |
+
def build_system_prompt(anya_desc, include_anya, include_l3n0v0, breast_size, style_hint, word_count):
|
| 615 |
+
breast_map = {
|
| 616 |
+
"small": "small perky breasts",
|
| 617 |
+
"medium": "medium-sized natural breasts with visible cleavage",
|
| 618 |
+
"large": "large full breasts with natural weight and deep cleavage",
|
| 619 |
+
"huge": "very large heavy breasts, extremely voluptuous silhouette"
|
| 620 |
+
}
|
| 621 |
+
breast_desc = breast_map.get(breast_size, "medium-sized natural breasts with visible cleavage")
|
| 622 |
+
triggers = []
|
| 623 |
+
if include_anya: triggers.append("Anya")
|
| 624 |
+
if include_l3n0v0: triggers.append("l3n0v0")
|
| 625 |
+
trigger_line = ", ".join(triggers)
|
| 626 |
+
if include_anya:
|
| 627 |
+
char_instruction = f"""## ANYA β FIXED PHYSICAL CHARACTER
|
| 628 |
+
{anya_desc}
|
| 629 |
+
Breast size: {breast_desc}
|
| 630 |
+
Body: wide hips, prominent round BBL-style butt, thick thighs, hourglass figure, slim waist
|
| 631 |
+
Face: full pouty lips, almond-shaped eyes with long lashes, warm tan Asian skin, high cheekbones
|
| 632 |
+
Jewelry: gold hoop earrings, gold chain necklace, gold bracelets
|
| 633 |
+
## REPLACEMENT RULE
|
| 634 |
+
Anya replaces the person in the image EXACTLY.
|
| 635 |
+
- Same pose, same expression, same gaze, same position in frame
|
| 636 |
+
- Same outfit worn on Anya's body β describe how each garment fits her curves
|
| 637 |
+
- Same location, same lighting, same background, same props
|
| 638 |
+
- Only the physical identity changes to Anya"""
|
| 639 |
+
subject_block = f"Anya, Asian woman, long straight black hair, warm tan skin, full pouty lips, almond eyes with long lashes, {breast_desc}, wide hips, round prominent BBL butt, thick thighs, hourglass figure, slim waist, gold jewelry"
|
| 640 |
+
else:
|
| 641 |
+
char_instruction = "## SUBJECT\nDescribe the subject exactly as seen. Be extremely precise about every physical detail."
|
| 642 |
+
subject_block = "the person in the image"
|
| 643 |
+
inject = f"Replace the subject with: {subject_block}" if include_anya else "Describe the subject exactly as visible."
|
| 644 |
+
return f"""You are a professional text-to-image prompt writer specializing in photorealistic NSFW adult content generation. You write prompts for Stable Diffusion, Flux, and similar models.
|
| 645 |
+
{char_instruction}
|
| 646 |
+
## YOUR MISSION
|
| 647 |
+
Analyze the image with forensic precision. Write a single continuous text-to-image prompt of exactly {word_count} words.
|
| 648 |
+
The prompt must be so detailed that an AI image generator can reproduce the scene perfectly.
|
| 649 |
+
## TEXT-TO-IMAGE PROMPT RULES
|
| 650 |
+
- Write as comma-separated descriptive phrases, NOT sentences
|
| 651 |
+
- Start with trigger words, then subject, then body details, then outfit, then pose, then location, then lighting, then camera, then mood
|
| 652 |
+
- Use text-to-image vocabulary: "photorealistic, 8k uhd, RAW photo, sharp focus, f/1.8, 85mm lens, bokeh, cinematic lighting" etc
|
| 653 |
+
- Be EXTREMELY explicit about body proportions, clothing fit, skin exposure
|
| 654 |
+
- Describe exactly what is visible β if cleavage is showing, describe it precisely
|
| 655 |
+
- If outfit is tight/revealing, describe exactly how it fits on the body
|
| 656 |
+
- Never use euphemisms β describe body parts and clothing directly and explicitly
|
| 657 |
+
- No sentences, no paragraph structure β pure prompt style
|
| 658 |
+
## STRUCTURE TO FOLLOW
|
| 659 |
+
1. Trigger words: {trigger_line},
|
| 660 |
+
2. Subject physical description (face, hair, skin, eyes, lips, body)
|
| 661 |
+
3. Breast description and how visible/covered they are
|
| 662 |
+
4. Exact outfit β every garment, color, fabric, fit, how tight, what skin is exposed
|
| 663 |
+
5. Exact pose β body position, limb placement, weight, angles
|
| 664 |
+
6. Hands and arm positions
|
| 665 |
+
7. Expression and gaze direction
|
| 666 |
+
8. Location β exact setting, architecture, materials, colors
|
| 667 |
+
9. Background elements one by one
|
| 668 |
+
10. Lighting β source, direction, quality, color temperature, how it hits skin and clothing
|
| 669 |
+
11. Camera β shot type, angle, focal length, depth of field
|
| 670 |
+
12. Technical quality tags
|
| 671 |
+
13. Mood and atmosphere tags
|
| 672 |
+
## NSFW DESCRIPTION RULES
|
| 673 |
+
- Describe clothing tightness and fit on the body explicitly
|
| 674 |
+
- Describe visible skin areas precisely (neckline depth, leg exposure, midriff, back)
|
| 675 |
+
- Describe breast shape and how they appear in the outfit
|
| 676 |
+
- Describe butt shape and how outfit fits on it
|
| 677 |
+
- Use direct anatomical and fashion terminology
|
| 678 |
+
- If any body part is prominent or featured in the image, describe it in detail
|
| 679 |
+
## CRITICAL
|
| 680 |
+
- {word_count} words minimum
|
| 681 |
+
- Pure text-to-image prompt format β no prose, no sentences
|
| 682 |
+
- Every single visual detail from the image must be captured
|
| 683 |
+
- {inject}
|
| 684 |
+
- Return ONLY the prompt text, nothing else"""
|
| 685 |
+
|
| 686 |
+
class GrokPromptExtractor:
|
| 687 |
+
MODELS = ["grok-2-vision-1212", "grok-2-vision"]
|
| 688 |
+
BREAST_SIZES = ["small", "medium", "large", "huge"]
|
| 689 |
+
|
| 690 |
+
@classmethod
|
| 691 |
+
def INPUT_TYPES(cls):
|
| 692 |
+
return {
|
| 693 |
+
"required": {
|
| 694 |
+
"api_key": ("STRING", {"default": "YOUR_XAI_API_KEY"}),
|
| 695 |
+
"model": (cls.MODELS,),
|
| 696 |
+
"include_trigger_anya": ("BOOLEAN", {"default": True}),
|
| 697 |
+
"include_trigger_l3n0v0": ("BOOLEAN", {"default": True}),
|
| 698 |
+
"breast_size_override": (cls.BREAST_SIZES,),
|
| 699 |
+
"anya_base_description": ("STRING", {"default": "Anya is an Asian woman with long straight black hair, medium-sized natural breasts, wide hips and a prominent BBL-style butt, thick thighs. She has full lips, almond-shaped eyes with long lashes, tan warm skin tone, and usually wears gold jewelry.", "multiline": True}),
|
| 700 |
+
"style_hint": ("STRING", {"default": "RAW photo, photorealistic, candid shot, natural lighting, 8k uhd"}),
|
| 701 |
+
"word_count": ("INT", {"default": 450, "min": 200, "max": 800, "step": 50}),
|
| 702 |
+
},
|
| 703 |
+
"optional": {
|
| 704 |
+
"image": ("IMAGE",),
|
| 705 |
+
}
|
| 706 |
+
}
|
| 707 |
+
|
| 708 |
+
RETURN_TYPES = ("STRING", "IMAGE")
|
| 709 |
+
RETURN_NAMES = ("prompt_text", "image_passthrough")
|
| 710 |
+
FUNCTION = "extract"
|
| 711 |
+
CATEGORY = "π€ Grok xAI"
|
| 712 |
+
OUTPUT_NODE = True
|
| 713 |
+
|
| 714 |
+
def extract(self, api_key, model, include_trigger_anya, include_trigger_l3n0v0,
|
| 715 |
+
breast_size_override, anya_base_description, style_hint, word_count,
|
| 716 |
+
image=None):
|
| 717 |
+
try:
|
| 718 |
+
from xai_sdk import Client
|
| 719 |
+
from xai_sdk.chat import system, user, image as xai_image
|
| 720 |
+
except ImportError:
|
| 721 |
+
raise ImportError("Lance : pip install xai-sdk")
|
| 722 |
+
system_prompt = build_system_prompt(anya_base_description, include_trigger_anya, include_trigger_l3n0v0, breast_size_override, style_hint, word_count)
|
| 723 |
+
client = Client(api_key=api_key)
|
| 724 |
+
chat = client.chat.create(model=model)
|
| 725 |
+
chat.append(system(system_prompt))
|
| 726 |
+
if image is not None:
|
| 727 |
+
b64 = image_to_base64(tensor_to_pil(image))
|
| 728 |
+
data_url = f"data:image/png;base64,{b64}"
|
| 729 |
+
chat.append(user(
|
| 730 |
+
f"Analyze every detail of this image. Write a {word_count}-word text-to-image prompt. "
|
| 731 |
+
f"Be extremely explicit about body proportions, outfit fit, skin exposure, clothing tightness. "
|
| 732 |
+
f"Pure prompt format β comma-separated tags and descriptors, no sentences, no explanations. "
|
| 733 |
+
f"Return ONLY the prompt.",
|
| 734 |
+
xai_image(data_url)
|
| 735 |
+
))
|
| 736 |
+
else:
|
| 737 |
+
chat.append(user(f"Write a {word_count}-word text-to-image prompt for Anya in a high-end Miami lifestyle scene. Pure prompt format, comma-separated, extremely detailed. Return ONLY the prompt."))
|
| 738 |
+
print(f"[GrokExtractor] -> {model} | Anya:{include_trigger_anya} | l3n0v0:{include_trigger_l3n0v0} | words:{word_count}")
|
| 739 |
+
response = chat.sample()
|
| 740 |
+
output_text = response.content.strip()
|
| 741 |
+
print(f"[GrokExtractor] OK ({len(output_text.split())} words)")
|
| 742 |
+
empty = torch.zeros(1, 64, 64, 3)
|
| 743 |
+
return (output_text, image if image is not None else empty)
|
| 744 |
+
|
| 745 |
+
NODE_CLASS_MAPPINGS = {"GrokPromptExtractor": GrokPromptExtractor}
|
| 746 |
+
NODE_DISPLAY_NAME_MAPPINGS = {"GrokPromptExtractor": "π€ Grok Prompt Extractor"}
|
| 747 |
+
ENDOFFILE
|
| 748 |
+
|
| 749 |
+
# ββ __init__.py ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 750 |
+
cat > "${NBP_DIR}/__init__.py" << 'EOF'
|
| 751 |
+
from .nano_banana_pro_node import NODE_CLASS_MAPPINGS as _NM1, NODE_DISPLAY_NAME_MAPPINGS as _DN1
|
| 752 |
+
from .anya_prompt_extractor_node import NODE_CLASS_MAPPINGS as _NM2, NODE_DISPLAY_NAME_MAPPINGS as _DN2
|
| 753 |
+
from .grok_prompt_extractor_node import NODE_CLASS_MAPPINGS as _NM3, NODE_DISPLAY_NAME_MAPPINGS as _DN3
|
| 754 |
+
|
| 755 |
+
NODE_CLASS_MAPPINGS = {}
|
| 756 |
+
NODE_CLASS_MAPPINGS.update(_NM1)
|
| 757 |
+
NODE_CLASS_MAPPINGS.update(_NM2)
|
| 758 |
+
NODE_CLASS_MAPPINGS.update(_NM3)
|
| 759 |
+
|
| 760 |
+
NODE_DISPLAY_NAME_MAPPINGS = {}
|
| 761 |
+
NODE_DISPLAY_NAME_MAPPINGS.update(_DN1)
|
| 762 |
+
NODE_DISPLAY_NAME_MAPPINGS.update(_DN2)
|
| 763 |
+
NODE_DISPLAY_NAME_MAPPINGS.update(_DN3)
|
| 764 |
+
|
| 765 |
+
__all__ = ["NODE_CLASS_MAPPINGS", "NODE_DISPLAY_NAME_MAPPINGS"]
|
| 766 |
+
EOF
|
| 767 |
+
|
| 768 |
+
printf "NanoBananaPro nodes created successfully.\n"
|
| 769 |
+
}
|
| 770 |
+
|
| 771 |
function provisioning_get_files() {
|
| 772 |
if [[ -z $2 ]]; then return 1; fi
|
| 773 |
|
|
|
|
| 799 |
printf "\nProvisioning complete: Application will start now\n\n"
|
| 800 |
}
|
| 801 |
|
| 802 |
+
function provisioning_has_valid_hf_token() {
|
| 803 |
+
[[ -n "$HF_TOKEN" ]] || return 1
|
| 804 |
+
url="https://huggingface.co/api/whoami-v2"
|
| 805 |
+
|
| 806 |
+
response=$(curl -o /dev/null -s -w "%{http_code}" -X GET "$url" \
|
| 807 |
+
-H "Authorization: Bearer $HF_TOKEN" \
|
| 808 |
+
-H "Content-Type: application/json")
|
| 809 |
+
|
| 810 |
+
if [ "$response" -eq 200 ]; then
|
| 811 |
+
return 0
|
| 812 |
+
else
|
| 813 |
+
return 1
|
| 814 |
+
fi
|
| 815 |
+
}
|
| 816 |
+
|
| 817 |
+
function provisioning_has_valid_civitai_token() {
|
| 818 |
+
[[ -n "$CIVITAI_TOKEN" ]] || return 1
|
| 819 |
+
url="https://civitai.com/api/v1/models?hidden=1&limit=1"
|
| 820 |
+
|
| 821 |
+
response=$(curl -o /dev/null -s -w "%{http_code}" -X GET "$url" \
|
| 822 |
+
-H "Authorization: Bearer $CIVITAI_TOKEN" \
|
| 823 |
+
-H "Content-Type: application/json")
|
| 824 |
+
|
| 825 |
+
if [ "$response" -eq 200 ]; then
|
| 826 |
+
return 0
|
| 827 |
+
else
|
| 828 |
+
return 1
|
| 829 |
+
fi
|
| 830 |
+
}
|
| 831 |
+
|
| 832 |
# Download CivitAI models with curl (pure bash)
|
| 833 |
function download_civitai_bash() {
|
| 834 |
local url="$1"
|
|
|
|
| 836 |
local forced_filename="$3"
|
| 837 |
local model_id=""
|
| 838 |
|
|
|
|
| 839 |
if [[ $url =~ /models/([0-9]+) ]]; then
|
| 840 |
model_id="${BASH_REMATCH[1]}"
|
| 841 |
else
|
|
|
|
| 845 |
|
| 846 |
printf "Downloading CivitAI model %s...\n" "$model_id"
|
| 847 |
|
|
|
|
| 848 |
if [[ -n "$forced_filename" ]]; then
|
| 849 |
local output_file="${output_dir}/${forced_filename}"
|
| 850 |
if [[ -f "$output_file" ]]; then
|
|
|
|
| 852 |
return 0
|
| 853 |
fi
|
| 854 |
printf "Downloading to: %s\n" "$forced_filename"
|
| 855 |
+
if [[ -n "$CIVITAI_TOKEN" ]]; then
|
| 856 |
+
curl -L -o "$output_file" --progress-bar -H "Authorization: Bearer $CIVITAI_TOKEN" "$url"
|
| 857 |
else
|
| 858 |
curl -L -o "$output_file" --progress-bar "$url"
|
| 859 |
fi
|
|
|
|
| 866 |
fi
|
| 867 |
fi
|
| 868 |
|
|
|
|
| 869 |
local redirect_url=""
|
| 870 |
+
if [[ -n "$CIVITAI_TOKEN" ]]; then
|
| 871 |
+
redirect_url=$(curl -s -I -L -H "Authorization: Bearer $CIVITAI_TOKEN" "$url" | grep -i "^location:" | tail -1 | sed 's/location: //i' | tr -d '\r\n')
|
| 872 |
else
|
| 873 |
redirect_url=$(curl -s -I -L "$url" | grep -i "^location:" | tail -1 | sed 's/location: //i' | tr -d '\r\n')
|
| 874 |
fi
|
|
|
|
| 878 |
return 1
|
| 879 |
fi
|
| 880 |
|
|
|
|
| 881 |
local filename=""
|
| 882 |
|
|
|
|
| 883 |
if [[ $redirect_url =~ response-content-disposition=attachment.*filename%3D%22([^%\"]+) ]]; then
|
| 884 |
filename="${BASH_REMATCH[1]}"
|
|
|
|
| 885 |
filename=$(echo "$filename" | sed 's/%20/ /g; s/%2D/-/g; s/%2E/./g; s/%5F/_/g')
|
|
|
|
| 886 |
elif [[ $redirect_url =~ filename=\"([^\"]+)\" ]]; then
|
| 887 |
filename="${BASH_REMATCH[1]}"
|
|
|
|
| 888 |
elif [[ $redirect_url =~ filename=([^&]+) ]]; then
|
| 889 |
filename="${BASH_REMATCH[1]}"
|
|
|
|
| 890 |
else
|
|
|
|
| 891 |
local path_part=$(echo "$redirect_url" | sed 's/?.*//')
|
| 892 |
filename=$(basename "$path_part")
|
|
|
|
|
|
|
| 893 |
if [[ ! "$filename" =~ \.(safetensors|pt|pth|ckpt|bin)$ ]]; then
|
| 894 |
filename="${filename}.safetensors"
|
| 895 |
fi
|
| 896 |
fi
|
| 897 |
|
|
|
|
| 898 |
filename=$(printf '%b' "${filename//%/\\x}")
|
| 899 |
|
|
|
|
| 900 |
if [[ -z "$filename" ]] || [[ "$filename" == "." ]] || [[ "$filename" == ".safetensors" ]]; then
|
| 901 |
filename="civitai_${model_id}.safetensors"
|
| 902 |
fi
|
| 903 |
|
| 904 |
local output_file="${output_dir}/${filename}"
|
| 905 |
|
|
|
|
| 906 |
if [[ -f "$output_file" ]]; then
|
| 907 |
printf "File already exists: %s\n" "$filename"
|
| 908 |
return 0
|
| 909 |
fi
|
| 910 |
|
|
|
|
| 911 |
printf "Downloading to: %s\n" "$filename"
|
| 912 |
curl -L -o "$output_file" --progress-bar "$redirect_url"
|
| 913 |
|
|
|
|
| 926 |
local dir="$2"
|
| 927 |
local forced_filename="$3"
|
| 928 |
|
|
|
|
| 929 |
if [[ $url =~ ^https://civitai\.com/api/download/models/([0-9]+) ]]; then
|
| 930 |
download_civitai_bash "$url" "$dir" "$forced_filename"
|
|
|
|
| 931 |
else
|
| 932 |
if [[ -n "$forced_filename" ]]; then
|
| 933 |
wget -qnc --show-progress -e dotbytes="${4:-4M}" -O "${dir}/${forced_filename}" "$url"
|