set cut_paste_input [stack 0] version 13.1 v2 push $cut_paste_input Group { name Stability tile_color 0xf794ff00 selected true xpos 109 ypos 128 addUserKnob {20 img l "Still Image"} addUserKnob {26 ""} addUserKnob {26 sda l " " T "

Stable Diffusion for Nuke

"} addUserKnob {26 ""} addUserKnob {20 "" n -2} addUserKnob {20 text-to-image l "Text to image"} addUserKnob {26 ""} addUserKnob {4 ti_engine_name l Engine M {stable-diffusion-v1 stable-diffusion-v1-5 stable-diffusion-512-v2-0 stable-diffusion-768-v2-0 stable-diffusion-512-v2-1 stable-diffusion-768-v2-1 stable-diffusion-xl-beta-v2-2-2}} ti_engine_name stable-diffusion-xl-beta-v2-2-2 addUserKnob {26 ""} addUserKnob {43 ti_prompt l Prompt} ti_prompt "a unicorn in socotra island, pink and white elegant" addUserKnob {7 ti_weight l "Prompt Weight"} ti_weight 0.5 addUserKnob {26 ""} addUserKnob {7 ti_cfg_scale l "Cfg Scale" R 1 10} ti_cfg_scale 7 addUserKnob {4 ti_style_preset l "Style Preset" M {"" 3d-model analog-film anime cinematic comic-book digital-art enhance fantasy-art isometric line-art low-poly modeling-compound neon-punk origami photographic pixel-art tile-texture}} addUserKnob {4 ti_clip_guidance_preset l "Clip Guidance Preset" M {NONE FAST_BLUE FAST_GREEN SIMPLE SLOW SLOWER SLOWEST}} addUserKnob {4 ti_sampler l Sampler M {DDIM DDPM K_DPMPP_2M K_DPMPP_2S_ANCESTRAL K_EULER K_EULER_ANCESTRAL K_HEUN K_LMS}} addUserKnob {3 ti_samples l Samples R 1 10} ti_samples 1 addUserKnob {3 ti_seed l Seed R 1 4.29497e+09} addUserKnob {3 ti_steps l Steps R 10 150} ti_steps 30 addUserKnob {26 ""} addUserKnob {22 t2i_dream l Dream T "\nimport base64\nimport os\nimport requests\n\nengine_id = \"stable-diffusion-v1-5\"\napi_host = os.getenv('API_HOST', 'https://api.stability.ai')\napi_key = os.getenv(\"STABILITY_API_KEY\")\n\n# Get the directory of the current Nuke script\nscript_dir = os.path.dirname(nuke.root().name())\n\n# Set the subdirectory where the image files will be stored\nsub_dir = \"Stability\"\n\n# Set the directories where the image files and temp files will be stored\nimage_dir = os.path.join(script_dir, sub_dir, \"Images\")\ntemp_dir = os.path.join(script_dir, sub_dir, \"temp\")\n\n# Create the directories if they don't exist\nos.makedirs(image_dir, exist_ok=True)\nos.makedirs(temp_dir, exist_ok=True)\n\n# Get the list of existing image files in the directory\nexisting_files = os.listdir(image_dir)\n\nengine_txt_img=nuke.thisNode().knob('ti_engine_name').value()\nprompt_txt_img=nuke.thisNode().knob('ti_prompt').value()\ncfg_scale_txt_img=int(nuke.thisNode().knob('ti_cfg_scale').getValue())\nclip_guidance_preset_txt_img=nuke.thisNode().knob('ti_clip_guidance_preset').value()\nstyle_preset_txt_img=nuke.thisNode().knob('ti_style_preset').value()\nsamples_txt_img=int(nuke.thisNode().knob('ti_samples').getValue())\nsteps_txt_img=int(nuke.thisNode().knob('ti_steps').getValue())\nweight_txt_img=nuke.thisNode().knob('ti_weight').getValue()\napi_key = nuke.thisNode().knob('api-key').value()\n\njson_data = \{\n \"text_prompts\": \[\n \{\n \"text\": prompt_txt_img,\n \}\n ],\n \"weight\": weight_txt_img,\n \"cfg_scale\": cfg_scale_txt_img,\n \"clip_guidance_preset\": clip_guidance_preset_txt_img,\n \"height\": 512,\n \"width\": 512,\n \"samples\": samples_txt_img,\n \"steps\": steps_txt_img,\n\}\n\nif style_preset_txt_img:\n json_data\[\"style_preset\"] = style_preset_txt_img\n\nresponse = requests.post(\n f\"\{api_host\}/v1/generation/\{engine_txt_img\}/text-to-image\",\n headers=\{\n \"Content-Type\": 'application/json',\n \"Accept\": 'application/json',\n \"Authorization\": f'Bearer \{api_key\}'\n \},\n json = json_data\n)\n\nif response.status_code != 200:\n raise Exception(\"Non-200 response: \" + str(response.text))\n\ndata = response.json()\n\nfor i, image in enumerate(data\[\"artifacts\"]):\n # Construct the initial filename\n file_name = f\"Text_To_Image_\{i\}.png\"\n input_path = os.path.join(image_dir, file_name)\n \n # Check if the filename already exists\n version = 1\n while os.path.exists(input_path):\n # If the file already exists, version up the filename\n version += 1\n file_name = f\"Text_To_Image_\{i\}_v\{version\}.png\"\n input_path = os.path.join(image_dir, file_name)\n \n # Write the image data to the new file\n with open(input_path, \"wb\") as f:\n f.write(base64.b64decode(image\[\"base64\"]))\n \n # Create a Read node for the new file\n with nuke.root():\n read_node = nuke.createNode(\"Read\", inpanel=False)\n read_node\['file'].fromUserText(input_path)" +STARTLINE} addUserKnob {20 image-to-image l "Image to image"} addUserKnob {26 ""} addUserKnob {4 ii_engine_name l Model -STARTLINE M {stable-diffusion-v1 stable-diffusion-v1-5 stable-diffusion-512-v2-0 stable-diffusion-768-v2-0 stable-diffusion-512-v2-1 stable-diffusion-768-v2-1 stable-diffusion-xl-beta-v2-2-2}} ii_engine_name stable-diffusion-xl-beta-v2-2-2 addUserKnob {26 ""} addUserKnob {43 ii_prompt1 l Prompt} ii_prompt1 "Dark nightmare unicorn, dreamy and ethereal, expressive pose, big pink eyes, exciting expression, fantasy, intricate, elegant" addUserKnob {7 ii_weight1 l "Prompt Weight" R -1 1} ii_weight1 0.5 addUserKnob {26 ""} addUserKnob {43 ii_prompt2 l "Second Prompt"} ii_prompt2 "pink, unicorn, rainbow" addUserKnob {7 ii_weight2 l "Second Prompt Weight" R -1 1} ii_weight2 -0.9 addUserKnob {26 ""} addUserKnob {7 image_strength l "Image Strength"} image_strength 0.35 addUserKnob {4 ii_init_image_mode l "Init Image Mode" M {IMAGE_STRENGTH STEP_SCHEDULE.}} addUserKnob {26 ""} addUserKnob {7 ii_cfg_scale l "Cfg Scale" R 1 10} ii_cfg_scale 7 addUserKnob {4 ii_style_preset l "Style Preset" M {"" 3d-model analog-film anime cinematic comic-book digital-art enhance fantasy-art isometric line-art low-poly modeling-compound neon-punk origami photographic pixel-art tile-texture}} addUserKnob {4 ii_clip_guidance_preset l "Clip Guidance Preset" M {NONE FAST_BLUE FAST_GREEN SIMPLE SLOW SLOWER SLOWEST}} addUserKnob {4 ii_sampler l Sampler M {DDIM DDPM K_DPMPP_2M K_DPMPP_2S_ANCESTRAL K_EULER K_EULER_ANCESTRAL K_HEUN K_LMS}} addUserKnob {3 ii_samples l Samples t "Number of diffusion steps to run" R 1 10} ii_samples 1 addUserKnob {3 ii_seed l Seed R 1 4.29497e+09} addUserKnob {3 ii_steps l Steps R 10 150} ii_steps 30 addUserKnob {26 ""} addUserKnob {22 i2i_dream l Dream T "\nimport base64\nimport os\nimport requests\n\nengine_id = \"stable-diffusion-v1-5\"\napi_host = os.getenv('API_HOST', 'https://api.stability.ai')\napi_key = os.getenv(\"STABILITY_API_KEY\")\n\n# Get the directory of the current Nuke script\nscript_dir = os.path.dirname(nuke.root().name())\n# Set the subdirectory where the image files will be stored\nsub_dir = \"Stability\"\n# Set the directories where the image files and temp files will be stored\nimage_dir = os.path.join(script_dir, sub_dir, \"Images\")\ntemp_dir = os.path.join(script_dir, sub_dir, \"temp\")\n# Create the directories if they don't exist\nos.makedirs(image_dir, exist_ok=True)\nos.makedirs(temp_dir, exist_ok=True)\n# Get the list of existing image files in the directory\nexisting_files = os.listdir(image_dir)\n\nnuke.execute(nuke.toNode('write_init_image'), start=1, end=1)\n\nimg_engine = nuke.thisNode().knob('ii_engine_name').value()\nprompt1_img_img=str(nuke.thisNode().knob('ii_prompt1').value())\nweight1_img_img=nuke.thisNode().knob('ii_weight1').value()\nprompt2_img_img=str(nuke.thisNode().knob('ii_prompt2').value())\nweight2_img_img=nuke.thisNode().knob('ii_weight2').value()\ncfg_scale_img_img=int(nuke.thisNode().knob('ii_cfg_scale').value())\nclip_guidance_preset_img_img=nuke.thisNode().knob('ii_clip_guidance_preset').value()\nstyle_preset_img_img=nuke.thisNode().knob('ii_style_preset').value()\nsamples_img_img=int(nuke.thisNode().knob('ii_samples').value())\nsteps_img_img=int(nuke.thisNode().knob('ii_steps').value())\nweight_img_img=nuke.thisNode().knob('image_strength').getValue()\napi_key = nuke.thisNode().knob('api-key').value()\n\nwith nuke.thisNode():\n write_init_image_path = nuke.toNode('write_init_image')\['file'].value()\n\njson_data = \{\n \"text_prompts\[0]\[text]\": prompt1_img_img,\n \"text_prompts\[0]\[weight]\": weight1_img_img,\n \"text_prompts\[1]\[text]\": prompt2_img_img,\n \"text_prompts\[1]\[weight]\": weight2_img_img,\n \"image_strength\": weight_img_img,\n \"init_image_mode\": \"IMAGE_STRENGTH\",\n \"cfg_scale\": cfg_scale_img_img,\n \"clip_guidance_preset\": clip_guidance_preset_img_img,\n \"samples\": samples_img_img,\n \"steps\": steps_img_img,\n\}\n\nif style_preset_img_img:\n json_data\[\"style_preset\"] = style_preset_img_img\n\nresponse = requests.post(\n f\"\{api_host\}/v1/generation/\{img_engine\}/image-to-image\",\n headers=\{\n \"Accept\": \"application/json\",\n \"Authorization\": f\"Bearer \{api_key\}\"\n \},\n files=\{\n \"init_image\": open(write_init_image_path, \"rb\")\n \},\n data = json_data\n)\n\nif response.status_code != 200:\n raise Exception(\"Non-200 response: \" + str(response.text))\n\ndata = response.json()\n\nfor i, image in enumerate(data\[\"artifacts\"]):\n # Construct the initial filename\n file_name = f\"Image_To_Image_\{i\}.png\"\n input_path = os.path.join(image_dir, file_name)\n \n # Check if the filename already exists\n version = 1\n while os.path.exists(input_path):\n # If the file already exists, version up the filename\n version += 1\n file_name = f\"Image_To_Image_\{i\}_v\{version\}.png\"\n input_path = os.path.join(image_dir, file_name)\n \n # Write the image data to the new file\n with open(input_path, \"wb\") as f:\n f.write(base64.b64decode(image\[\"base64\"]))\n \n # Create a Read node for the new file\n with nuke.root():\n read_node = nuke.createNode(\"Read\", inpanel=False)\n read_node\['file'].fromUserText(input_path)" +STARTLINE} addUserKnob {20 upscale-tab l Upscale} addUserKnob {26 ""} addUserKnob {4 ui_engine_name l Model -STARTLINE M {esrgan-v1-x2plus stable-diffusion-x4-latent-upscaler}} addUserKnob {4 upscale l "Upscale size" M {1024x1024 2048x2048}} addUserKnob {26 ""} addUserKnob {22 i2i_u_dream l Dream T "\nimport os\nimport requests\n\nengine_id = \"esrgan-v1-x2plus\"\napi_host = os.getenv(\"API_HOST\", \"https://api.stability.ai\")\napi_key = os.getenv(\"STABILITY_API_KEY\")\n\n# Get the directory of the current Nuke script\nscript_dir = os.path.dirname(nuke.root().name())\n\n# Set the subdirectory where the image files will be stored\nsub_dir = \"Stability\"\n\n# Set the directories where the image files and temp files will be stored\nimage_dir = os.path.join(script_dir, sub_dir, \"Images\")\ntemp_dir = os.path.join(script_dir, sub_dir, \"temp\")\n\n# Create the directories if they don't exist\nos.makedirs(image_dir, exist_ok=True)\nos.makedirs(temp_dir, exist_ok=True)\n\n# Get the list of existing image files in the directory\nexisting_files = os.listdir(image_dir)\n\nnuke.execute(nuke.toNode('write_upscale_image'), start=1, end=1)\n\nupscale_engine = nuke.thisNode().knob('ui_engine_name').value()\napi_key = nuke.thisNode().knob('api-key').value()\n# Get the selected option from the Enumeration_Knob\nselected_option = nuke.thisNode().knob('upscale').value()\n# Set the integer variable based on the selected option\nif selected_option == \"1024x1024\":\n upscale_value = 1024\nelif selected_option == \"2048x2048\":\n upscale_value = 2048\n\nwith nuke.thisNode():\n write_upscale_image_path = nuke.toNode('write_upscale_image')\['file'].value()\n\nresponse = requests.post(\n f\"\{api_host\}/v1/generation/\{upscale_engine\}/image-to-image/upscale\",\n headers=\{\n \"Accept\": \"image/png\",\n \"Authorization\": f\"Bearer \{api_key\}\"\n \},\n files=\{\n \"image\": open(write_upscale_image_path, \"rb\")\n \},\n data=\{\n \"width\": upscale_value,\n \}\n)\n\ndata = response.content\n\n# Construct the initial filename\ninput_path = os.path.join(image_dir, f\"Image_upscaled_.png\")\n\n# Check if the filename already exists\nversion = 1\nwhile os.path.exists(input_path):\n # If the file already exists, version up the filename\n version += 1\n file_name = f\"Image_upscaled_\{upscale_value\}_v\{version\}.png\"\n input_path = os.path.join(image_dir, file_name)\n\n# Write the image data to the new file\nwith open(input_path, \"wb\") as f:\n f.write(response.content)\n\n# Create a Read node for the new file\nwith nuke.root():\n read_node = nuke.createNode(\"Read\", inpanel=False)\nread_node\['file'].fromUserText(input_path)" +STARTLINE} addUserKnob {20 inpainting l Inpainting} addUserKnob {26 ""} addUserKnob {4 iim_engine_name l Model M {stable-inpainting-v1-0 stable-inpainting-512-v2-0}} iim_engine_name stable-inpainting-512-v2-0 addUserKnob {26 ""} addUserKnob {43 iim_prompt1 l Prompt} iim_prompt1 "a pink unicorn with a cat riding it with a lot of rainbow" addUserKnob {7 iim_weight1 l "Prompt Weight" R -1 1} iim_weight1 0.5 addUserKnob {26 ""} addUserKnob {43 iim_prompt2 l "Second Prompt"} iim_prompt2 "a pink unicorn with a cat riding it with a lot of rainbow" addUserKnob {7 iim_weight2 l "Second Prompt Weight" R -1 1} iim_weight2 -0.9 addUserKnob {26 ""} addUserKnob {7 iim_cfg_scale l "Cfg Scale" R 1 10} iim_cfg_scale 7 addUserKnob {4 iim_style_preset l "Style Preset" M {"" 3d-model analog-film anime cinematic comic-book digital-art enhance fantasy-art isometric line-art low-poly modeling-compound neon-punk origami photographic pixel-art tile-texture}} addUserKnob {4 iim_clip_guidance_preset l "Clip Guidance Preset" M {NONE FAST_BLUE FAST_GREEN SIMPLE SLOW SLOWER SLOWEST}} addUserKnob {4 iim_sampler l Sampler M {DDIM DDPM K_DPMPP_2M K_DPMPP_2S_ANCESTRAL K_EULER K_EULER_ANCESTRAL K_HEUN K_LMS}} addUserKnob {3 iim_samples l Samples R 1 10} iim_samples 1 addUserKnob {3 iim_seed l Seed R 1 4.29497e+09} addUserKnob {3 iim_steps l Steps R 10 150} iim_steps 30 addUserKnob {26 ""} addUserKnob {22 i2i_m_dream l Dream T "\nimport base64\nimport os\nimport requests\n\nengine_id = \"stable-inpainting-512-v2-0\"\napi_host = os.getenv('API_HOST', 'https://api.stability.ai')\napi_key = os.getenv(\"STABILITY_API_KEY\")\n\n# Get the directory of the current Nuke script\nscript_dir = os.path.dirname(nuke.root().name())\n\n# Set the subdirectory where the image files will be stored\nsub_dir = \"Stability\"\n\n# Set the directories where the image files and temp files will be stored\nimage_dir = os.path.join(script_dir, sub_dir, \"Images\")\ntemp_dir = os.path.join(script_dir, sub_dir, \"temp\")\n\n# Create the directories if they don't exist\nos.makedirs(image_dir, exist_ok=True)\nos.makedirs(temp_dir, exist_ok=True)\n\n# Get the list of existing image files in the directory\nexisting_files = os.listdir(image_dir)\n\napi_key = nuke.thisNode().knob('api-key').value()\n\nnuke.execute(nuke.toNode('write_init_mask_image'), start=1, end=1)\nnuke.execute(nuke.toNode('write_mask_image'), start=1, end=1)\n\ninpaint_engine = nuke.thisNode().knob('iim_engine_name').value()\nprompt1_img_msk=nuke.thisNode().knob('iim_prompt1').getValue()\nprompt2_img_msk=nuke.thisNode().knob('iim_prompt1').getValue()\ncfg_scale_img_msk=int(nuke.thisNode().knob('iim_cfg_scale').getValue())\nclip_guidance_preset_img_msk=nuke.thisNode().knob('iim_clip_guidance_preset').value()\nstyle_preset_img_msk=nuke.thisNode().knob('iim_style_preset').value()\nsamples_img_msk=int(nuke.thisNode().knob('iim_samples').getValue())\nsteps_img_msk=int(nuke.thisNode().knob('iim_steps').getValue())\nweight1_img_msk=nuke.thisNode().knob('iim_weight1').getValue()\nweight2_img_msk=nuke.thisNode().knob('iim_weight2').getValue()\n\nwith nuke.thisNode():\n init_write_mask_image_path = nuke.toNode('write_init_mask_image')\['file'].value()\n write_mask_image_path = nuke.toNode('write_mask_image')\['file'].value()\n\njson_data = \{\n \"mask_source\": \"MASK_IMAGE_WHITE\",\n \"text_prompts\[0]\[text]\": prompt1_img_msk,\n \"text_prompts\[0]\[weight]\": weight1_img_msk,\n \"text_prompts\[1]\[text]\": prompt2_img_msk,\n \"text_prompts\[1]\[weight]\": weight2_img_msk,\n \"cfg_scale\": cfg_scale_img_msk,\n \"clip_guidance_preset\": clip_guidance_preset_img_msk,\n \"samples\": samples_img_msk,\n \"steps\": steps_img_msk,\n\}\n \nif style_preset_img_msk:\n json_data\[\"style_preset\"] = style_preset_img_msk\n\nresponse = requests.post(\n f\"\{api_host\}/v1/generation/\{inpaint_engine\}/image-to-image/masking\",\n headers=\{\n \"Accept\": 'application/json',\n \"Authorization\": f\"Bearer \{api_key\}\"\n \},\n files=\{\n 'init_image': open(init_write_mask_image_path, 'rb'),\n 'mask_image': open(write_mask_image_path, 'rb'),\n \},\n data = json_data\n)\n\nif response.status_code != 200:\n raise Exception(\"Non-200 response: \" + str(response.text))\n\ndata = response.json()\n\nfor i, image in enumerate(data\[\"artifacts\"]):\n # Construct the initial filename\n file_name = f\"Inpaint_Image_\{i\}.png\"\n input_path = os.path.join(image_dir, file_name)\n \n # Check if the filename already exists\n version = 1\n while os.path.exists(input_path):\n # If the file already exists, version up the filename\n version += 1\n file_name = f\"Inpaint_Image_\{i\}_v\{version\}.png\"\n input_path = os.path.join(image_dir, file_name)\n \n # Write the image data to the new file\n with open(input_path, \"wb\") as f:\n f.write(base64.b64decode(image\[\"base64\"]))\n \n # Create a Read node for the new file\n with nuke.root():\n read_node = nuke.createNode(\"Read\", inpanel=False)\n read_node\['file'].fromUserText(input_path)" +STARTLINE} addUserKnob {20 "" n -3} addUserKnob {20 account l Account} addUserKnob {26 ""} addUserKnob {26 sda l " " T "

Stable Diffusion for Nuke

"} addUserKnob {26 ""} addUserKnob {26 link l " " T "Get your Stability API key"} addUserKnob {26 ""} addUserKnob {1 api-key l "API key"} addUserKnob {26 ""} addUserKnob {26 sdinfo l " " T "STABLEDIFFUSION - Version 1.0 - 2023 - Github Page

Besar Ismaili

"} addUserKnob {26 ""} } Input { inputs 0 name Image xpos 180 ypos -9 } Reformat { format "512 512 0 0 512 512 1 square_512" resize fill name Reformat1 xpos 180 ypos 15 } set N5ef19c00 [stack 0] Write { file /Stability/temp/int2img_.png file_type png checkHashOnRead false name write_init_image xpos 180 ypos 39 } Input { inputs 0 name Mask xpos 290 ypos -9 number 1 } Shuffle2 { fromInput1 {{0} B} fromInput2 {{0} B} mappings "4 rgba.alpha 0 3 rgba.red 0 0 rgba.alpha 0 3 rgba.green 0 1 rgba.alpha 0 3 rgba.blue 0 2 rgba.alpha 0 3 rgba.alpha 0 3" name mask_input_shuffle xpos 290 ypos 15 } Reformat { format "512 512 0 0 512 512 1 square_512" resize fill name Reformat2 xpos 290 ypos 39 } set N5ef18400 [stack 0] Write { file /Stability/temp/mask_img_.png file_type png checkHashOnRead false name write_mask_image xpos 290 ypos 63 } push $N5ef19c00 Write { file /Stability/temp/upscale_img_.png file_type png checkHashOnRead false name write_upscale_image xpos 400 ypos 39 } push $N5ef19c00 Write { file /Stability/temp/init_mask_img_.png file_type png checkHashOnRead false name write_init_mask_image xpos 510 ypos 39 } push $N5ef18400 push $N5ef19c00 Merge { inputs 2 mix 0.5 name Merge1 xpos 400 ypos 63 } Output { name Output1 xpos 400 ypos 87 } end_group