Open chiragn888 opened 4 months ago
edb107ca0f
)[!TIP] I can email you next time I complete a pull request if you set up your email here!
Here are the GitHub Actions logs prior to making any changes:
ceb229d
Checking javascript/aspectRatioOverlay.js for syntax errors... ✅ javascript/aspectRatioOverlay.js has no syntax errors!
1/1 ✓Checking javascript/aspectRatioOverlay.js for syntax errors... ✅ javascript/aspectRatioOverlay.js has no syntax errors!
Sandbox passed on the latest main
, so sandbox checks will be enabled for this issue.
I found the following snippets in your repository. I will now analyze these snippets and come up with a plan.
extensions-builtin/extra-options-section/scripts/hires_fix.py
✓ https://github.com/chiragn888/Stable_difussion/commit/b749bca53efe6de59704829a94e071d7d71479b1 Edit
Create extensions-builtin/extra-options-section/scripts/hires_fix.py with contents:
• Create a new Python script named `hires_fix.py` in the `extensions-builtin/extra-options-section/scripts/` directory. This script will contain the logic for applying the "Hires fix" to img2img operations.
• Import necessary dependencies at the top of the file, such as TensorFlow or PyTorch, depending on the model's requirements.
• Define a function `apply_hires_fix` that takes parameters for the image input, denoise strength, and any other relevant parameters for the "Hires fix". This function will modify the image generation parameters to apply the "Hires fix".
• Ensure that this script can be imported and used by other parts of the application, particularly where img2img operations are handled.
extensions-builtin/extra-options-section/scripts/hires_fix.py
✓ Edit
Check extensions-builtin/extra-options-section/scripts/hires_fix.py with contents:
Ran GitHub Actions for b749bca53efe6de59704829a94e071d7d71479b1:
javascript/aspectRatioOverlay.js
✓ https://github.com/chiragn888/Stable_difussion/commit/f3d6221b5d9cc3d2e5da58ce640fb94bb16acdd7 Edit
Modify javascript/aspectRatioOverlay.js with contents:
• Add a new checkbox or toggle UI component within the img2img tab for enabling the "Hires fix". This will involve adding HTML for the checkbox and a label explaining its purpose.
• Within the `onAfterUiUpdate` function, add an event listener for the new "Hires fix" checkbox. When the checkbox is toggled, set a global or scoped variable to indicate whether the "Hires fix" should be applied.
• Modify the `dimensionChange` event listener function to check if the "Hires fix" is enabled. If so, pass the necessary parameters (e.g., denoise strength) to the backend when img2img operations are triggered.
• Ensure that the state of the "Hires fix" option is correctly managed between UI updates to preserve the user's selection.
--- +++ @@ -1,113 +1,137 @@ - -let currentWidth = null; -let currentHeight = null; -let arFrameTimeout = setTimeout(function() {}, 0); - -function dimensionChange(e, is_width, is_height) { - - if (is_width) { - currentWidth = e.target.value * 1.0; - } - if (is_height) { - currentHeight = e.target.value * 1.0; - } - - var inImg2img = gradioApp().querySelector("#tab_img2img").style.display == "block"; - - if (!inImg2img) { - return; - } - - var targetElement = null; - - var tabIndex = get_tab_index('mode_img2img'); - if (tabIndex == 0) { // img2img - targetElement = gradioApp().querySelector('#img2img_image div[data-testid=image] img'); - } else if (tabIndex == 1) { //Sketch - targetElement = gradioApp().querySelector('#img2img_sketch div[data-testid=image] img'); - } else if (tabIndex == 2) { // Inpaint - targetElement = gradioApp().querySelector('#img2maskimg div[data-testid=image] img'); - } else if (tabIndex == 3) { // Inpaint sketch - targetElement = gradioApp().querySelector('#inpaint_sketch div[data-testid=image] img'); - } - - - if (targetElement) { - - var arPreviewRect = gradioApp().querySelector('#imageARPreview'); - if (!arPreviewRect) { - arPreviewRect = document.createElement('div'); - arPreviewRect.id = "imageARPreview"; - gradioApp().appendChild(arPreviewRect); - } - - - - var viewportOffset = targetElement.getBoundingClientRect(); - - var viewportscale = Math.min(targetElement.clientWidth / targetElement.naturalWidth, targetElement.clientHeight / targetElement.naturalHeight); - - var scaledx = targetElement.naturalWidth * viewportscale; - var scaledy = targetElement.naturalHeight * viewportscale; - - var cleintRectTop = (viewportOffset.top + window.scrollY); - var cleintRectLeft = (viewportOffset.left + window.scrollX); - var cleintRectCentreY = cleintRectTop + (targetElement.clientHeight / 2); - var cleintRectCentreX = cleintRectLeft + (targetElement.clientWidth / 2); - - var arscale = Math.min(scaledx / currentWidth, scaledy / currentHeight); - var arscaledx = currentWidth * arscale; - var arscaledy = currentHeight * arscale; - - var arRectTop = cleintRectCentreY - (arscaledy / 2); - var arRectLeft = cleintRectCentreX - (arscaledx / 2); - var arRectWidth = arscaledx; - var arRectHeight = arscaledy; - - arPreviewRect.style.top = arRectTop + 'px'; - arPreviewRect.style.left = arRectLeft + 'px'; - arPreviewRect.style.width = arRectWidth + 'px'; - arPreviewRect.style.height = arRectHeight + 'px'; - - clearTimeout(arFrameTimeout); - arFrameTimeout = setTimeout(function() { - arPreviewRect.style.display = 'none'; - }, 2000); - - arPreviewRect.style.display = 'block'; - - } - -} - - -onAfterUiUpdate(function() { - var arPreviewRect = gradioApp().querySelector('#imageARPreview'); - if (arPreviewRect) { - arPreviewRect.style.display = 'none'; - } - var tabImg2img = gradioApp().querySelector("#tab_img2img"); - if (tabImg2img) { - var inImg2img = tabImg2img.style.display == "block"; - if (inImg2img) { - let inputs = gradioApp().querySelectorAll('input'); - inputs.forEach(function(e) { - var is_width = e.parentElement.id == "img2img_width"; - var is_height = e.parentElement.id == "img2img_height"; - - if ((is_width || is_height) && !e.classList.contains('scrollwatch')) { - e.addEventListener('input', function(e) { - dimensionChange(e, is_width, is_height); - }); - e.classList.add('scrollwatch'); - } - if (is_width) { - currentWidth = e.value * 1.0; - } - if (is_height) { - currentHeight = e.value * 1.0; - } - }); - } - } -}); + +let currentWidth = null; +let currentHeight = null; +let arFrameTimeout = setTimeout(function() {}, 0); + +function dimensionChange(e, is_width, is_height) { + + if (is_width) { + currentWidth = e.target.value * 1.0; + } + if (is_height) { + currentHeight = e.target.value * 1.0; + } + + var inImg2img = gradioApp().querySelector("#tab_img2img").style.display == "block" && window.hiresFixEnabled; + + if (!inImg2img) { + return; + } + + var targetElement = null; + + var tabIndex = get_tab_index('mode_img2img'); + if (tabIndex == 0) { // img2img + targetElement = gradioApp().querySelector('#img2img_image div[data-testid=image] img'); + } else if (tabIndex == 1) { //Sketch + targetElement = gradioApp().querySelector('#img2img_sketch div[data-testid=image] img'); + } else if (tabIndex == 2) { // Inpaint + targetElement = gradioApp().querySelector('#img2maskimg div[data-testid=image] img'); + } else if (tabIndex == 3) { // Inpaint sketch + targetElement = gradioApp().querySelector('#inpaint_sketch div[data-testid=image] img'); + } + + + if (targetElement) { + + var arPreviewRect = gradioApp().querySelector('#imageARPreview'); + if (!arPreviewRect) { + arPreviewRect = document.createElement('div'); + arPreviewRect.id = "imageARPreview"; + gradioApp().appendChild(arPreviewRect); + } + + + // Add Hires fix checkbox + var hiresFixContainer = document.createElement('div'); + hiresFixContainer.id = "hiresFixContainer"; + var hiresFixCheckbox = document.createElement('input'); + hiresFixCheckbox.type = "checkbox"; + hiresFixCheckbox.id = "hiresFixCheckbox"; + var hiresFixLabel = document.createElement('label'); + hiresFixLabel.htmlFor = "hiresFixCheckbox"; + hiresFixLabel.innerText = "Enable Hires fix"; + hiresFixContainer.appendChild(hiresFixCheckbox); + hiresFixContainer.appendChild(hiresFixLabel); + gradioApp().querySelector("#tab_img2img").appendChild(hiresFixContainer); + + var viewportOffset = targetElement.getBoundingClientRect(); + + var viewportscale = Math.min(targetElement.clientWidth / targetElement.naturalWidth, targetElement.clientHeight / targetElement.naturalHeight); + + var scaledx = targetElement.naturalWidth * viewportscale; + var scaledy = targetElement.naturalHeight * viewportscale; + + var cleintRectTop = (viewportOffset.top + window.scrollY); + var cleintRectLeft = (viewportOffset.left + window.scrollX); + var cleintRectCentreY = cleintRectTop + (targetElement.clientHeight / 2); + var cleintRectCentreX = cleintRectLeft + (targetElement.clientWidth / 2); + + var arscale = Math.min(scaledx / currentWidth, scaledy / currentHeight); + var arscaledx = currentWidth * arscale; + var arscaledy = currentHeight * arscale; + + var arRectTop = cleintRectCentreY - (arscaledy / 2); + var arRectLeft = cleintRectCentreX - (arscaledx / 2); + var arRectWidth = arscaledx; + var arRectHeight = arscaledy; + + arPreviewRect.style.top = arRectTop + 'px'; + arPreviewRect.style.left = arRectLeft + 'px'; + arPreviewRect.style.width = arRectWidth + 'px'; + arPreviewRect.style.height = arRectHeight + 'px'; + + clearTimeout(arFrameTimeout); + arFrameTimeout = setTimeout(function() { + arPreviewRect.style.display = 'none'; + }, 2000); + + arPreviewRect.style.display = 'block'; + + } + +} + + +onAfterUiUpdate(function() { + var arPreviewRect = gradioApp().querySelector('#imageARPreview'); + if (arPreviewRect) { + arPreviewRect.style.display = 'none'; + } + var tabImg2img = gradioApp().querySelector("#tab_img2img"); + if (tabImg2img) { + // Event listener for Hires fix checkbox + var hiresFixCheckbox = gradioApp().querySelector("#hiresFixCheckbox"); + if (hiresFixCheckbox) { + hiresFixCheckbox.addEventListener('change', function() { + window.hiresFixEnabled = hiresFixCheckbox.checked; + }); + } + var inImg2img = tabImg2img.style.display == "block"; + if (inImg2img) { + let inputs = gradioApp().querySelectorAll('input'); + inputs.forEach(function(e) { + var is_width = e.parentElement.id == "img2img_width"; + var is_height = e.parentElement.id == "img2img_height"; + + if ((is_width || is_height) && !e.classList.contains('scrollwatch')) { + e.addEventListener('input', function(e) { + dimensionChange(e, is_width, is_height); + }); + e.classList.add('scrollwatch'); + } + if (is_width) { + currentWidth = e.value * 1.0; + } + if (is_height) { + currentHeight = e.value * 1.0; + } + }); + } + } +}); + // Restore Hires fix checkbox state + var hiresFixCheckbox = gradioApp().querySelector("#hiresFixCheckbox"); + if (hiresFixCheckbox) { + hiresFixCheckbox.checked = window.hiresFixEnabled || false; + }
javascript/aspectRatioOverlay.js
✓ Edit
Check javascript/aspectRatioOverlay.js with contents:
Ran GitHub Actions for f3d6221b5d9cc3d2e5da58ce640fb94bb16acdd7:
I have finished reviewing the code for completeness. I did not find errors for sweep/hiresfix_for_img2img
.
💡 To recreate the pull request edit the issue title or description. To tweak the pull request, leave a comment on the pull request.Something wrong? Let us know.
This is an automated message generated by Sweep AI.
Add Hires. fix option into img2img tab. Useful for generating images with high denoise straight. E.g. photo -> painting
Checklist
- [X] Create `extensions-builtin/extra-options-section/scripts/hires_fix.py` ✓ https://github.com/chiragn888/Stable_difussion/commit/b749bca53efe6de59704829a94e071d7d71479b1 [Edit](https://github.com/chiragn888/Stable_difussion/edit/sweep/hiresfix_for_img2img/extensions-builtin/extra-options-section/scripts/hires_fix.py) - [X] Running GitHub Actions for `extensions-builtin/extra-options-section/scripts/hires_fix.py` ✓ [Edit](https://github.com/chiragn888/Stable_difussion/edit/sweep/hiresfix_for_img2img/extensions-builtin/extra-options-section/scripts/hires_fix.py) - [X] Modify `javascript/aspectRatioOverlay.js` ✓ https://github.com/chiragn888/Stable_difussion/commit/f3d6221b5d9cc3d2e5da58ce640fb94bb16acdd7 [Edit](https://github.com/chiragn888/Stable_difussion/edit/sweep/hiresfix_for_img2img/javascript/aspectRatioOverlay.js#L69-L113) - [X] Running GitHub Actions for `javascript/aspectRatioOverlay.js` ✓ [Edit](https://github.com/chiragn888/Stable_difussion/edit/sweep/hiresfix_for_img2img/javascript/aspectRatioOverlay.js#L69-L113)