From 9ae8d30b6bf5b0620019a78aa4e70e43f06f1e73 Mon Sep 17 00:00:00 2001 From: shadowcz007 Date: Sun, 31 Dec 2023 21:23:26 +0800 Subject: [PATCH] llma --- __init__.py | 2 +- nodes/Lama.py | 15 ++++--- web/index.html | 5 --- web/javascript/ui_mixlab.js | 80 +++++++++++++++++++++++++++++++------ 4 files changed, 75 insertions(+), 27 deletions(-) diff --git a/__init__.py b/__init__.py index 6d90fc7..011a8ba 100644 --- a/__init__.py +++ b/__init__.py @@ -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"], diff --git a/nodes/Lama.py b/nodes/Lama.py index d914154..d2d680e 100644 --- a/nodes/Lama.py +++ b/nodes/Lama.py @@ -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): diff --git a/web/index.html b/web/index.html index 73bd959..e39ef52 100644 --- a/web/index.html +++ b/web/index.html @@ -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 } diff --git a/web/javascript/ui_mixlab.js b/web/javascript/ui_mixlab.js index df4873b..f0c08b1 100644 --- a/web/javascript/ui_mixlab.js +++ b/web/javascript/ui_mixlab.js @@ -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