This commit is contained in:
shadowcz007
2023-12-31 21:23:26 +08:00
parent 44349c10b0
commit 9ae8d30b6b
4 changed files with 75 additions and 27 deletions
+1 -1
View File
@@ -221,7 +221,7 @@ def get_my_workflow_for_app(filename="my_workflow_app.json"):
for item in data:
x=item["data"]
print(apps[0]['filename'] ,item["filename"])
# print(apps[0]['filename'] ,item["filename"])
if apps[0]['filename']!=item["filename"]:
apps.append({
"filename":item["filename"],
+7 -8
View File
@@ -8,14 +8,13 @@ import numpy as np
import torch
os.environ['LAMA_MODEL'] = os.path.join(folder_paths.models_dir, "lama/big-lama.pt")
if os.environ.get("LAMA_MODEL"):
model_path=os.environ.get("LAMA_MODEL")
if not os.path.exists(model_path):
os.environ['LAMA_MODEL']=''
raise FileNotFoundError(
f"lama torchscript model not found: {model_path}"
)
llma_model_path=os.path.join(folder_paths.models_dir, "lama/big-lama.pt")
if not os.path.exists(llma_model_path):
os.environ['LAMA_MODEL']=''
print(f"lama torchscript model not found: {llma_model_path}")
else:
os.environ['LAMA_MODEL'] = llma_model_path
# Tensor to PIL
def tensor2pil(image):
-5
View File
@@ -389,9 +389,7 @@
}
async function get_my_app(filename = null) {
let url = get_url()
const res = await fetch(`${url}/mixlab/workflow`, {
method: 'POST',
body: JSON.stringify({
@@ -411,10 +409,7 @@
})
}
} catch (error) {
}
return data
}
+67 -13
View File
@@ -4,7 +4,6 @@ import { ComfyWidgets } from '../../../scripts/widgets.js'
import { $el } from '../../../scripts/ui.js'
import { closeIcon } from './svg_icons.js'
import {
GroupNodeConfig,
GroupNodeHandler
@@ -49,6 +48,38 @@ async function get_nodes_map () {
return await res.json()
}
function get_url () {
let api_host = `${window.location.hostname}:${window.location.port}`
let api_base = ''
let url = `${window.location.protocol}//${api_host}${api_base}`
return url
}
async function get_my_app (filename = null) {
let url = get_url()
const res = await fetch(`${url}/mixlab/workflow`, {
method: 'POST',
body: JSON.stringify({
task: 'my_app',
filename
})
})
let result = await res.json()
let data = []
try {
for (const res of result.data) {
let { app,workflow } = res.data
if (app.filename)
data.push({
...app,
data: workflow,
date: res.date
})
}
} catch (error) {}
return data
}
function loadCSS (url) {
var link = document.createElement('link')
link.rel = 'stylesheet'
@@ -668,29 +699,31 @@ app.registerExtension({
...options
] // and return the options
}
LGraphCanvas.prototype.centerOnNode = function(node) {
var dpr = window.devicePixelRatio || 1; // 获取设备像素比
LGraphCanvas.prototype.centerOnNode = function (node) {
var dpr = window.devicePixelRatio || 1 // 获取设备像素比
this.ds.offset[0] =
-node.pos[0] -
node.size[0] * 0.5 +
(this.canvas.width * 0.5) / (this.ds.scale * dpr); // 考虑设备像素比
-node.pos[0] -
node.size[0] * 0.5 +
(this.canvas.width * 0.5) / (this.ds.scale * dpr) // 考虑设备像素比
this.ds.offset[1] =
-node.pos[1] -
node.size[1] * 0.5 +
(this.canvas.height * 0.5) / (this.ds.scale * dpr); // 考虑设备像素比
this.setDirty(true, true);
};
-node.pos[1] -
node.size[1] * 0.5 +
(this.canvas.height * 0.5) / (this.ds.scale * dpr) // 考虑设备像素比
this.setDirty(true, true)
}
},
async setup () {
// Add canvas menu options
const orig = LGraphCanvas.prototype.getCanvasMenuOptions
const apps = await get_my_app()
// console.log('apps',apps)
LGraphCanvas.prototype.getCanvasMenuOptions = function () {
const options = orig.apply(this, arguments)
options.push(null, {
content: `Nodes Map ♾️Mixlab`,
disabled: false, // or a function determining whether to disable
disabled: false,
callback: async () => {
nodesMap =
nodesMap && Object.keys(nodesMap).length > 0
@@ -809,7 +842,7 @@ app.registerExtension({
let d = document.createElement('button')
d.style = `text-align: left;margin:6px;color: var(--input-text);
background-color: var(--comfy-input-bg); border-color: var(--border-color);cursor: pointer;`
d.addEventListener('click', () => {
d.addEventListener('click', () => {
const node = app.graph.getNodeById(nodeId)
if (!node) return
app.canvas.centerOnNode(node)
@@ -845,6 +878,27 @@ app.registerExtension({
}
})
options.push({
content: 'Workflow App ♾️Mixlab',
has_submenu: true,
submenu: {
options: Array.from(apps, a => {
return {
content: a.name,
callback: async () => {
try {
let item = (await get_my_app(a.filename))[0]
if (item) {
console.log(item.data)
app.loadGraphData(item.data)
}
} catch (error) {}
}
}
})
}
})
// options.push({
// content: `Save For App ♾️Mixlab`,
// disabled: false, // or a function determining whether to disable