-
-
Notifications
You must be signed in to change notification settings - Fork 400
Allow saving generated ControlNet previews #1364
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1125,7 +1125,7 @@ public static string ValidateParam(T2IParamType type, string val, Session sessio | |
|
|
||
| public static string FilePathToDataString(Session session, string filePath, string errorContext) | ||
| { | ||
| string root = WebServer.GetUserOutputRoot(session.User); | ||
| string root = Utilities.CombinePathWithAbsolute(Environment.CurrentDirectory, session.User.OutputDirectory); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Selecting from the "Select" modal would try to pull from the wrong location when generating workflow.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. very out of bounds for this PR, but valid fix for if you have
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. actually yeah no, i committed this fix separately |
||
| (string path, string consoleError, string userError) = WebServer.CheckFilePath(root, filePath); | ||
| if (consoleError is not null) | ||
| { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -814,7 +814,7 @@ function genInputs(delay_final = false) { | |
| let controlnetGroup = document.getElementById('input_group_content_controlnet'); | ||
| if (controlnetGroup) { | ||
| let firstGroup = controlnetGroup.querySelector('.input-group'); | ||
| let buttonDiv = createDiv(`controlnet_button_preview`, null, `<button class="basic-button" onclick="controlnetShowPreview()">Preview</button>`); | ||
| let buttonDiv = createDiv(`controlnet_button_preview`, null, `<button class="basic-button" onclick="controlnetShowPreview()">Preview</button> <button class="basic-button" onclick="controlnetSavePreviewToServer()">Save to Server</button>`); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This probably needs a disabled or a display:none? otherwise it's a very odd button with odd behavior. |
||
| if (firstGroup) { | ||
| controlnetGroup.insertBefore(buttonDiv, firstGroup); | ||
| } | ||
|
|
@@ -1452,7 +1452,7 @@ function debugShowHiddenParams() { | |
| } | ||
|
|
||
| /** Loads and shows a preview of ControlNet preprocessing to the user. */ | ||
| function controlnetShowPreview() { | ||
| function controlnetShowPreview(callback) { | ||
| let toggler = getRequiredElementById('input_group_content_controlnet_toggle'); | ||
| if (!toggler.checked) { | ||
| toggler.checked = true; | ||
|
|
@@ -1465,10 +1465,10 @@ function controlnetShowPreview() { | |
| } | ||
| let previewArea = getRequiredElementById('controlnet_button_preview'); | ||
| let clearPreview = () => { | ||
| let lastResult = previewArea.querySelector('.controlnet-preview-result'); | ||
| if (lastResult) { | ||
| lastResult.remove(); | ||
| for (let result of previewArea.querySelectorAll('.controlnet-preview-result, .controlnet-save-result')) { | ||
| result.remove(); | ||
| } | ||
| delete previewArea.dataset.controlnetPreviewImage; | ||
| }; | ||
| clearPreview(); | ||
| let imgInput = getRequiredElementById('input_controlnetimageinput'); | ||
|
|
@@ -1510,11 +1510,55 @@ function controlnetShowPreview() { | |
| resultBox.append(imgElem); | ||
| } | ||
| clearPreview(); | ||
| previewArea.dataset.controlnetPreviewImage = data.image; | ||
| previewArea.append(resultBox); | ||
| if (callback) { | ||
| callback(data); | ||
| } | ||
| }); | ||
| }); | ||
| } | ||
|
|
||
| /** Saves a ControlNet preview data URL through the existing history save route. */ | ||
| function controlnetSavePreviewDataToServer(image) { | ||
| let now = new Date(); | ||
| let pad = (val) => `${val}`.padStart(2, '0'); | ||
| let millis = `${now.getMilliseconds()}`.padStart(3, '0'); | ||
| let name = `controlnet-preview-${now.getFullYear()}-${pad(now.getMonth() + 1)}-${pad(now.getDate())}_${pad(now.getHours())}-${pad(now.getMinutes())}-${pad(now.getSeconds())}-${millis}`; | ||
| let data = { | ||
| image: image, | ||
| ['Override Outpath Format']: `inputs/controlnet/${name}` | ||
| }; | ||
| genericRequest('AddImageToHistory', data, res => { | ||
| let previewArea = getRequiredElementById('controlnet_button_preview'); | ||
| let oldSaveResult = previewArea.querySelector('.controlnet-save-result'); | ||
| if (oldSaveResult) { | ||
| oldSaveResult.remove(); | ||
| } | ||
| let saveResult = createDiv(null, 'controlnet-save-result modal_success_bottom', 'Saved ControlNet preview.'); | ||
| previewArea.append(saveResult); | ||
| setTimeout(() => { | ||
| saveResult.remove(); | ||
| }, 5000); | ||
| }); | ||
| } | ||
|
|
||
| /** Saves the current ControlNet preview, generating it first if needed. */ | ||
| function controlnetSavePreviewToServer() { | ||
| let previewArea = getRequiredElementById('controlnet_button_preview'); | ||
| let image = previewArea.dataset.controlnetPreviewImage; | ||
| if (image) { | ||
| controlnetSavePreviewDataToServer(image); | ||
| return; | ||
| } | ||
| controlnetShowPreview(data => { | ||
| if (!data || !data.image) { | ||
| return; | ||
| } | ||
| controlnetSavePreviewDataToServer(data.image); | ||
| }); | ||
| } | ||
|
|
||
| /** Gets the parameter with a given ID, from either the current param set, or the raw set from server. If unavailable, returns null. */ | ||
| function getParamById(id) { | ||
| if (!gen_param_types) { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.