Compare commits

...
7 Commits
Author SHA1 Message Date
shadowcz007 c8b24fe84b Update Watcher.py 2023-12-01 23:00:45 +08:00
shadowcz007 798aabf333 bugfix 2023-12-01 22:10:27 +08:00
shadow d38a7aa558 Merge pull request #14 from shadowcz007/v0.3-psd读取分层
v0.2.2
2023-12-01 19:54:15 +08:00
shadowcz007 0bdf1e47a6 v0.2.2
- 本地读取节点也可以更新prompt了
2023-12-01 19:53:50 +08:00
shadowcz007 a44016e57c Update README.md 2023-12-01 18:20:03 +08:00
shadowcz007 35a9351e53 1 2023-12-01 17:51:31 +08:00
shadowcz007 c1b2112bb8 Update requirements.txt 2023-12-01 16:39:16 +08:00
9 changed files with 187 additions and 113 deletions
+2 -1
View File
@@ -1,4 +1,5 @@
##
![screenshare](./assets/screenshare.png)
@@ -61,7 +62,7 @@ pip3 install -r requirements.txt
>LoadImagesFromLocal
> LoadImagesFromLocal
![watch](./assets/load-watch.png)
+10 -8
View File
@@ -196,15 +196,17 @@ routes = web.RouteTableDef()
async def mixlab_hander(request):
config=os.path.join(current_path, "nodes/config.json")
data={}
# print(config)
if os.path.exists(config):
with open(config, 'r') as f:
data = json.load(f)
# print(data)
try:
if os.path.exists(config):
with open(config, 'r') as f:
data = json.load(f)
# print(data)
except Exception as e:
print(e)
return web.json_response(data)
@routes.post('/mixlab/workflow')
async def mixlab_hander(request):
async def mixlab_workflow_hander(request):
data = await request.json()
result={}
try:
@@ -276,8 +278,8 @@ NODE_CLASS_MAPPINGS = {
"VAEDecodeConsistencyDecoder":VAEDecode,
"ScreenShare":ScreenShareNode,
"FloatingVideo":FloatingVideo,
"CLIPSeg":CLIPSeg,
"CombineMasks":CombineMasks
"CLIPSeg_":CLIPSeg,
"CombineMasks_":CombineMasks
}
# 一个包含节点友好/可读的标题的字典
+8 -7
View File
@@ -583,32 +583,33 @@ class LoadImagesFromPath:
"white_bg": (["disable","enable"],),
"newest_files": (["enable", "disable"],),
"index_variable":("INT", {
"default": -1,
"default": 0,
"min": -1, #Minimum value
"max": 2048, #Maximum value
"step": 1, #Slider's step
"display": "number" # Cosmetic only: display as "number" or "slider"
}),
"watcher":(["disable","enable"],),
"result": ("WATCHER",),
"result": ("WATCHER",),#为了激活本节点运行
"prompt": ("PROMPT",),
# "seed": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff}),
}
}
RETURN_TYPES = ('IMAGE','MASK',)
RETURN_TYPES = ('IMAGE','MASK','STRING')
FUNCTION = "run"
CATEGORY = "Mixlab/image"
# INPUT_IS_LIST = True
OUTPUT_IS_LIST = (True,True,)
OUTPUT_IS_LIST = (True,True,False,)
global watcher_folder
watcher_folder=None
# 运行的函数
def run(self,file_path,white_bg,newest_files,index_variable,watcher,result):
def run(self,file_path,white_bg,newest_files,index_variable,watcher,result,prompt):
global watcher_folder
# print('###监听:',watcher_folder,watcher,file_path,result)
@@ -642,8 +643,8 @@ class LoadImagesFromPath:
imgs=[imgs[index_variable]] if index_variable < len(imgs) else None
masks=[masks[index_variable]] if index_variable < len(masks) else None
return (imgs,masks,)
print('#prompt::::',prompt)
return (imgs,masks,prompt,)
# TODO 扩大选区的功能,重新输出mask
+21 -12
View File
@@ -8,25 +8,34 @@ import os
# print('Watcher:',current_directory)
def save_to_json(file_path, data):
with open(file_path, 'w') as f:
json.dump(data, f)
try:
with open(file_path, 'w') as f:
json.dump(data, f)
except Exception as e:
print(e)
def read_from_json(file_path):
with open(file_path, 'r') as f:
data = json.load(f)
data={}
try:
with open(file_path, 'r') as f:
data = json.load(f)
except Exception as e:
print(e)
return data
# read_from_json()
current_path = os.path.abspath(os.path.dirname(__file__))
config_json=os.path.join(current_path,'config.json')
print('Watcher:',config_json)
# print('Watcher:',config_json)
def read_config():
config={}
if os.path.exists(config_json):
# print('exists')
config=read_from_json(config_json)
try:
if os.path.exists(config_json):
config=read_from_json(config_json)
except Exception as e:
print(e)
return config
@@ -42,7 +51,7 @@ class FolderWatcher:
# self.observer = Observer()
self.event_handler = self._create_event_handler()
self.status = "Not started"
self.event_type=''
self.event_type='-'
def _create_event_handler(self):
@@ -77,14 +86,14 @@ class FolderWatcher:
config=read_config()
config['folder_path']=new_folder_path
save_to_json(config_json,config)
self.event_type=''
self.event_type='-'
def start(self):
self.observer = Observer()
self.observer.schedule(self.event_handler, self.folder_path, recursive=True)
self.observer.start()
self.status = "Listening"
self.event_type=''
self.event_type='-'
print('Listening')
def stop(self):
@@ -92,7 +101,7 @@ class FolderWatcher:
self.observer.join()
self.observer=None
self.status = "Stopped"
self.event_type=''
self.event_type='-'
print('Stopped')
+3 -1
View File
@@ -1,3 +1,5 @@
numpy
pyOpenSSL
watchdog
watchdog
opencv-python-headless
matplotlib
+1 -1
View File
@@ -3,7 +3,7 @@ import { app } from '../../../scripts/app.js'
const repoOwner = 'shadowcz007' // 替换为仓库的所有者
const repoName = 'comfyui-mixlab-nodes' // 替换为仓库的名称
const version='v0.2.1'
const version='v0.2.2'
fetch(`https://api.github.com/repos/${repoOwner}/${repoName}/releases/latest`)
+45 -33
View File
@@ -402,6 +402,7 @@ const base64Df =
app.registerExtension({
name: 'Mixlab.image.ScreenShareNode',
async getCustomWidgets (app) {
console.log('#Mixlab.image.ScreenShareNode', app)
return {
CHEESE (node, inputName, inputData, app) {
// We return an object containing a field CHEESE which has a function (taking node, name, data, app)
@@ -419,8 +420,8 @@ app.registerExtension({
return window._mixlab_screen_imagePath || base64Df
}
}
// widget.something = something; // maybe adds stuff to it
node.addCustomWidget(widget) // adds it to the node
// console.log('#Mixlab.image.ScreenShareNode',widget)
node.addCustomWidget(widget)
return widget // and returns it.
},
PROMPT (node, inputName, inputData, app) {
@@ -439,7 +440,7 @@ app.registerExtension({
return window._mixlab_screen_prompt || ''
}
}
console.log('###widget', widget)
// console.log('###widget', widget)
node.addCustomWidget(widget) // adds it to the node
return widget // and returns it.
}
@@ -990,11 +991,16 @@ app.registerExtension({
function handleKeyDown (event) {
if (event.key === 'Enter') {
console.log('##更新Prompt')
window._mixlab_screen_prompt =
window._mixlab_screen_prompt_input ||
window._mixlab_screen_prompt
document.querySelector('#queue-button').click()
if (!event.shiftKey) {
// 回车键被按下且未同时按下Shift键,执行你的操作
event.preventDefault() // 阻止默认行为(如提交表单)
// 在这里添加你的代码
console.log('##更新Prompt')
window._mixlab_screen_prompt =
window._mixlab_screen_prompt_input ||
window._mixlab_screen_prompt
document.querySelector('#queue-button').click()
}
}
}
@@ -1437,24 +1443,30 @@ function getURLParameters (url) {
const node = {
name: 'RandomPrompt',
async init (app) {
// Any initial setup to run as soon as the page loads
console.log('[logging]', 'extension init')
if (window.location.href.match('/?')) {
const { workflow } = getURLParameters(window.location.href)
if (workflow)
get_my_workflow().then(data => {
console.log('#get_my_workflow', data)
let my_workflow = data.filter(
d => d.filename == 'my_workflow.json'
)[0]
if (my_workflow?.data) {
// app.loadGraphData(my_workflow.data)
localStorage.setItem('workflow',JSON.stringify(my_workflow.data));
}
})
}
},
async setup (a) {
for (const node of app.graph._nodes) {
// console.log('#setup', node)
console.log('#setup', node)
if (node.type === 'RandomPrompt') {
updateUI(node)
if (window.location.href.match('/?')) {
const { workflow } = getURLParameters(window.location.href)
if (workflow)
get_my_workflow().then(data => {
console.log('#get_my_workflow', data)
let my_workflow = data.filter(
d => d.filename == 'my_workflow.json'
)[0]
if (my_workflow?.data) {
app.loadGraphData(my_workflow.data)
}
})
}
}
}
// console.log('[logging]', 'loaded graph node: ', exportGraph(app.graph))
@@ -1505,17 +1517,17 @@ const node = {
// 汉化
// app.graph._nodes // title ='123'
if (nodeData.name === 'SaveTransparentImage') {
const onExecuted = nodeType.prototype.onExecuted
nodeType.prototype.onExecuted = function (message) {
const r = onExecuted?.apply?.(this, arguments)
console.log('executed', message)
const { image_path } = message
if (image_path) {
}
return r
}
}
// if (nodeData.name === 'SaveTransparentImage') {
// const onExecuted = nodeType.prototype.onExecuted
// nodeType.prototype.onExecuted = function (message) {
// const r = onExecuted?.apply?.(this, arguments)
// console.log('executed', message)
// const { image_path } = message
// if (image_path) {
// }
// return r
// }
// }
if (nodeData.name === 'WSServer') {
// Create the button widget for selecting the files
+22
View File
@@ -14,6 +14,8 @@ async function getConfig () {
return await res.json()
}
if(!window._mixlab_screen_prompt) window._mixlab_screen_prompt="beautiful scenery nature glass bottle landscape,under water"
function get_position_style (ctx, widget_width, y, node_height) {
const MARGIN = 4 // the margin around the html element
@@ -69,6 +71,26 @@ app.registerExtension({
// widget.something = something; // maybe adds stuff to it
node.addCustomWidget(widget) // adds it to the node
return widget // and returns it.
},
PROMPT (node, inputName, inputData, app) {
// console.log('node', inputName, inputData[0])
const widget = {
type: inputData[0], // the type, CHEESE
name: inputName, // the name, slice
size: [128, 24], // a default size
draw (ctx, node, width, y) {
// a method to draw the widget (ctx is a CanvasRenderingContext2D)
},
computeSize (...args) {
return [128, 24] // a method to compute the current size of the widget
},
async serializeValue (nodeId, widgetIndex) {
return window._mixlab_screen_prompt || ''
}
}
// widget.something = something; // maybe adds stuff to it
node.addCustomWidget(widget) // adds it to the node
return widget // and returns it.
}
}
},
+75 -50
View File
@@ -1,6 +1,6 @@
{
"last_node_id": 23,
"last_link_id": 47,
"last_link_id": 48,
"nodes": [
{
"id": 11,
@@ -94,7 +94,7 @@
"Node name for S&R": "KSampler"
},
"widgets_values": [
882790958612696,
1088992701378297,
"randomize",
4,
1.6,
@@ -110,10 +110,10 @@
-470,
840
],
"size": [
430.924072265625,
253.48239135742188
],
"size": {
"0": 430.924072265625,
"1": 253.48239135742188
},
"flags": {},
"order": 0,
"mode": 0,
@@ -212,7 +212,7 @@
"1": 58
},
"flags": {},
"order": 9,
"order": 8,
"mode": 0,
"inputs": [
{
@@ -271,45 +271,6 @@
"control_scribble-fp16.safetensors"
]
},
{
"id": 8,
"type": "CLIPTextEncode",
"pos": [
678,
-77
],
"size": {
"0": 400,
"1": 200
},
"flags": {},
"order": 5,
"mode": 0,
"inputs": [
{
"name": "clip",
"type": "CLIP",
"link": 32
}
],
"outputs": [
{
"name": "CONDITIONING",
"type": "CONDITIONING",
"links": [
39
],
"shape": 3,
"slot_index": 0
}
],
"properties": {
"Node name for S&R": "CLIPTextEncode"
},
"widgets_values": [
"superman,"
]
},
{
"id": 7,
"type": "CLIPTextEncode",
@@ -322,7 +283,7 @@
"1": 200
},
"flags": {},
"order": 6,
"order": 5,
"mode": 0,
"inputs": [
{
@@ -361,7 +322,7 @@
"1": 126
},
"flags": {},
"order": 7,
"order": 6,
"mode": 0,
"inputs": [
{
@@ -465,7 +426,7 @@
"1": 246
},
"flags": {},
"order": 8,
"order": 7,
"mode": 0,
"inputs": [
{
@@ -512,6 +473,53 @@
1
]
},
{
"id": 8,
"type": "CLIPTextEncode",
"pos": [
678,
-77
],
"size": [
400,
200
],
"flags": {},
"order": 9,
"mode": 0,
"inputs": [
{
"name": "clip",
"type": "CLIP",
"link": 32
},
{
"name": "text",
"type": "STRING",
"link": 48,
"widget": {
"name": "text"
}
}
],
"outputs": [
{
"name": "CONDITIONING",
"type": "CONDITIONING",
"links": [
39
],
"shape": 3,
"slot_index": 0
}
],
"properties": {
"Node name for S&R": "CLIPTextEncode"
},
"widgets_values": [
"superman,"
]
},
{
"id": 22,
"type": "LoadImagesFromPath",
@@ -521,7 +529,7 @@
],
"size": {
"0": 315,
"1": 202
"1": 238
},
"flags": {},
"order": 4,
@@ -542,6 +550,15 @@
"type": "MASK",
"links": null,
"shape": 6
},
{
"name": "STRING",
"type": "STRING",
"links": [
48
],
"shape": 3,
"slot_index": 2
}
],
"properties": {
@@ -813,6 +830,14 @@
18,
0,
"IMAGE"
],
[
48,
22,
2,
8,
1,
"STRING"
]
],
"groups": [