Sergiu 10 сар өмнө
parent
commit
aa6e2f18dd

+ 142 - 0
03_blender/sd_blender/__init__.py

@@ -0,0 +1,142 @@
+# ----------------------------------------------------------
+# File __init__.py
+# ----------------------------------------------------------
+
+# Imports
+# Check if this add-on is being reloaded
+if "bpy" in locals():
+    # reloading .py files
+    import bpy
+    import importlib
+
+    from . import zs_renderscene as zsrs
+
+    importlib.reload(zsrs)
+    from . import zs_masterscene as zsms
+
+    importlib.reload(zsms)
+    from . import zs_renderscene as zsu
+
+    importlib.reload(zsu)
+
+    from . import zs_anvil
+
+    importlib.reload(zs_anvil)
+
+    from . import zs_deadline
+
+    importlib.reload(zs_deadline)
+
+    from . import zs_light_linking
+
+    importlib.reload(zs_light_linking)
+
+
+# or if this is the first load of this add-on
+else:
+    import bpy
+    import json
+    from pathlib import Path
+
+    from . import zs_masterscene as zsms  # noqa
+
+    from . import zs_renderscene as zsrs  # noqa
+
+    from . import zs_renderscene as zsu  # noqa
+
+    from . import zs_anvil
+
+    from . import zs_deadline
+
+    from . import zs_light_linking
+
+
+# Addon info
+bl_info = {
+    "name": "ZS Stable Diffusion Connection V0.0.1",
+    "author": "Sergiu <sergiu@zixelise.com>",
+    "Version": (0, 0, 1),
+    "blender": (4, 00, 0),
+    "category": "Scene",
+    "description": "Stable Diffusion Connection",
+}
+
+
+# -------------------------------------------------------------------
+# UI Functions
+# -------------------------------------------------------------------
+
+
+# -------------------------------------------------------------------
+# Operators
+# -------------------------------------------------------------------
+
+
+# parent class for panels
+class ZSSDPanel:
+    bl_space_type = "VIEW_3D"
+    bl_region_type = "UI"
+    bl_category = "ZS Scene Manager"
+
+
+# -------------------------------------------------------------------
+#   Draw
+# -------------------------------------------------------------------
+
+# Panels
+
+
+class ZSSD_PT_Main(ZSSDPanel, bpy.types.Panel):
+    bl_label = "SD Loader"
+
+    def draw(self, context):
+        layout = self.layout
+
+        scene = context.scene
+
+        col = layout.column()
+
+        self.is_connected = False
+
+        col.label(text="Stable Diffusion Connection")
+
+
+# modify after making products
+blender_classes = [
+    ZSSD_PT_Main,
+]
+
+
+def register():
+
+    # register classes
+    for blender_class in blender_classes:
+        bpy.utils.register_class(blender_class)
+
+    # Has to be after class registering to correctly register property
+    bpy.types.Scene.zs_ll_parameters = bpy.props.CollectionProperty(
+        type=zs_light_linking.ZS_LL_Parameter, name="Light Linking Parameters"
+    )
+
+    # register global properties
+
+    # register list
+
+    # list data
+
+    # bpy.types.Scene.zs_product_list = bpy.props.CollectionProperty(
+    #    type=ZS_Product_ListItem)
+
+    # current item in list
+
+
+def unregister():
+
+    # unregister classes
+    for blender_class in blender_classes:
+        bpy.utils.unregister_class(blender_class)
+    # unregister global properties
+
+    # unregister list items
+    # del bpy.types.Scene.my_list
+    # del bpy.types.Scene.product_product_list_index

+ 5 - 0
03_blender/sd_blender/mklink_40.bat

@@ -0,0 +1,5 @@
+mklink /J "C:\Users\hulpe\AppData\Roaming\Blender Foundation\Blender\4.0\scripts\addons\zs_scene_manager_addon" "D:\Git\zs_scene_manager_addon"
+
+ECHO\
+ECHO Enter your input string and press ENTER when done.
+ECHO\

+ 69 - 0
04_stable_diffusion/sd_comfy_api.py

@@ -0,0 +1,69 @@
+import json
+from urllib import request, parse
+import random
+
+# This is the ComfyUI api prompt format.
+
+# If you want it for a specific workflow you can "enable dev mode options"
+# in the settings of the UI (gear beside the "Queue Size: ") this will enable
+# a button on the UI to save workflows in api format.
+
+# keep in mind ComfyUI is pre alpha software so this format will change a bit.
+
+# this is the one for the default workflow
+
+# load the prompt from a workflow_api_test.json file
+with open(
+    "D://Temp//ComfyUI_windows_portable_nvidia//ComfyUI_windows_portable//ComfyUI//script_examples//custom//workflow_api_test.json",
+    "r",
+) as f:
+    prompt_text_json = f.read()
+
+
+def queue_prompt(prompt):
+    p = {"prompt": prompt}
+    data = json.dumps(p).encode("utf-8")
+    req = request.Request("http://127.0.0.1:8188/prompt", data=data)
+    request.urlopen(req)
+
+
+def find_node(json_obj, title):
+    for key, value in json_obj.items():
+        if isinstance(value, dict):
+            if value.get("_meta", {}).get("title") == title:
+                return value
+            else:
+                result = find_node(value, title)
+                if result:
+                    return result
+    return None
+
+
+def set_filename(json_obj, title, new_prefix):
+    for key, value in json_obj.items():
+        if isinstance(value, dict):
+            if value.get("_meta", {}).get("title") == title:
+                if "inputs" in value and "filename_prefix" in value["inputs"]:
+                    value["inputs"]["filename_prefix"] = new_prefix
+                else:
+                    result = set_filename(value, title, new_prefix)
+                    if result:
+                        return result
+    return None
+
+
+prompt = json.loads(prompt_text_json)
+set_filename(prompt, "Save Image", "custom/basic_api_example")
+
+ksampler_main = find_node(prompt, "KSampler")
+ksampler_main["inputs"]["seed"] = random.randint(0, 1000000)
+
+prompt_positive = find_node(prompt, "prompt_positive")
+prompt_positive["inputs"][
+    "text"
+] = "cosmetics bottle at sunset, beautiful product advertising, luxury"
+
+prompt_negative = find_node(prompt, "prompt_negative")
+prompt_negative["inputs"]["text"] = "ugly, bad"
+
+queue_prompt(prompt)

+ 128 - 0
04_stable_diffusion/sd_comfy_workflow_test.json

@@ -0,0 +1,128 @@
+{
+  "1": {
+    "inputs": {
+      "seed": 723859630206859,
+      "steps": 25,
+      "cfg": 7,
+      "sampler_name": "dpmpp_2m",
+      "scheduler": "karras",
+      "denoise": 1,
+      "model": [
+        "2",
+        0
+      ],
+      "positive": [
+        "3",
+        0
+      ],
+      "negative": [
+        "4",
+        0
+      ],
+      "latent_image": [
+        "5",
+        0
+      ]
+    },
+    "class_type": "KSampler",
+    "_meta": {
+      "title": "KSampler"
+    }
+  },
+  "2": {
+    "inputs": {
+      "ckpt_name": "dreamshaper_8.safetensors"
+    },
+    "class_type": "CheckpointLoaderSimple",
+    "_meta": {
+      "title": "Load Checkpoint"
+    }
+  },
+  "3": {
+    "inputs": {
+      "text": "cosmetics bottle, beautiful, photo",
+      "clip": [
+        "2",
+        1
+      ]
+    },
+    "class_type": "CLIPTextEncode",
+    "_meta": {
+      "title": "prompt_positive"
+    }
+  },
+  "4": {
+    "inputs": {
+      "text": "ugly, cheap",
+      "clip": [
+        "2",
+        1
+      ]
+    },
+    "class_type": "CLIPTextEncode",
+    "_meta": {
+      "title": "prompt_negative"
+    }
+  },
+  "5": {
+    "inputs": {
+      "width": 512,
+      "height": 768,
+      "batch_size": 1
+    },
+    "class_type": "EmptyLatentImage",
+    "_meta": {
+      "title": "Empty Latent Image"
+    }
+  },
+  "6": {
+    "inputs": {
+      "samples": [
+        "1",
+        0
+      ],
+      "vae": [
+        "7",
+        0
+      ]
+    },
+    "class_type": "VAEDecode",
+    "_meta": {
+      "title": "VAE Decode"
+    }
+  },
+  "7": {
+    "inputs": {
+      "vae_name": "taesd"
+    },
+    "class_type": "VAELoader",
+    "_meta": {
+      "title": "Load VAE"
+    }
+  },
+  "8": {
+    "inputs": {
+      "images": [
+        "6",
+        0
+      ]
+    },
+    "class_type": "PreviewImage",
+    "_meta": {
+      "title": "Preview Image"
+    }
+  },
+  "30": {
+    "inputs": {
+      "filename_prefix": "Image_Name",
+      "images": [
+        "6",
+        0
+      ]
+    },
+    "class_type": "SaveImage",
+    "_meta": {
+      "title": "Save Image"
+    }
+  }
+}

+ 34 - 0
05_deadline/sd_comfy_deadline.py

@@ -0,0 +1,34 @@
+import requests
+
+DDL_SERVER = "http://69.230.251.234:8081/api"
+
+script_path = "D://Temp//ComfyUI_windows_portable_nvidia//ComfyUI_windows_portable//ComfyUI//script_examples//custom//basic_api_example - Copy.py"
+
+
+def send_ddl_job(
+    job_info={
+        "Plugin": "Python",
+        "Priority": 49,
+        "Name": "ComfyUI Job",
+        "Group": "general",
+    },
+    plugin_info={"ScriptFile": script_path, "Version": "3.1"},
+):
+    url = f"{DDL_SERVER}/jobs"
+    data = {
+        "JobInfo": job_info,
+        "PluginInfo": plugin_info,
+        "AuxFiles": [],
+        "IdOnly": True,
+    }
+    response = requests.post(url, json=data)
+
+    if response.status_code == 200:
+        print("Data posted successfully.")
+        return response.json()
+    else:
+        print(f"Failed to post data. Status code: {response.status_code}")
+        return None
+
+
+send_ddl_job()