Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
32d42bf472 | ||
|
|
281b8408c9 | ||
|
|
b215c83b76 | ||
|
|
76bc1c343e | ||
|
|
42bc6926ae | ||
|
|
351a68831d | ||
|
|
1c0585fabe | ||
|
|
60d55d904b | ||
|
|
3a5ef069d9 | ||
|
|
77a493f0eb | ||
|
|
2f6a649801 | ||
|
|
4d0de66b0b | ||
|
|
0aa2747736 | ||
|
|
0351a2eaab | ||
|
|
4276ddbfb1 | ||
|
|
0094c08d1c | ||
|
|
14824e3473 | ||
|
|
ea32a8fbbe | ||
|
|
e7363070f1 | ||
|
|
39c22295bc | ||
|
|
881e48a10c | ||
|
|
dc6b71b494 | ||
|
|
4f689e1ad5 | ||
|
|
fa57d09325 | ||
|
|
af9a0dfe75 | ||
|
|
aa5416634c | ||
|
|
d5b1896fec | ||
|
|
b360c53cea | ||
|
|
ef9637f257 | ||
|
|
d0c9b00336 | ||
|
|
14a9e6006b | ||
|
|
be237bd10a | ||
|
|
d938df9f4f | ||
|
|
9ea8e993c4 | ||
|
|
cdca60ff04 | ||
|
|
9694b84c9c | ||
|
|
26ed53e53b | ||
|
|
a548adf762 | ||
|
|
fa4d3631f6 | ||
|
|
e53f61cc8c | ||
|
|
e42b98048f | ||
|
|
fc76d349eb | ||
|
|
a0f665c5f6 | ||
|
|
8c7cbf6ea3 | ||
|
|
507e096676 | ||
|
|
8f0a47307e | ||
|
|
0b4788d2af | ||
|
|
793854d21b | ||
|
|
f0bc65ed1b | ||
|
|
8f71ab9c39 | ||
|
|
ac6e6b660a | ||
|
|
58ea247a16 | ||
|
|
38d941b829 | ||
|
|
5b00e27355 | ||
|
|
5564e0b313 | ||
|
|
16b4858b48 | ||
|
|
77cd75a332 | ||
|
|
3ad6de7ce4 | ||
|
|
5fe795c13e | ||
|
|
9aaee0bc8c |
@@ -0,0 +1,25 @@
|
||||
name: Publish to Comfy registry
|
||||
on:
|
||||
workflow_dispatch:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
paths:
|
||||
- "pyproject.toml"
|
||||
|
||||
permissions:
|
||||
issues: write
|
||||
|
||||
jobs:
|
||||
publish-node:
|
||||
name: Publish Custom Node to registry
|
||||
runs-on: ubuntu-latest
|
||||
if: ${{ github.repository_owner == 'pydn' }}
|
||||
steps:
|
||||
- name: Check out code
|
||||
uses: actions/checkout@v4
|
||||
- name: Publish Custom Node
|
||||
uses: Comfy-Org/publish-node-action@v1
|
||||
with:
|
||||
## Add your own personal access token to your Github Repository secrets and reference it here.
|
||||
personal_access_token: ${{ secrets.REGISTRY_ACCESS_TOKEN }}
|
||||
@@ -1,4 +1,5 @@
|
||||
## ComfyUI-to-Python-Extension
|
||||

|
||||
|
||||
The `ComfyUI-to-Python-Extension` is a powerful tool that translates [ComfyUI](https://github.com/comfyanonymous/ComfyUI) workflows into executable Python code. Designed to bridge the gap between ComfyUI's visual interface and Python's programming environment, this script facilitates the seamless transition from design to code execution. Whether you're a data scientist, a software developer, or an AI enthusiast, this tool streamlines the process of implementing ComfyUI workflows in Python.
|
||||
|
||||
@@ -115,15 +116,27 @@ if __name__ == "__main__":
|
||||
- Creating large queues for image generation (For example, you could adjust the script to generate 1000 images without clicking ctrl+enter 1000 times)
|
||||
- Easily expanding or iterating on your architecture in Python once a foundational workflow is in place in the GUI
|
||||
|
||||
## V1.3.0 Release Notes
|
||||
- Generate .py file directly from the ComfyUI Web App
|
||||
|
||||

|
||||
|
||||
## V1.2.1 Release Notes
|
||||
- Dynamically change `comfyui_to_python.py` parameters with CLI arguments
|
||||
- Hotfix to handle nodes that accept kwargs.
|
||||
|
||||
## V1.2.0 Release Notes
|
||||
- Updates to adhere to latest changes from `ComfyUI`
|
||||
|
||||
## V1.0.0 Release Notes
|
||||
- **Use all the custom nodes!**
|
||||
- Custom nodes are now supported. If you run into any issues with code execution, first ensure that the each node works as expected in the GUI. If it works in the GUI, but not in the generated script, please submit an issue.
|
||||
|
||||
|
||||
## Usage
|
||||
## Installation
|
||||
|
||||
|
||||
1. Navigate to your `ComfyUI` directory
|
||||
1. Navigate to your `ComfyUI/custom_nodes` directory
|
||||
|
||||
2. Clone this repo
|
||||
```bash
|
||||
@@ -134,8 +147,8 @@ if __name__ == "__main__":
|
||||
```
|
||||
/comfy
|
||||
/comfy_extras
|
||||
/ComfyUI-to-Python-Extension
|
||||
/custom_nodes
|
||||
--/ComfyUI-to-Python-Extension
|
||||
/input
|
||||
/models
|
||||
/output
|
||||
@@ -156,30 +169,44 @@ if __name__ == "__main__":
|
||||
server.py
|
||||
```
|
||||
|
||||
3. Navigate to the `ComfyUI-to-Python-Extension` folder and install requirements
|
||||
## Web App Use
|
||||
1. Launch ComfyUI
|
||||
|
||||
2. Load your favorite workflow and click `Save As Script`
|
||||
|
||||

|
||||
|
||||
3. Type your desired file name into the pop up screen.
|
||||
|
||||
4. Move .py file from your downloads folder to your `ComfyUI` directory.
|
||||
|
||||
5. Now you can execute the newly created .py file to generate images without launching a server.
|
||||
|
||||
## CLI Usage
|
||||
1. Navigate to the `ComfyUI-to-Python-Extension` folder and install requirements
|
||||
```bash
|
||||
pip install -r requirements.txt
|
||||
```
|
||||
|
||||
4. Launch ComfyUI, click the gear icon over `Queue Prompt`, then check `Enable Dev mode Options`. **THE SCRIPT WILL NOT WORK IF YOU DO NOT ENABLE THIS OPTION!**
|
||||
2. Launch ComfyUI, click the gear icon over `Queue Prompt`, then check `Enable Dev mode Options`. **THE SCRIPT WILL NOT WORK IF YOU DO NOT ENABLE THIS OPTION!**
|
||||
|
||||

|
||||
|
||||
5. Load up your favorite workflows, then click the newly enabled `Save (API Format)` button under Queue Prompt
|
||||
3. Load up your favorite workflows, then click the newly enabled `Save (API Format)` button under Queue Prompt
|
||||
|
||||
6. Move the downloaded .json workflow file to your `ComfyUI/ComfyUI-to-Python-Extension` folder
|
||||
4. Move the downloaded .json workflow file to your `ComfyUI/ComfyUI-to-Python-Extension` folder
|
||||
|
||||
7. If needed, add arguments when executing `comfyui_to_python.py` to update the default `input_file` and `output_file` to match your .json workflow file and desired .py file name. By default, the script will look for a file called `workflow_api.json`. You can also update the `queue_size` variable to your desired number of images that you want to generate in a single script execution. By default, the scripts will generate 10 images. Run `python comfyui_to_python.py --help` for more details.
|
||||
5. If needed, add arguments when executing `comfyui_to_python.py` to update the default `input_file` and `output_file` to match your .json workflow file and desired .py file name. By default, the script will look for a file called `workflow_api.json`. You can also update the `queue_size` variable to your desired number of images that you want to generate in a single script execution. By default, the scripts will generate 10 images. Run `python comfyui_to_python.py --help` for more details.
|
||||
|
||||
8a. Run the script with default arguments:
|
||||
6a. Run the script with default arguments:
|
||||
```bash
|
||||
python comfyui_to_python.py
|
||||
```
|
||||
8b. Run the script with optional arguments:
|
||||
6b. Run the script with optional arguments:
|
||||
```bash
|
||||
python comfyui_to_python.py --input_file "workflow_api (2).json" --output_file my_workflow.py --queue_size 100
|
||||
```
|
||||
|
||||
9. After running `comfyui_to_python.py`, a new .py file will be created in the current working directory. If you made no changes, look for `workflow_api.py`.
|
||||
7. After running `comfyui_to_python.py`, a new .py file will be created in the current working directory. If you made no changes, look for `workflow_api.py`.
|
||||
|
||||
10. Now you can execute the newly created .py file to generate images without launching a server.
|
||||
8. Now you can execute the newly created .py file to generate images without launching a server.
|
||||
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
import sys
|
||||
import os
|
||||
|
||||
from io import StringIO
|
||||
|
||||
import traceback
|
||||
|
||||
from aiohttp import web
|
||||
|
||||
ext_dir = os.path.dirname(__file__)
|
||||
sys.path.append(ext_dir)
|
||||
|
||||
try:
|
||||
import black
|
||||
except ImportError:
|
||||
print("Unable to import requirements for ComfyUI-SaveAsScript.")
|
||||
print("Installing...")
|
||||
|
||||
import importlib
|
||||
|
||||
spec = importlib.util.spec_from_file_location(
|
||||
"impact_install", os.path.join(os.path.dirname(__file__), "install.py")
|
||||
)
|
||||
impact_install = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(impact_install)
|
||||
|
||||
print("Successfully installed. Hopefully, at least.")
|
||||
|
||||
# Prevent reimporting of custom nodes
|
||||
os.environ["RUNNING_IN_COMFYUI"] = "TRUE"
|
||||
|
||||
from comfyui_to_python import ComfyUItoPython
|
||||
|
||||
sys.path.append(os.path.dirname(os.path.dirname(ext_dir)))
|
||||
|
||||
import server
|
||||
|
||||
WEB_DIRECTORY = "js"
|
||||
NODE_CLASS_MAPPINGS = {}
|
||||
|
||||
|
||||
@server.PromptServer.instance.routes.post("/saveasscript")
|
||||
async def save_as_script(request):
|
||||
try:
|
||||
data = await request.json()
|
||||
name = data["name"]
|
||||
workflow = data["workflow"]
|
||||
|
||||
sio = StringIO()
|
||||
ComfyUItoPython(workflow=workflow, output_file=sio)
|
||||
|
||||
sio.seek(0)
|
||||
data = sio.read()
|
||||
|
||||
return web.Response(text=data, status=200)
|
||||
except Exception as e:
|
||||
traceback.print_exc()
|
||||
return web.Response(text=str(e), status=500)
|
||||
+77
-56
@@ -6,12 +6,13 @@ import os
|
||||
import random
|
||||
import sys
|
||||
import re
|
||||
from typing import Dict, List, Callable, Tuple
|
||||
from typing import Dict, List, Any, Callable, Tuple, TextIO
|
||||
from argparse import ArgumentParser
|
||||
|
||||
import black
|
||||
|
||||
|
||||
# Add current directory to Python path
|
||||
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
||||
from comfyui_to_python_utils import (
|
||||
import_custom_nodes,
|
||||
find_path,
|
||||
@@ -20,7 +21,7 @@ from comfyui_to_python_utils import (
|
||||
get_value_at_index,
|
||||
)
|
||||
|
||||
sys.path.append("../")
|
||||
add_comfyui_directory_to_sys_path()
|
||||
from nodes import NODE_CLASS_MAPPINGS
|
||||
|
||||
|
||||
@@ -36,7 +37,7 @@ class FileHandler:
|
||||
"""
|
||||
|
||||
@staticmethod
|
||||
def read_json_file(file_path: str) -> dict:
|
||||
def read_json_file(file_path: str | TextIO, encoding: str = "utf-8") -> dict:
|
||||
"""
|
||||
Reads a JSON file and returns its contents as a dictionary.
|
||||
|
||||
@@ -51,35 +52,14 @@ class FileHandler:
|
||||
ValueError: If the file is not a valid JSON.
|
||||
"""
|
||||
|
||||
try:
|
||||
with open(file_path, "r") as file:
|
||||
data = json.load(file)
|
||||
return data
|
||||
|
||||
except FileNotFoundError:
|
||||
# Get the directory from the file_path
|
||||
directory = os.path.dirname(file_path)
|
||||
|
||||
# If the directory is an empty string (which means file is in the current directory),
|
||||
# get the current working directory
|
||||
if not directory:
|
||||
directory = os.getcwd()
|
||||
|
||||
# Find all JSON files in the directory
|
||||
json_files = glob.glob(f"{directory}/*.json")
|
||||
|
||||
# Format the list of JSON files as a string
|
||||
json_files_str = "\n".join(json_files)
|
||||
|
||||
raise FileNotFoundError(
|
||||
f"\n\nFile not found: {file_path}. JSON files in the directory:\n{json_files_str}"
|
||||
)
|
||||
|
||||
except json.JSONDecodeError:
|
||||
raise ValueError(f"Invalid JSON format in file: {file_path}")
|
||||
if hasattr(file_path, "read"):
|
||||
return json.load(file_path)
|
||||
with open(file_path, "r", encoding="utf-8") as file:
|
||||
data = json.load(file)
|
||||
return data
|
||||
|
||||
@staticmethod
|
||||
def write_code_to_file(file_path: str, code: str) -> None:
|
||||
def write_code_to_file(file_path: str | TextIO, code: str) -> None:
|
||||
"""Write the specified code to a Python file.
|
||||
|
||||
Args:
|
||||
@@ -89,16 +69,19 @@ class FileHandler:
|
||||
Returns:
|
||||
None
|
||||
"""
|
||||
# Extract directory from the filename
|
||||
directory = os.path.dirname(file_path)
|
||||
if isinstance(file_path, str):
|
||||
# Extract directory from the filename
|
||||
directory = os.path.dirname(file_path)
|
||||
|
||||
# If the directory does not exist, create it
|
||||
if directory and not os.path.exists(directory):
|
||||
os.makedirs(directory)
|
||||
# If the directory does not exist, create it
|
||||
if directory and not os.path.exists(directory):
|
||||
os.makedirs(directory)
|
||||
|
||||
# Save the code to a .py file
|
||||
with open(file_path, "w") as file:
|
||||
file.write(code)
|
||||
# Save the code to a .py file
|
||||
with open(file_path, "w", encoding="utf-8") as file:
|
||||
file.write(code)
|
||||
else:
|
||||
file_path.write(code)
|
||||
|
||||
|
||||
class LoadOrderDeterminer:
|
||||
@@ -203,15 +186,12 @@ class CodeGenerator:
|
||||
def generate_workflow(
|
||||
self,
|
||||
load_order: List,
|
||||
filename: str = "generated_code_workflow.py",
|
||||
queue_size: int = 10,
|
||||
) -> str:
|
||||
"""Generate the execution code based on the load order.
|
||||
|
||||
Args:
|
||||
load_order (List): A list of tuples representing the load order.
|
||||
filename (str): The name of the Python file to which the code should be saved.
|
||||
Defaults to 'generated_code_workflow.py'.
|
||||
queue_size (int): The number of photos that will be created by the script.
|
||||
|
||||
Returns:
|
||||
@@ -232,8 +212,18 @@ class CodeGenerator:
|
||||
for idx, data, is_special_function in load_order:
|
||||
# Generate class definition and inputs from the data
|
||||
inputs, class_type = data["inputs"], data["class_type"]
|
||||
input_types = self.node_class_mappings[class_type].INPUT_TYPES()
|
||||
class_def = self.node_class_mappings[class_type]()
|
||||
|
||||
# If required inputs are not present, skip the node as it will break the code if passed through to the script
|
||||
missing_required_variable = False
|
||||
if "required" in input_types.keys():
|
||||
for required in input_types["required"]:
|
||||
if required not in inputs.keys():
|
||||
missing_required_variable = True
|
||||
if missing_required_variable:
|
||||
continue
|
||||
|
||||
# If the class hasn't been initialized yet, initialize it and generate the import statements
|
||||
if class_type not in initialized_objects:
|
||||
# No need to use preview image nodes since we are executing the script in a terminal
|
||||
@@ -263,7 +253,12 @@ class CodeGenerator:
|
||||
if no_params or key in class_def_params
|
||||
}
|
||||
# Deal with hidden variables
|
||||
if class_def_params is not None:
|
||||
if (
|
||||
"hidden" in input_types.keys()
|
||||
and "unique_id" in input_types["hidden"].keys()
|
||||
):
|
||||
inputs["unique_id"] = random.randint(1, 2**64)
|
||||
elif class_def_params is not None:
|
||||
if "unique_id" in class_def_params:
|
||||
inputs["unique_id"] = random.randint(1, 2**64)
|
||||
|
||||
@@ -515,23 +510,37 @@ class ComfyUItoPython:
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
input_file: str,
|
||||
output_file: str,
|
||||
queue_size: int = 10,
|
||||
workflow: str = "",
|
||||
input_file: str = "",
|
||||
output_file: str | TextIO = "",
|
||||
queue_size: int = 1,
|
||||
node_class_mappings: Dict = NODE_CLASS_MAPPINGS,
|
||||
needs_init_custom_nodes: bool = False,
|
||||
):
|
||||
"""Initialize the ComfyUItoPython class with the given parameters.
|
||||
|
||||
"""Initialize the ComfyUItoPython class with the given parameters. Exactly one of workflow or input_file must be specified.
|
||||
Args:
|
||||
workflow (str): The workflow's JSON.
|
||||
input_file (str): Path to the input JSON file.
|
||||
output_file (str): Path to the output Python file.
|
||||
queue_size (int): The number of times a workflow will be executed by the script. Defaults to 10.
|
||||
output_file (str | TextIO): Path to the output file or a file-like object.
|
||||
queue_size (int): The number of times a workflow will be executed by the script. Defaults to 1.
|
||||
node_class_mappings (Dict): Mappings of node classes. Defaults to NODE_CLASS_MAPPINGS.
|
||||
needs_init_custom_nodes (bool): Whether to initialize custom nodes. Defaults to False.
|
||||
"""
|
||||
if input_file and workflow:
|
||||
raise ValueError("Can't provide both input_file and workflow")
|
||||
elif not input_file and not workflow:
|
||||
raise ValueError("Needs input_file or workflow")
|
||||
|
||||
if not output_file:
|
||||
raise ValueError("Needs output_file")
|
||||
|
||||
self.workflow = workflow
|
||||
self.input_file = input_file
|
||||
self.output_file = output_file
|
||||
self.queue_size = queue_size
|
||||
self.node_class_mappings = node_class_mappings
|
||||
self.needs_init_custom_nodes = needs_init_custom_nodes
|
||||
|
||||
self.base_node_class_mappings = copy.deepcopy(self.node_class_mappings)
|
||||
self.execute()
|
||||
|
||||
@@ -541,11 +550,18 @@ class ComfyUItoPython:
|
||||
Returns:
|
||||
None
|
||||
"""
|
||||
# Step 1: Import all custom nodes
|
||||
import_custom_nodes()
|
||||
# Step 1: Import all custom nodes if we need to
|
||||
if self.needs_init_custom_nodes:
|
||||
import_custom_nodes()
|
||||
else:
|
||||
# If they're already imported, we don't know which nodes are custom nodes, so we need to import all of them
|
||||
self.base_node_class_mappings = {}
|
||||
|
||||
# Step 2: Read JSON data from the input file
|
||||
data = FileHandler.read_json_file(self.input_file)
|
||||
if self.input_file:
|
||||
data = FileHandler.read_json_file(self.input_file)
|
||||
else:
|
||||
data = json.loads(self.workflow)
|
||||
|
||||
# Step 3: Determine the load order
|
||||
load_order_determiner = LoadOrderDeterminer(data, self.node_class_mappings)
|
||||
@@ -556,7 +572,7 @@ class ComfyUItoPython:
|
||||
self.node_class_mappings, self.base_node_class_mappings
|
||||
)
|
||||
generated_code = code_generator.generate_workflow(
|
||||
load_order, filename=self.output_file, queue_size=self.queue_size
|
||||
load_order, queue_size=self.queue_size
|
||||
)
|
||||
|
||||
# Step 5: Write the generated code to a file
|
||||
@@ -582,7 +598,12 @@ def run(
|
||||
Returns:
|
||||
None
|
||||
"""
|
||||
ComfyUItoPython(input_file, output_file, queue_size)
|
||||
ComfyUItoPython(
|
||||
input_file=input_file,
|
||||
output_file=output_file,
|
||||
queue_size=queue_size,
|
||||
needs_init_custom_nodes=True,
|
||||
)
|
||||
|
||||
|
||||
def main() -> None:
|
||||
@@ -612,7 +633,7 @@ def main() -> None:
|
||||
default=DEFAULT_QUEUE_SIZE,
|
||||
)
|
||||
pargs = parser.parse_args()
|
||||
ComfyUItoPython(**vars(pargs))
|
||||
run(**vars(pargs))
|
||||
print("Done.")
|
||||
|
||||
|
||||
|
||||
@@ -2,8 +2,6 @@ import os
|
||||
from typing import Sequence, Mapping, Any, Union
|
||||
import sys
|
||||
|
||||
sys.path.append("../")
|
||||
|
||||
|
||||
def import_custom_nodes() -> None:
|
||||
"""Find all custom nodes in the custom_nodes folder and add those node objects to NODE_CLASS_MAPPINGS
|
||||
@@ -14,6 +12,7 @@ def import_custom_nodes() -> None:
|
||||
import asyncio
|
||||
import execution
|
||||
from nodes import init_extra_nodes
|
||||
sys.path.insert(0, find_path("ComfyUI"))
|
||||
import server
|
||||
|
||||
# Creating a new event loop and setting it as the default loop
|
||||
@@ -25,7 +24,7 @@ def import_custom_nodes() -> None:
|
||||
execution.PromptQueue(server_instance)
|
||||
|
||||
# Initializing custom nodes
|
||||
init_extra_nodes()
|
||||
asyncio.run(init_extra_nodes())
|
||||
|
||||
|
||||
def find_path(name: str, path: str = None) -> str:
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 712 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 58 KiB |
+20
@@ -0,0 +1,20 @@
|
||||
import os
|
||||
import sys
|
||||
|
||||
from subprocess import Popen, check_output, PIPE
|
||||
|
||||
requirements = open(os.path.join(os.path.dirname(__file__), "requirements.txt")).read().split("\n")
|
||||
|
||||
installed_packages = check_output(
|
||||
[sys.executable, "-m", "pip", "list"],
|
||||
universal_newlines=True
|
||||
).split("\n")
|
||||
|
||||
installed_packages = set([package.split(" ")[0].lower() for package in installed_packages if package.strip()])
|
||||
|
||||
for requirement in requirements:
|
||||
if requirement.lower() not in installed_packages:
|
||||
print(f"Installing requirements...")
|
||||
Popen([sys.executable, "-m", "pip", "install", "-r", "requirements.txt"], stdout=PIPE, stderr=PIPE, cwd=os.path.dirname(__file__)).communicate()
|
||||
print(f"Installed.")
|
||||
break
|
||||
@@ -0,0 +1,60 @@
|
||||
import { api } from "../../scripts/api.js";
|
||||
import { app } from "../../scripts/app.js";
|
||||
import { $el } from "../../scripts/ui.js";
|
||||
|
||||
const extension = {
|
||||
name: "Comfy.SaveAsScript",
|
||||
commands: [
|
||||
{
|
||||
id: "triggerSaveAsScript",
|
||||
label: "Save As Script",
|
||||
function: () => { extension.savePythonScript(); }
|
||||
}
|
||||
],
|
||||
menuCommands: [
|
||||
{
|
||||
path: ["File"],
|
||||
commands: ["triggerSaveAsScript"]
|
||||
}
|
||||
],
|
||||
init() {
|
||||
$el("style", {
|
||||
parent: document.head,
|
||||
});
|
||||
},
|
||||
savePythonScript() {
|
||||
var filename = prompt("Save script as:");
|
||||
if(filename === undefined || filename === null || filename === "") {
|
||||
return
|
||||
}
|
||||
|
||||
app.graphToPrompt().then(async (p) => {
|
||||
const json = JSON.stringify({name: filename + ".json", workflow: JSON.stringify(p.output, null, 2)}, null, 2); // convert the data to a JSON string
|
||||
var response = await api.fetchApi(`/saveasscript`, { method: "POST", body: json });
|
||||
if(response.status == 200) {
|
||||
const blob = new Blob([await response.text()], {type: "text/python;charset=utf-8"});
|
||||
const url = URL.createObjectURL(blob);
|
||||
if(!filename.endsWith(".py")) {
|
||||
filename += ".py";
|
||||
}
|
||||
|
||||
const a = $el("a", {
|
||||
href: url,
|
||||
download: filename,
|
||||
style: {display: "none"},
|
||||
parent: document.body,
|
||||
});
|
||||
a.click();
|
||||
setTimeout(function () {
|
||||
a.remove();
|
||||
window.URL.revokeObjectURL(url);
|
||||
}, 0);
|
||||
}
|
||||
});
|
||||
},
|
||||
async setup() {
|
||||
console.log("SaveAsScript loaded");
|
||||
}
|
||||
};
|
||||
|
||||
app.registerExtension(extension);
|
||||
@@ -0,0 +1,15 @@
|
||||
[project]
|
||||
name = "comfyui-to-python-extension"
|
||||
description = "This custom node allows you to generate pure python code from your ComfyUI workflow with the click of a button. Great for rapid experimentation or production deployment."
|
||||
version = "1.3.1"
|
||||
license = { text = "MIT License" }
|
||||
dependencies = ["black"]
|
||||
|
||||
[project.urls]
|
||||
Repository = "https://github.com/pydn/ComfyUI-to-Python-Extension"
|
||||
# Used by Comfy Registry https://comfyregistry.org
|
||||
|
||||
[tool.comfy]
|
||||
PublisherId = "pydn"
|
||||
DisplayName = "ComfyUI-to-Python-Extension"
|
||||
Icon = ""
|
||||
@@ -1,13 +1 @@
|
||||
torch
|
||||
torchdiffeq
|
||||
torchsde
|
||||
einops
|
||||
transformers>=4.25.1
|
||||
safetensors>=0.3.0
|
||||
aiohttp
|
||||
accelerate
|
||||
pyyaml
|
||||
Pillow
|
||||
scipy
|
||||
tqdm
|
||||
black
|
||||
Reference in New Issue
Block a user