Image Captioning, New API UI with UTM referral, Default 90s timeout + Dynamic timeout, Enhanced Prompt Weighting for txt2img and PhotoMaker, Changed Model Sorting

This commit is contained in:
Jack
2024-12-16 21:09:09 +02:00
parent 6d9fc4bbfd
commit 6bf9d37204
9 changed files with 155 additions and 28 deletions
+7 -1
View File
@@ -1,12 +1,13 @@
import { app } from "../../scripts/app.js";
import { api } from "../../scripts/api.js";
import { promptEnhanceHandler, syncDimensionsNodeHandler, searchNodeHandler, APIKeyHandler, handleCustomErrors } from "./utils.js";
import { promptEnhanceHandler, syncDimensionsNodeHandler, searchNodeHandler, APIKeyHandler, captionNodeHandler, handleCustomErrors } from "./utils.js";
import { RUNWARE_NODE_TYPES, RUNWARE_NODE_PROPS, SEARCH_TERMS } from "./types.js";
app.registerExtension({
name: "runware.ai",
async setup() {
api.addEventListener('runwareError', handleCustomErrors);
api.addEventListener('runwareImageCaption', captionNodeHandler);
},
async nodeCreated(node) {
@@ -21,6 +22,11 @@ app.registerExtension({
node.bgcolor = crNodeProps.bgColor;
if(nodeClass === RUNWARE_NODE_TYPES.APIMANAGER) {
APIKeyHandler(node);
} else if(nodeClass === RUNWARE_NODE_TYPES.IMAGECAPTION) {
const captionInput = node.widgets[1].inputEl;
captionInput.style.outline = "none";
captionInput.readOnly = true;
return;
}
if(crNodeProps.colorModeOnly === true) return;
+46 -1
View File
@@ -5,6 +5,7 @@ import { DEFAULT_DIMENSIONS_LIST, DEFAULT_MODELS_ARCH_LIST, DEFAULT_CONTROLNET_C
} from "./types.js";
let openDialog = false;
let lastTimeout = false;
async function enhancePrompt(userPrompt) {
const resp = await api.fetchApi('/promptEnhance', {
@@ -30,6 +31,18 @@ async function setAPIKey(apiKey) {
return setAPIKeyResults;
}
async function setTimeout(maxTimeout) {
const resp = await api.fetchApi('/setMaxTimeout', {
method: "POST",
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
maxTimeout: maxTimeout
})
});
const setTimeoutResults = await resp.json();
return setTimeoutResults;
}
async function modelSearch(modelQuery = "", modelArch = "all", modelType = "base", modelCat = "checkpoint", condtioning = "") {
const resp = await api.fetchApi('/modelSearch', {
method: "POST",
@@ -46,6 +59,20 @@ async function modelSearch(modelQuery = "", modelArch = "all", modelType = "base
return modelSearchResults;
}
function captionNodeHandler(msgEvent) {
const captionData = msgEvent.detail;
const captionText = captionData.captionText;
const captionNodeID = parseInt(captionData.nodeID);
if(captionData.success) {
const captionNode = app.graph.getNodeById(captionNodeID);
if(captionNode !== null || captionNode !== undefined) {
const captionInput = captionNode.widgets[1].inputEl;
captionInput.value = captionText;
}
}
return false;
}
function notifyUser(message, type="info", title = "Runware", life = 4.5) {
app.extensionManager.toast.add({
severity: type, // 'info', 'success', 'warn', 'error' \\
@@ -99,7 +126,24 @@ async function APIKeyHandler(apiManagerNode) {
}
}
});
break;
} else if(widget.name === "Max Timeout") {
if(lastTimeout) widget.value = lastTimeout;
appendWidgetCB(widget, async function(...args) {
const maxTimeout = args[0];
if(maxTimeout < 5 || maxTimeout > 99) {
notifyUser("Invalid Timeout Value, Timeout must be between 5 and 99 seconds!", "error", "Runware API Manager");
return;
} else {
const setTimeoutResults = await setTimeout(maxTimeout);
if(setTimeoutResults.success) {
remNode(apiManagerNode);
notifyUser("Timeout Set Successfully!", "success", "Runware API Manager");
lastTimeout = maxTimeout;
} else {
notifyUser(setTimeoutResults.error, "error", "Runware API Manager");
}
}
});
}
}
}
@@ -319,6 +363,7 @@ export {
promptEnhanceHandler,
syncDimensionsNodeHandler,
searchNodeHandler,
captionNodeHandler,
handleCustomErrors,
APIKeyHandler
};