Allow default image in image node
This commit is contained in:
+5
-1
@@ -1 +1,5 @@
|
||||
__pycache__/*
|
||||
__pycache__/*
|
||||
/examples/node_modules/*
|
||||
|
||||
.idea
|
||||
.vscode
|
||||
@@ -1,5 +1,3 @@
|
||||
## Updated to include "Serving Input Image" node, you can now send image attachments via Discord for img2img generation.
|
||||
|
||||
# ComfyUI Serving Toolkit
|
||||
Welcome to the ComfyUI Serving Toolkit, a powerful tool for serving image generation workflows in Discord and other platforms (soon).
|
||||
This toolkit is designed to simplify the process of serving your ComfyUI workflow, making image generation bots easier than ever before.
|
||||
@@ -55,6 +53,11 @@ Outputs:
|
||||
|
||||
This will connect to a websocket and wait for JSON of {_requestId, prompt, arguments} and will return a json of {_requestId, base64_img}
|
||||
You can see an example ws server over at examples/websocket.js
|
||||
to run it you would need to navigate to the examples folder and run these commands:
|
||||
```
|
||||
npm install
|
||||
node websocket.js
|
||||
```
|
||||
|
||||
Inputs:
|
||||
* websocket_url - the url of the websocket you connect to, if you use the example it will be ws://localhost:8080
|
||||
|
||||
Generated
+37
@@ -0,0 +1,37 @@
|
||||
{
|
||||
"name": "websocket-example",
|
||||
"version": "1.0.0",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "websocket-example",
|
||||
"version": "1.0.0",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"ws": "^8.18.0"
|
||||
}
|
||||
},
|
||||
"node_modules/ws": {
|
||||
"version": "8.18.0",
|
||||
"resolved": "https://registry.npmjs.org/ws/-/ws-8.18.0.tgz",
|
||||
"integrity": "sha512-8VbfWfHLbbwu3+N6OKsOMpBdT4kXPDDB9cJk2bJ6mh9ucxdlnNvH1e+roYkKmN9Nxw2yjz7VzeO9oOz2zJ04Pw==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=10.0.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"bufferutil": "^4.0.1",
|
||||
"utf-8-validate": ">=5.0.2"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"bufferutil": {
|
||||
"optional": true
|
||||
},
|
||||
"utf-8-validate": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"name": "websocket-example",
|
||||
"version": "1.0.0",
|
||||
"main": "websocket.js",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"description": "",
|
||||
"dependencies": {
|
||||
"ws": "^8.18.0"
|
||||
}
|
||||
}
|
||||
@@ -35,12 +35,11 @@ function saveBase64Image(base64String, filePath) {
|
||||
}
|
||||
});
|
||||
}
|
||||
console.log("Listening on 8080")
|
||||
console.log("Listening on 8080. Use ws://localhost:8080 as the websocket URL in the websocket serving node");
|
||||
|
||||
function sendMessage(message) {
|
||||
wss.clients.forEach((client) => {
|
||||
console.log("Messaging Everyone a hi")
|
||||
|
||||
console.log("Sending the prompt - ", message.prompt)
|
||||
if (client.readyState === WebSocket.OPEN) {
|
||||
client.send(message);
|
||||
}
|
||||
@@ -51,5 +50,5 @@ function sendMessage(message) {
|
||||
let i = 0
|
||||
setInterval(() => sendMessage(JSON.stringify({
|
||||
_requestId: ++i,
|
||||
prompt: "Cow"
|
||||
prompt: "Robot saying 'it works!'",
|
||||
})), 5000)
|
||||
@@ -389,9 +389,7 @@ class WebSocketServing():
|
||||
"_requestId": data["_requestId"]
|
||||
}
|
||||
self.ws.send(json.dumps(response))
|
||||
data["serve_image_function"] = serve_image_function
|
||||
data["serve_multi_image_function"] = serve_multi_image_function
|
||||
data["serve_text_function"] = lambda text: self.ws.send(json.dumps({"text": text, "_requestId": data["_requestId"]}))
|
||||
|
||||
def serve_image_function(image, frame_duration):
|
||||
image_file = tensorToImageConversion(image, frame_duration)
|
||||
base64_img = base64.b64encode(image_file.read()).decode('utf-8')
|
||||
@@ -400,7 +398,11 @@ class WebSocketServing():
|
||||
"_requestId":data["_requestId"] # It's assumed that it will exist.
|
||||
}
|
||||
self.ws.send(json.dumps(response))
|
||||
|
||||
data["serve_image_function"] = serve_image_function
|
||||
data["serve_multi_image_function"] = serve_multi_image_function
|
||||
data["serve_text_function"] = lambda text: self.ws.send(
|
||||
json.dumps({"text": text, "_requestId": data["_requestId"]}))
|
||||
|
||||
return (data,)
|
||||
|
||||
@@ -413,7 +415,9 @@ class ServingInputImage:
|
||||
return {
|
||||
"required": {
|
||||
"serving_config": ("SERVING_CONFIG",),
|
||||
}
|
||||
|
||||
},
|
||||
"default_image": ("IMAGE",)
|
||||
}
|
||||
|
||||
RETURN_TYPES = ("IMAGE",)
|
||||
@@ -433,9 +437,11 @@ class ServingInputImage:
|
||||
image = torch.from_numpy(result)[None,]
|
||||
return image
|
||||
|
||||
def out(self, serving_config):
|
||||
def out(self, serving_config, default_image = None):
|
||||
attachment_url_key = "attachment_url_0"
|
||||
if attachment_url_key not in serving_config:
|
||||
if default_image is not None:
|
||||
return (default_image,)
|
||||
raise ValueError("No attachment found in serving_config")
|
||||
|
||||
attachment_url = serving_config[attachment_url_key]
|
||||
|
||||
+2
-1
@@ -1,3 +1,4 @@
|
||||
discord.py
|
||||
websocket-client
|
||||
rel
|
||||
rel
|
||||
opencv-python
|
||||
Reference in New Issue
Block a user