add some hrfix compatibility with old version
Signed-off-by: Victor Seiji Hariki <victorseijih@gmail.com>
This commit is contained in:
parent
f3eaa84a76
commit
ad66f0ec29
4 changed files with 63 additions and 46 deletions
16
index.html
16
index.html
|
@ -100,11 +100,11 @@
|
|||
<input type="checkbox" id="cbxHRFix" onchange="changeHiResFix()" />
|
||||
<label for="cbxHRFix">Apply txt2img HRfix</label>
|
||||
<br />
|
||||
<div id="hrFixScale"></div>
|
||||
<div id="hrFixLockPx"></div>
|
||||
<label id="hrFixLabel">Choose HRfix upscaler</label>
|
||||
<div id="hrFixUpscaler"></div>
|
||||
<div id="hrDenoising"></div>
|
||||
<div id="hrFixScale" class="hrfix"></div>
|
||||
<div id="hrFixLockPx" class="hrfix"></div>
|
||||
<label id="hrFixLabel" class="hrfix">Choose HRfix upscaler</label>
|
||||
<div id="hrFixUpscaler" class="hrfix"></div>
|
||||
<div id="hrDenoising" class="hrfix"></div>
|
||||
<input
|
||||
type="checkbox"
|
||||
id="cbxRestoreFaces"
|
||||
|
@ -320,7 +320,7 @@
|
|||
</div>
|
||||
|
||||
<!-- Basics -->
|
||||
<script src="js/global.js?v=1807d6e" type="text/javascript"></script>
|
||||
<script src="js/global.js?v=3a1cde6" type="text/javascript"></script>
|
||||
|
||||
<!-- Base Libs -->
|
||||
<script src="js/lib/util.js?v=7f6847c" type="text/javascript"></script>
|
||||
|
@ -341,7 +341,7 @@
|
|||
|
||||
<!-- Content -->
|
||||
<script src="js/prompt.js?v=7a1c68c" type="text/javascript"></script>
|
||||
<script src="js/index.js?v=57dca90" type="text/javascript"></script>
|
||||
<script src="js/index.js?v=afc36b6" type="text/javascript"></script>
|
||||
|
||||
<script
|
||||
src="js/ui/floating/history.js?v=fc92d14"
|
||||
|
@ -355,7 +355,7 @@
|
|||
src="js/ui/tool/generic.js?v=2bcd36d"
|
||||
type="text/javascript"></script>
|
||||
|
||||
<script src="js/ui/tool/dream.js?v=51db348" type="text/javascript"></script>
|
||||
<script src="js/ui/tool/dream.js?v=e4e5883" type="text/javascript"></script>
|
||||
<script
|
||||
src="js/ui/tool/maskbrush.js?v=1e8a893"
|
||||
type="text/javascript"></script>
|
||||
|
|
|
@ -50,6 +50,9 @@ const global = {
|
|||
toggledebug() {
|
||||
this.debug = !this.debug;
|
||||
},
|
||||
|
||||
// HRFix compatibility shenanigans
|
||||
isOldHRFix: false,
|
||||
};
|
||||
|
||||
global._firstRun = !localStorage.getItem("openoutpaint/host");
|
||||
|
|
12
js/index.js
12
js/index.js
|
@ -345,12 +345,16 @@ async function testHostConnection() {
|
|||
);
|
||||
const optionsdata = await response.json();
|
||||
if (optionsdata["use_scale_latent_for_hires_fix"]) {
|
||||
const message = `You are using an outdated version of A1111 webUI.\nThe HRfix options will not work until you update to at least commit ef27a18 or newer.\n(https://github.com/AUTOMATIC1111/stable-diffusion-webui/commit/ef27a18b6b7cb1a8eebdc9b2e88d25baf2c2414d)\nHRfix options have been disabled.`;
|
||||
console.error(message);
|
||||
const message = `You are using an outdated version of A1111 webUI.\nThe HRfix options will not work until you update to at least commit ef27a18 or newer.\n(https://github.com/AUTOMATIC1111/stable-diffusion-webui/commit/ef27a18b6b7cb1a8eebdc9b2e88d25baf2c2414d)\nHRfix will fallback to half-resolution only.`;
|
||||
console.warn(message);
|
||||
if (notify) alert(message);
|
||||
// Hide all new hrfix options
|
||||
document
|
||||
.getElementById("cbxHRFix")
|
||||
.setAttribute("disabled", "disabled");
|
||||
.querySelectorAll(".hrfix")
|
||||
.forEach((el) => (el.style.display = "none"));
|
||||
|
||||
// We are using old HRFix
|
||||
global.isOldHRFix = true;
|
||||
stableDiffusionData.enable_hr = false;
|
||||
}
|
||||
switch (response.status) {
|
||||
|
|
|
@ -141,41 +141,7 @@ const _dream = async (endpoint, request) => {
|
|||
let data = null;
|
||||
try {
|
||||
generating(true);
|
||||
if (
|
||||
endpoint == "txt2img" &&
|
||||
request.enable_hr &&
|
||||
localStorage.getItem("openoutpaint/settings.hrfix-liar") == "true"
|
||||
) {
|
||||
/**
|
||||
* try and make the new HRfix method useful for our purposes
|
||||
* since it now returns an image that's been upscaled x the hr_scale parameter,
|
||||
* we cheekily lie to SD and tell it that the original dimensions are _divided_
|
||||
* by the scale factor so it returns something about the same size as we wanted initially
|
||||
*/
|
||||
|
||||
// ok so instead, only do that if stableDiffusionData.hr_fix_lock_px > 0
|
||||
if (stableDiffusionData.hr_fix_lock_px > 0) {
|
||||
// find the appropriate scale factor for hrfix
|
||||
var widthFactor =
|
||||
request.width / stableDiffusionData.hr_fix_lock_px <= 4
|
||||
? request.width / stableDiffusionData.hr_fix_lock_px
|
||||
: 4;
|
||||
var heightFactor =
|
||||
request.height / stableDiffusionData.hr_fix_lock_px <= 4
|
||||
? request.height / stableDiffusionData.hr_fix_lock_px
|
||||
: 4;
|
||||
var factor = heightFactor > widthFactor ? heightFactor : widthFactor;
|
||||
request.hr_scale = hrFixScaleSlider.value = factor < 1 ? 1 : factor;
|
||||
}
|
||||
|
||||
var newWidth = Math.floor(request.width / request.hr_scale);
|
||||
var newHeight = Math.floor(request.height / request.hr_scale);
|
||||
request.width = newWidth;
|
||||
request.height = newHeight;
|
||||
}
|
||||
if (endpoint == "txt2img") {
|
||||
request.denoising_strength = stableDiffusionData.hr_denoising_strength;
|
||||
}
|
||||
const response = await fetch(apiURL, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
|
@ -849,6 +815,50 @@ const dream_generate_callback = async (bb, resolution, state) => {
|
|||
|
||||
// Use txt2img if canvas is blank
|
||||
if (isCanvasBlank(0, 0, bb.w, bb.h, visibleCanvas)) {
|
||||
if (
|
||||
!global.isOldHRFix &&
|
||||
request.enable_hr &&
|
||||
localStorage.getItem("openoutpaint/settings.hrfix-liar") == "true"
|
||||
) {
|
||||
/**
|
||||
* try and make the new HRfix method useful for our purposes
|
||||
* since it now returns an image that's been upscaled x the hr_scale parameter,
|
||||
* we cheekily lie to SD and tell it that the original dimensions are _divided_
|
||||
* by the scale factor so it returns something about the same size as we wanted initially
|
||||
*/
|
||||
|
||||
// ok so instead, only do that if stableDiffusionData.hr_fix_lock_px > 0
|
||||
if (stableDiffusionData.hr_fix_lock_px > 0) {
|
||||
// find the appropriate scale factor for hrfix
|
||||
var widthFactor =
|
||||
request.width / stableDiffusionData.hr_fix_lock_px <= 4
|
||||
? request.width / stableDiffusionData.hr_fix_lock_px
|
||||
: 4;
|
||||
var heightFactor =
|
||||
request.height / stableDiffusionData.hr_fix_lock_px <= 4
|
||||
? request.height / stableDiffusionData.hr_fix_lock_px
|
||||
: 4;
|
||||
var factor = heightFactor > widthFactor ? heightFactor : widthFactor;
|
||||
request.hr_scale = hrFixScaleSlider.value = factor < 1 ? 1 : factor;
|
||||
}
|
||||
|
||||
var newWidth = Math.floor(request.width / request.hr_scale);
|
||||
var newHeight = Math.floor(request.height / request.hr_scale);
|
||||
request.width = newWidth;
|
||||
request.height = newHeight;
|
||||
}
|
||||
|
||||
// For compatibility with the old HRFix API
|
||||
if (global.isOldHRFix && request.enable_hr) {
|
||||
request.firstphase_width = request.width / 2;
|
||||
request.firstphase_height = request.height / 2;
|
||||
}
|
||||
|
||||
// Only set this if HRFix is enabled in the first place
|
||||
request.denoising_strength = request.enable_hr
|
||||
? stableDiffusionData.hr_denoising_strength
|
||||
: 1;
|
||||
|
||||
// Dream
|
||||
_generate("txt2img", request, bb);
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue