mirror of
https://github.com/easydiffusion/easydiffusion.git
synced 2024-11-29 03:33:20 +01:00
Don't include empty lora values in the metadata
This commit is contained in:
parent
e80db71d1c
commit
1190bedafd
@ -292,6 +292,10 @@ const TASK_MAPPING = {
|
|||||||
use_lora_model: {
|
use_lora_model: {
|
||||||
name: "LoRA model",
|
name: "LoRA model",
|
||||||
setUI: (use_lora_model) => {
|
setUI: (use_lora_model) => {
|
||||||
|
if (!use_lora_model) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
let modelPaths = []
|
let modelPaths = []
|
||||||
use_lora_model.forEach((m) => {
|
use_lora_model.forEach((m) => {
|
||||||
if (m.includes("models\\lora\\")) {
|
if (m.includes("models\\lora\\")) {
|
||||||
@ -329,6 +333,10 @@ const TASK_MAPPING = {
|
|||||||
lora_alpha: {
|
lora_alpha: {
|
||||||
name: "LoRA Strength",
|
name: "LoRA Strength",
|
||||||
setUI: (lora_alpha) => {
|
setUI: (lora_alpha) => {
|
||||||
|
if (!lora_alpha) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
loraModelField.modelWeights = lora_alpha
|
loraModelField.modelWeights = lora_alpha
|
||||||
},
|
},
|
||||||
readUI: () => {
|
readUI: () => {
|
||||||
|
@ -29,15 +29,7 @@ class MultiModelSelector {
|
|||||||
return this.root.parentNode
|
return this.root.parentNode
|
||||||
}
|
}
|
||||||
get value() {
|
get value() {
|
||||||
let modelNames = []
|
return { modelNames: this.modelNames, modelWeights: this.modelWeights }
|
||||||
let modelWeights = []
|
|
||||||
|
|
||||||
this.modelElements.forEach((e) => {
|
|
||||||
modelNames.push(e.name.value)
|
|
||||||
modelWeights.push(e.weight.value)
|
|
||||||
})
|
|
||||||
|
|
||||||
return { modelNames: modelNames, modelWeights: modelWeights }
|
|
||||||
}
|
}
|
||||||
set value(modelData) {
|
set value(modelData) {
|
||||||
if (typeof modelData !== "object") {
|
if (typeof modelData !== "object") {
|
||||||
@ -53,31 +45,13 @@ class MultiModelSelector {
|
|||||||
throw new Error("Need to pass an equal number of modelNames and modelWeights!")
|
throw new Error("Need to pass an equal number of modelNames and modelWeights!")
|
||||||
}
|
}
|
||||||
|
|
||||||
// expand or shrink entries
|
// update weight first, name second.
|
||||||
let currElements = this.modelElements
|
// for some unholy reason this order matters for dispatch chains
|
||||||
if (currElements.length < newModelNames.length) {
|
// the root of all this unholiness is because searchable-models automatically dispatches an update event
|
||||||
for (let i = currElements.length; i < newModelNames.length; i++) {
|
// as soon as the value is updated via JS, which is against the DOM pattern of not dispatching an event automatically
|
||||||
this.addModelEntry()
|
// unless the caller explicitly dispatches the event.
|
||||||
}
|
this.modelWeights = newModelWeights
|
||||||
} else {
|
this.modelNames = newModelNames
|
||||||
for (let i = newModelNames.length; i < currElements.length; i++) {
|
|
||||||
this.removeModelEntry()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// assign to the corresponding elements
|
|
||||||
currElements = this.modelElements
|
|
||||||
for (let i = 0; i < newModelNames.length; i++) {
|
|
||||||
let curr = currElements[i]
|
|
||||||
|
|
||||||
// update weight first, name second.
|
|
||||||
// for some unholy reason this order matters for dispatch chains
|
|
||||||
// the root of all this unholiness is because searchable-models automatically dispatches an update event
|
|
||||||
// as soon as the value is updated via JS, which is against the DOM pattern of not dispatching an event automatically
|
|
||||||
// unless the caller explicitly dispatches the event.
|
|
||||||
curr.weight.value = newModelWeights[i]
|
|
||||||
curr.name.value = newModelNames[i]
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
get disabled() {
|
get disabled() {
|
||||||
return false
|
return false
|
||||||
@ -85,12 +59,19 @@ class MultiModelSelector {
|
|||||||
set disabled(state) {
|
set disabled(state) {
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
get modelElements() {
|
getModelElements(ignoreEmpty = false) {
|
||||||
let entries = this.root.querySelectorAll(".model_entry")
|
let entries = this.root.querySelectorAll(".model_entry")
|
||||||
entries = [...entries]
|
entries = [...entries]
|
||||||
let elements = entries.map((e) => {
|
let elements = entries.map((e) => {
|
||||||
return { name: e.querySelector(".model_name").field, weight: e.querySelector(".model_weight") }
|
let modelName = e.querySelector(".model_name").field
|
||||||
|
let modelWeight = e.querySelector(".model_weight")
|
||||||
|
if (ignoreEmpty && modelName.value.trim() === "") {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
return { name: modelName, weight: modelWeight }
|
||||||
})
|
})
|
||||||
|
elements = elements.filter((e) => e !== null)
|
||||||
return elements
|
return elements
|
||||||
}
|
}
|
||||||
addEventListener(type, listener, options) {
|
addEventListener(type, listener, options) {
|
||||||
@ -213,18 +194,18 @@ class MultiModelSelector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get length() {
|
get length() {
|
||||||
return this.modelContainer.childElementCount
|
return this.getModelElements().length
|
||||||
}
|
}
|
||||||
|
|
||||||
get modelNames() {
|
get modelNames() {
|
||||||
return this.modelElements.map((e) => e.name.value)
|
return this.getModelElements(true).map((e) => e.name.value)
|
||||||
}
|
}
|
||||||
|
|
||||||
set modelNames(newModelNames) {
|
set modelNames(newModelNames) {
|
||||||
this.resizeEntryList(newModelNames.length)
|
this.resizeEntryList(newModelNames.length)
|
||||||
|
|
||||||
// assign to the corresponding elements
|
// assign to the corresponding elements
|
||||||
let currElements = this.modelElements
|
let currElements = this.getModelElements()
|
||||||
for (let i = 0; i < newModelNames.length; i++) {
|
for (let i = 0; i < newModelNames.length; i++) {
|
||||||
let curr = currElements[i]
|
let curr = currElements[i]
|
||||||
|
|
||||||
@ -233,14 +214,14 @@ class MultiModelSelector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get modelWeights() {
|
get modelWeights() {
|
||||||
return this.modelElements.map((e) => e.weight.value)
|
return this.getModelElements(true).map((e) => e.weight.value)
|
||||||
}
|
}
|
||||||
|
|
||||||
set modelWeights(newModelWeights) {
|
set modelWeights(newModelWeights) {
|
||||||
this.resizeEntryList(newModelWeights.length)
|
this.resizeEntryList(newModelWeights.length)
|
||||||
|
|
||||||
// assign to the corresponding elements
|
// assign to the corresponding elements
|
||||||
let currElements = this.modelElements
|
let currElements = this.getModelElements()
|
||||||
for (let i = 0; i < newModelWeights.length; i++) {
|
for (let i = 0; i < newModelWeights.length; i++) {
|
||||||
let curr = currElements[i]
|
let curr = currElements[i]
|
||||||
|
|
||||||
@ -249,6 +230,10 @@ class MultiModelSelector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
resizeEntryList(newLength) {
|
resizeEntryList(newLength) {
|
||||||
|
if (newLength === 0) {
|
||||||
|
newLength = 1
|
||||||
|
}
|
||||||
|
|
||||||
let currLength = this.length
|
let currLength = this.length
|
||||||
if (currLength < newLength) {
|
if (currLength < newLength) {
|
||||||
for (let i = currLength; i < newLength; i++) {
|
for (let i = currLength; i < newLength; i++) {
|
||||||
|
Loading…
Reference in New Issue
Block a user