Merge pull request #1328 from ogmaresca/negative-lora-strength

Allow LoRA strengths between -2 and 2
This commit is contained in:
cmdr2 2023-06-05 16:18:28 +05:30 committed by GitHub
commit f7c52b700e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 10 deletions

View File

@ -227,7 +227,7 @@
</td></tr> </td></tr>
<tr id="lora_alpha_container" class="pl-5"> <tr id="lora_alpha_container" class="pl-5">
<td><label for="lora_alpha_slider">LoRA Strength:</label></td> <td><label for="lora_alpha_slider">LoRA Strength:</label></td>
<td> <input id="lora_alpha_slider" name="lora_alpha_slider" class="editor-slider" value="50" type="range" min="0" max="100"> <input id="lora_alpha" name="lora_alpha" size="4" pattern="^[0-9\.]+$" onkeypress="preventNonNumericalInput(event)"><br/></td> <td> <input id="lora_alpha_slider" name="lora_alpha_slider" class="editor-slider" value="50" type="range" min="-200" max="200"> <input id="lora_alpha" name="lora_alpha" size="4" pattern="^-?[0-9]*\.?[0-9]*$" onkeypress="preventNonNumericalInput(event)"><br/></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="" />

View File

@ -1725,10 +1725,10 @@ function updateLoraAlpha() {
} }
function updateLoraAlphaSlider() { function updateLoraAlphaSlider() {
if (loraAlphaField.value < 0) { if (loraAlphaField.value < -2) {
loraAlphaField.value = 0 loraAlphaField.value = -2
} else if (loraAlphaField.value > 1) { } else if (loraAlphaField.value > 2) {
loraAlphaField.value = 1 loraAlphaField.value = 2
} }
loraAlphaSlider.value = loraAlphaField.value * 100 loraAlphaSlider.value = loraAlphaField.value * 100

View File

@ -402,12 +402,12 @@ function debounce(func, wait, immediate) {
function preventNonNumericalInput(e) { function preventNonNumericalInput(e) {
e = e || window.event e = e || window.event
let charCode = typeof e.which == "undefined" ? e.keyCode : e.which const charCode = typeof e.which == "undefined" ? e.keyCode : e.which
let charStr = String.fromCharCode(charCode) const charStr = String.fromCharCode(charCode)
let re = e.target.getAttribute("pattern") || "^[0-9]+$" const newInputValue = `${e.target.value}${charStr}`
re = new RegExp(re) const re = new RegExp(e.target.getAttribute("pattern") || "^[0-9]+$")
if (!charStr.match(re)) { if (!re.test(charStr) && !re.test(newInputValue)) {
e.preventDefault() e.preventDefault()
} }
} }