This commit is contained in:
nat-chan
2024-05-15 20:19:59 +09:00
parent 2c7c140078
commit 0a3e22532b
3 changed files with 72 additions and 0 deletions
+22
View File
@@ -0,0 +1,22 @@
import server # noqa
from aiohttp import web
NODE_CLASS_MAPPINGS = {}
NODE_DISPLAY_NAME_MAPPINGS = {}
WEB_DIRECTORY = "./js"
__all__ = ["NODE_CLASS_MAPPINGS", "NODE_DISPLAY_NAME_MAPPINGS", "WEB_DIRECTORY"]
@server.PromptServer.instance.routes.post("/graph_to_prompt")
async def graph_to_prompt(request):
data = await request.json()
print("\x1b[31m", data, "\x1b[m")
server.PromptServer.instance.send_sync("run_workflow", data)
return web.Response()
@server.PromptServer.instance.routes.post("/graph_to_prompt_from_js")
async def graph_to_prompt_from_js(request):
data = await request.read()
print("\x1b[32m", data, "\x1b[m")
return web.Response()
+19
View File
@@ -0,0 +1,19 @@
import argparse
import json
import requests
def post_json_to_server(filepath):
with open(filepath, "r") as file:
data = json.load(file)
response = requests.post("http://localhost:8189/graph_to_prompt", json=data)
print(f"Response Status Code: {response.status_code}")
print(f"Response json: {response.json()}")
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Post JSON to server")
parser.add_argument("filepath", type=str, help="Path to the JSON file to post")
args = parser.parse_args()
post_json_to_server(args.filepath)
+31
View File
@@ -0,0 +1,31 @@
import { app, ComfyApp } from "../../scripts/app.js";
import { api } from "../../scripts/api.js";
app.registerExtension({
name: "ComfyUI-graphToPrompt",
async setup() {
// queuePromptを呼び出すイベントリスナーを追加
api.addEventListener("run_workflow", async ({ detail }) => {
await app.loadGraphData(detail);
let { workflow, workflow_api } = await app.graphToPrompt();
console.log("workflow", workflow);
console.log("workflow_api", workflow_api);
const response = await fetch('http://localhost:8189/graph_to_prompt_from_js', {
credentials: "same-origin",
mode: "same-origin",
method: "post",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(workflow)
});
if (!response.ok) {
console.error('サーバーからの応答がありません。エラー:', response.status);
} else {
const responseData = await response.json();
console.log('サーバーからの応答:', responseData);
}
});
}
})