mirror of
https://github.com/easydiffusion/easydiffusion.git
synced 2025-04-10 19:18:18 +02:00
Add and remove buttons for arbitrary number of LoRA models
This commit is contained in:
parent
6f065918e9
commit
ef1e42dd7b
@ -232,7 +232,10 @@
|
|||||||
<td>
|
<td>
|
||||||
<label for="lora_model">LoRA:</label>
|
<label for="lora_model">LoRA:</label>
|
||||||
</td>
|
</td>
|
||||||
<td class="model_entries"></td>
|
<td>
|
||||||
|
<div class="model_entries"></div>
|
||||||
|
<button class="add_model_entry"><i class="fa-solid fa-plus"></i> add another LoRA</button>
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr class="pl-5"><td><label for="hypernetwork_model">Hypernetwork:</label></td><td>
|
<tr class="pl-5"><td><label for="hypernetwork_model">Hypernetwork:</label></td><td>
|
||||||
<input id="hypernetwork_model" type="text" spellcheck="false" autocomplete="off" class="model-filter" data-path="" />
|
<input id="hypernetwork_model" type="text" spellcheck="false" autocomplete="off" class="model-filter" data-path="" />
|
||||||
|
@ -906,6 +906,10 @@ div.img-preview img {
|
|||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#editor-settings-entries table {
|
||||||
|
width: 93%;
|
||||||
|
}
|
||||||
|
|
||||||
#negative_prompt {
|
#negative_prompt {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
@ -1680,5 +1684,5 @@ body.wait-pause {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.model_entry .model_name {
|
.model_entry .model_name {
|
||||||
width: 70%;
|
width: 65%;
|
||||||
}
|
}
|
@ -16,9 +16,6 @@ const SETTINGS_IDS_LIST = [
|
|||||||
"clip_skip",
|
"clip_skip",
|
||||||
"vae_model",
|
"vae_model",
|
||||||
"hypernetwork_model",
|
"hypernetwork_model",
|
||||||
"lora_model_0",
|
|
||||||
"lora_model_1",
|
|
||||||
"lora_model_2",
|
|
||||||
"sampler_name",
|
"sampler_name",
|
||||||
"width",
|
"width",
|
||||||
"height",
|
"height",
|
||||||
@ -26,9 +23,6 @@ const SETTINGS_IDS_LIST = [
|
|||||||
"guidance_scale",
|
"guidance_scale",
|
||||||
"prompt_strength",
|
"prompt_strength",
|
||||||
"hypernetwork_strength",
|
"hypernetwork_strength",
|
||||||
"lora_alpha_0",
|
|
||||||
"lora_alpha_1",
|
|
||||||
"lora_alpha_2",
|
|
||||||
"tiling",
|
"tiling",
|
||||||
"output_format",
|
"output_format",
|
||||||
"output_quality",
|
"output_quality",
|
||||||
|
@ -292,6 +292,11 @@ const TASK_MAPPING = {
|
|||||||
use_lora_model: {
|
use_lora_model: {
|
||||||
name: "LoRA model",
|
name: "LoRA model",
|
||||||
setUI: (use_lora_model) => {
|
setUI: (use_lora_model) => {
|
||||||
|
// create rows
|
||||||
|
for (let i = loraModels.length; i < use_lora_model.length; i++) {
|
||||||
|
createLoraEntry()
|
||||||
|
}
|
||||||
|
|
||||||
use_lora_model.forEach((model_name, i) => {
|
use_lora_model.forEach((model_name, i) => {
|
||||||
let field = loraModels[i][0]
|
let field = loraModels[i][0]
|
||||||
const oldVal = field.value
|
const oldVal = field.value
|
||||||
@ -304,9 +309,13 @@ const TASK_MAPPING = {
|
|||||||
})
|
})
|
||||||
|
|
||||||
// clear the remaining entries
|
// clear the remaining entries
|
||||||
|
let container = document.querySelector("#lora_model_container .model_entries")
|
||||||
for (let i = use_lora_model.length; i < loraModels.length; i++) {
|
for (let i = use_lora_model.length; i < loraModels.length; i++) {
|
||||||
loraModels[i][0].value = ""
|
let modelEntry = loraModels[i][2]
|
||||||
|
container.removeChild(modelEntry)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
loraModels.splice(use_lora_model.length)
|
||||||
},
|
},
|
||||||
readUI: () => {
|
readUI: () => {
|
||||||
let values = loraModels.map((e) => e[0].value)
|
let values = loraModels.map((e) => e[0].value)
|
||||||
@ -323,15 +332,23 @@ const TASK_MAPPING = {
|
|||||||
lora_alpha: {
|
lora_alpha: {
|
||||||
name: "LoRA Strength",
|
name: "LoRA Strength",
|
||||||
setUI: (lora_alpha) => {
|
setUI: (lora_alpha) => {
|
||||||
|
for (let i = loraModels.length; i < lora_alpha.length; i++) {
|
||||||
|
createLoraEntry()
|
||||||
|
}
|
||||||
|
|
||||||
lora_alpha.forEach((model_strength, i) => {
|
lora_alpha.forEach((model_strength, i) => {
|
||||||
let field = loraModels[i][1]
|
let field = loraModels[i][1]
|
||||||
field.value = model_strength
|
field.value = model_strength
|
||||||
})
|
})
|
||||||
|
|
||||||
// clear the remaining entries
|
// clear the remaining entries
|
||||||
|
let container = document.querySelector("#lora_model_container .model_entries")
|
||||||
for (let i = lora_alpha.length; i < loraModels.length; i++) {
|
for (let i = lora_alpha.length; i < loraModels.length; i++) {
|
||||||
loraModels[i][1].value = 0
|
let modelEntry = loraModels[i][2]
|
||||||
|
container.removeChild(modelEntry)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
loraModels.splice(lora_alpha.length)
|
||||||
},
|
},
|
||||||
readUI: () => {
|
readUI: () => {
|
||||||
let models = loraModels.filter((e) => e[0].value.trim() !== "")
|
let models = loraModels.filter((e) => e[0].value.trim() !== "")
|
||||||
|
@ -2242,31 +2242,59 @@ promptField.focus()
|
|||||||
promptField.selectionStart = promptField.value.length
|
promptField.selectionStart = promptField.value.length
|
||||||
|
|
||||||
// multi-models
|
// multi-models
|
||||||
function addModelEntry(i, modelContainer, modelsList, modelType, defaultValue, strengthStep) {
|
let modelCount = 0
|
||||||
let nameId = modelType + "_model_" + i
|
|
||||||
let strengthId = modelType + "_alpha_" + i
|
|
||||||
|
|
||||||
const modelEntry = document.createElement("div")
|
function addModelEntry(modelContainer, modelsList, modelType, defaultValue, strengthStep) {
|
||||||
modelEntry.className = "model_entry"
|
let idx = modelCount++
|
||||||
modelEntry.innerHTML = `
|
let nameId = modelType + "_model_" + idx
|
||||||
|
let strengthId = modelType + "_alpha_" + idx
|
||||||
|
|
||||||
|
const modelElement = document.createElement("div")
|
||||||
|
modelElement.className = "model_entry"
|
||||||
|
modelElement.innerHTML = `
|
||||||
<input id="${nameId}" class="model_name" type="text" spellcheck="false" autocomplete="off" class="model-filter" data-path="" />
|
<input id="${nameId}" class="model_name" type="text" spellcheck="false" autocomplete="off" class="model-filter" data-path="" />
|
||||||
<input id="${strengthId}" class="model_strength" type="number" step="${strengthStep}" style="width: 50pt" value="${defaultValue}" pattern="^-?[0-9]*\.?[0-9]*$" onkeypress="preventNonNumericalInput(event)"><br/>
|
<input id="${strengthId}" class="model_strength" type="number" step="${strengthStep}" style="width: 50pt" value="${defaultValue}" pattern="^-?[0-9]*\.?[0-9]*$" onkeypress="preventNonNumericalInput(event)">
|
||||||
`
|
`
|
||||||
|
modelContainer.appendChild(modelElement)
|
||||||
|
|
||||||
let modelName = new ModelDropdown(modelEntry.querySelector(".model_name"), modelType, "None")
|
let modelName = new ModelDropdown(modelElement.querySelector(".model_name"), modelType, "None")
|
||||||
let modelStrength = modelEntry.querySelector(".model_strength")
|
let modelStrength = modelElement.querySelector(".model_strength")
|
||||||
|
let entry = [modelName, modelStrength, modelElement]
|
||||||
|
|
||||||
modelContainer.appendChild(modelEntry)
|
let removeBtn = document.createElement("button")
|
||||||
modelsList.push([modelName, modelStrength])
|
removeBtn.innerHTML = '<i class="fa-solid fa-minus"></i>'
|
||||||
}
|
|
||||||
|
|
||||||
function createLoRAEntries() {
|
if (modelsList.length === 0) {
|
||||||
let container = document.querySelector("#lora_model_container .model_entries")
|
removeBtn.classList.add("displayNone")
|
||||||
for (let i = 0; i < 3; i++) {
|
|
||||||
addModelEntry(i, container, loraModels, "lora", 0.5, 0.02)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
removeBtn.addEventListener("click", function() {
|
||||||
|
let entryIdx = modelsList.indexOf(entry)
|
||||||
|
modelsList.splice(entryIdx, 1)
|
||||||
|
modelContainer.removeChild(modelElement)
|
||||||
|
})
|
||||||
|
|
||||||
|
modelElement.appendChild(removeBtn)
|
||||||
|
|
||||||
|
modelsList.push(entry)
|
||||||
|
|
||||||
|
return modelElement
|
||||||
}
|
}
|
||||||
createLoRAEntries()
|
|
||||||
|
function createLoraEntry() {
|
||||||
|
let container = document.querySelector("#lora_model_container .model_entries")
|
||||||
|
return addModelEntry(container, loraModels, "lora", 0.5, 0.02)
|
||||||
|
}
|
||||||
|
|
||||||
|
function createLoraEntries() {
|
||||||
|
let firstEntry = createLoraEntry()
|
||||||
|
|
||||||
|
let addLoraBtn = document.querySelector("#lora_model_container .add_model_entry")
|
||||||
|
addLoraBtn.addEventListener("click", () => {
|
||||||
|
createLoraEntry()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
createLoraEntries()
|
||||||
|
|
||||||
// chrome-like spinners only on hover
|
// chrome-like spinners only on hover
|
||||||
// function showSpinnerOnlyOnHover(e) {
|
// function showSpinnerOnlyOnHover(e) {
|
||||||
|
Loading…
Reference in New Issue
Block a user