-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
poc of use js front end to get loras list #156
Merged
ccssu
merged 3 commits into
add_shared_lora_loader_node
from
support_get_loras_in_js_end
Sep 28, 2024
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { api } from "../../../scripts/api.js"; | ||
import { app } from "../../scripts/app.js"; | ||
app.registerExtension({ | ||
name: "bizyair.siliconcloud.share.lora.loader", | ||
async beforeRegisterNodeDef(nodeType, nodeData, app) { | ||
if (nodeData.name === "BizyAir_SharedLoraLoader") { | ||
async function onTextChange(share_id, canvas, comfynode) { | ||
if(share_id.length === 25 && share_id.startsWith("clx")){ | ||
const response = await api.fetchApi("/bizyair/shareloras", { | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
body: JSON.stringify({ share_id: share_id }), | ||
}); | ||
const loras_list = await response.json() | ||
const lora_name_widget = comfynode.widgets.find(widget => widget.name === "lora_name"); | ||
lora_name_widget.value = loras_list[0] | ||
lora_name_widget.options.values = loras_list | ||
} | ||
} | ||
|
||
function setWigetCallback(){ | ||
const shareid_widget = this.widgets.find(widget => widget.name === "share_id"); | ||
|
||
if (shareid_widget) { | ||
shareid_widget.callback = onTextChange; | ||
} else { | ||
console.log("share_id widget not found"); | ||
} | ||
|
||
} | ||
const onNodeCreated = nodeType.prototype.onNodeCreated | ||
nodeType.prototype.onNodeCreated = function () { | ||
onNodeCreated?.apply(this, arguments); | ||
setWigetCallback.call(this, arguments); | ||
}; | ||
} | ||
}, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -119,3 +119,23 @@ async def get_file_content(request): | |
status=500, | ||
content_type="application/json", | ||
) | ||
|
||
|
||
@PromptServer.instance.routes.post("/bizyair/shareloras") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这段添加后端的代码,是临时放在这的。请根据需要挪到合适的地方。 |
||
async def get_share_loras(request): | ||
try: | ||
data = await request.json() | ||
except json.JSONDecodeError: | ||
return web.Response( | ||
text=json.dumps({"error": "Invalid JSON body"}), | ||
status=400, | ||
content_type="application/json", | ||
) | ||
|
||
share_id = data.get("share_id") | ||
print(f"use {share_id} to get the loras_list...") | ||
loras_list = ["flux/lora1.safetensors", "flux/lora2.safetensors"] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这个 loras_list 应该来自网络请求。 loras_list 建议放上一个默认的美甲模型,使得 loras_list 的长度一定是 >=1 的,这样前端的逻辑就完全不用改了 |
||
return web.Response( | ||
text=json.dumps(loras_list, ensure_ascii=False), | ||
content_type="application/json", | ||
) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
前端的主要作用,是通过设置 shareid 那个文本框的回调,监控文本改变事件。
然后在文本改变的事件里,像后端发请求,得到 loras list