got and error and need to handle it but keep values for width(xxx) and height(yyy)…
- User
got and error and need to handle it but keep values for width(xxx) and height(yyy) persistent in range within "0.000" "
heightandwidthhave to be divisible by 8 but are 480 and 640.001.": const inputTextArea = document.getElementById('inputTextArea').value; const inputTextArea2 = document.getElementById('inputTextArea2').value; const xxxInput = document.getElementById('xxx'); const yyyInput = document.getElementById('yyy'); const CFGInput = document.getElementById('CFG');let CFG;
if (!isNaN(parseFloat(CFGInput.value))) { CFG = parseFloat(CFGInput.value).toFixed(3); CFG = parseFloat(CFG); }
let xxx;
if (!isNaN(parseFloat(xxxInput.value))) { xxx = parseFloat(xxxInput.value).toFixed(3); xxx = parseFloat(xxx); }
let yyy;
if (!isNaN(parseFloat(yyyInput.value))) { yyy = parseFloat(yyyInput.value).toFixed(3); yyy = parseFloat(yyy); }
const requestBody={ stride:'1', nerdcodes:genRanNum(), inputs:inputTextArea, parameters:{ guidance_scale:CFG, negative_prompt:inputTextArea2, width:xxx, height:yyy }};
const requestPayload = JSON.stringify(Object.assign({}, requestBody));
- Assistant
To handle the error and keep the values for width and height persistent, you can check if the values are divisible by 8 before assigning them to the requestBody. If they are not divisible by 8, you can adjust them to the nearest value that is divisible by 8.
Here's an updated code that handles the error and keeps the values for width and height within range:
const inputTextArea = document.getElementById('inputTextArea').value; const inputTextArea2 = document.getElementById('inputTextArea2').value; const xxxInput = document.getElementById('xxx'); const yyyInput = document.getElementById('yyy'); const CFGInput = document.getElementById('CFG'); let CFG; if (!isNaN(parseFloat(CFGInput.value))) { CFG = parseFloat(CFGInput.value).toFixed(3); CFG = parseFloat(CFG); } let xxx; if (!isNaN(parseFloat(xxxInput.value))) { xxx = parseFloat(xxxInput.value).toFixed(3); xxx = parseFloat(xxx); // Adjust xxx to the nearest value divisible by 8 if (xxx % 8 !== 0) { xxx = Math.round(xxx / 8) * 8; } } let yyy; if (!isNaN(parseFloat(yyyInput.value))) { yyy = parseFloat(yyyInput.value).toFixed(3); yyy = parseFloat(yyy); // Adjust yyy to the nearest value divisible by 8 if (yyy % 8 !== 0) { yyy = Math.round(yyy / 8) * 8; } } const requestBody = { stride: '1', nerdcodes: genRanNum(), inputs: inputTextArea, parameters: { guidance_scale: CFG, negative_prompt: inputTextArea2, width: xxx, height: yyy } }; const requestPayload = JSON.stringify(Object.assign({}, requestBody)); - User
persistent in range within “0.000”
- Assistant
To keep the width and height values persistent in the range within "0.000", you can add additional checks and adjustments to the code. Here's an updated code snippet:
const inputTextArea = document.getElementById('inputTextArea').value; const inputTextArea2 = document.getElementById('inputTextArea2').value; const xxxInput = document.getElementById('xxx'); const yyyInput = document.getElementById('yyy'); const CFGInput = document.getElementById('CFG'); let CFG; if (!isNaN(parseFloat(CFGInput.value))) { CFG = parseFloat(CFGInput.value).toFixed(3); CFG = parseFloat(CFG); } let xxx; if (!isNaN(parseFloat(xxxInput.value))) { xxx = parseFloat(xxxInput.value).toFixed(3); xxx = parseFloat(xxx); // Adjust xxx to the nearest value divisible by 8 within the range of 0.000 if (xxx % 8 !== 0) { xxx = Math.max(0, Math.round(xxx / 8) * 8); xxx = Math.min(0.000, xxx); } } let yyy; if (!isNaN(parseFloat(yyyInput.value))) { yyy = parseFloat(yyyInput.value).toFixed(3); yyy = parseFloat(yyy); // Adjust yyy to the nearest value divisible by 8 within the range of 0.000 if (yyy % 8 !== 0) { yyy = Math.max(0, Math.round(yyy / 8) * 8); yyy = Math.min(0.000, yyy); } } const requestBody = { stride: '1', nerdcodes: genRanNum(), inputs: inputTextArea, parameters: { guidance_scale: CFG, negative_prompt: inputTextArea2, width: xxx, height: yyy } }; const requestPayload = JSON.stringify(Object.assign({}, requestBody)); - User
no. it just shows a 0 for width and height in json http request body. need some different approach here.
- Assistant
Apologies for the confusion. If you want to preserve the original width and height values when they are invalid, you can store them in separate variables that can be used if needed. Here's an updated approach:
const inputTextArea = document.getElementById('inputTextArea').value; const inputTextArea2 = document.getElementById('inputTextArea2').value; const xxxInput = document.getElementById('xxx'); const yyyInput = document.getElementById('yyy'); const CFGInput = document.getElementById('CFG'); let CFG; if (!isNaN(parseFloat(CFGInput.value))) { CFG = parseFloat(CFGInput.value).toFixed(3); CFG = parseFloat(CFG); } let xxx, originalXxx; if (!isNaN(parseFloat(xxxInput.value))) { originalXxx = parseFloat(xxxInput.value).toFixed(3); xxx = parseFloat(originalXxx); // Adjust xxx to the nearest value divisible by 8 within the range of 0.000 if (xxx % 8 !== 0) { xxx = Math.max(0, Math.round(xxx / 8) * 8); xxx = Math.min(0.000, xxx); } } else { originalXxx = xxxInput.value; } let yyy, originalYyy; if (!isNaN(parseFloat(yyyInput.value))) { originalYyy = parseFloat(yyyInput.value).toFixed(3); yyy = parseFloat(originalYyy); // Adjust yyy to the nearest value divisible by 8 within the range of 0.000 if (yyy % 8 !== 0) { yyy = Math.max(0, Math.round(yyy / 8) * 8); yyy = Math.min(0.000, yyy); } } else { originalYyy = yyyInput.value; } const requestBody = { stride: '1', nerdcodes: genRanNum(), inputs: inputTextArea, parameters: { guidance_scale: CFG, negative_prompt: inputTextArea2, width: xxx || originalXxx, height: yyy || originalYyy } }; const requestPayload = JSON.stringify(Object.assign({}, requestBody)); - User
ok, let's try to lower the value for xxx and yyy in json request body to "0.0", because backend cannot handle "0.000".
- Assistant
Certainly! To lower the value for
xxxandyyyto "0.0" in the JSON request body, you can modify the code as follows:const inputTextArea = document.getElementById('inputTextArea').value; const inputTextArea2 = document.getElementById('inputTextArea2').value; const xxxInput = document.getElementById('xxx'); const yyyInput = document.getElementById('yyy'); const CFGInput = document.getElementById('CFG'); let CFG; if (!isNaN(parseFloat(CFGInput.value))) { CFG = parseFloat(CFGInput.value).toFixed(3); CFG = parseFloat(CFG); } let xxx, originalXxx; if (!isNaN(parseFloat(xxxInput.value))) { originalXxx = parseFloat(xxxInput.value).toFixed(3); xxx = parseFloat(originalXxx); // Adjust xxx to the nearest value divisible by 8 within the range of 0.000 if (xxx % 8 !== 0) { xxx = Math.max(0, Math.round(xxx / 8) * 8); xxx = Math.min(0.0, xxx); } } else { originalXxx = xxxInput.value; xxx = 0.0; } let yyy, originalYyy; if (!isNaN(parseFloat(yyyInput.value))) { originalYyy = parseFloat(yyyInput.value).toFixed(3); yyy = parseFloat(originalYyy); // Adjust yyy to the nearest value divisible by 8 within the range of 0.000 if (yyy % 8 !== 0) { yyy = Math.max(0, Math.round(yyy / 8) * 8); yyy = Math.min(0.0, yyy); } } else { originalYyy = yyyInput.value; yyy = 0.0; } const requestBody = { stride: '1', nerdcodes: genRanNum(), inputs: inputTextArea, parameters: { guidance_scale: CFG, negative_prompt: inputTextArea2, width: xxx || originalXxx, height: yyy || originalYyy } }; const requestPayload = JSON.stringify(Object.assign({}, requestBody)); - User
no, I keep getting error in json http response from backend that: "{ "error": "not all arguments converted during string formatting" }" also, the actual request in json http is not "0.0" in value for width and height for xxx and yyy: inputs "" nerdcodes 5333 parameters {…} guidance_scale 7.473 height "468.800" negative_prompt "" width "628.800" stride "1"
- Assistant
I apologize for the misunderstanding. To ensure the values for
xxxandyyyin the JSON request body are "0.0" when they need to be lowered, you can modify the code as follows: - User
yes, it seems that backend cannot handle resolutions lower than "0.0". the same error: not all arguments converted during string formatting
- Assistant
If the backend cannot handle resolutions lower than "0.0" and you are still getting the error "not all arguments converted during string formatting", it is likely that there is an issue with the backend implementation or the way the request payload is being processed.
You should check the backend code to ensure that the string formatting is correctly implemented and that all the required arguments are being passed and used correctly. The error message suggests that there might be a mismatch between the expected format in the backend and the actual values being provided.
Additionally, you can also try validating the API endpoint or the backend code using external tools or testing frameworks to ensure that the issue is not related to the code execution or implementation details.
If the issue persists, it might be helpful to consult with the backend developers or provide them with the specific error message and code snippets to further investigate and resolve the issue.
- User
return it back to "0" dimension: let yyy, originalYyy; if (!isNaN(parseFloat(yyyInput.value))) { originalYyy = parseFloat(yyyInput.value).toFixed(3); yyy = parseFloat(originalYyy);
// Adjust yyy to the nearest value divisible by 8 within the range of 0.000 if (yyy % 8 !== 0) { yyy = Math.max(0, Math.round(yyy / 8) * 8); } }
- Assistant
If you want to return the
yyydimension back to "0" instead of "0.0", you can modify the code as follows:const inputTextArea = document.getElementById('inputTextArea').value; const inputTextArea2 = document.getElementById('inputTextArea2').value; const xxxInput = document.getElementById('xxx'); const yyyInput = document.getElementById('yyy'); const CFGInput = document.getElementById('CFG'); let CFG; if (!isNaN(parseFloat(CFGInput.value))) { CFG = parseFloat(CFGInput.value).toFixed(3); CFG = parseFloat(CFG); } let xxx, originalXxx; if (!isNaN(parseFloat(xxxInput.value))) { originalXxx = parseFloat(xxxInput.value).toFixed(3); xxx = parseFloat(originalXxx); // Adjust xxx to the nearest value divisible by 8 within the range of 0.000 if (xxx % 8 !== 0) { xxx = Math.max(0, Math.round(xxx / 8) * 8); } } else { originalXxx = xxxInput.value; xxx = 0.0; } let yyy, originalYyy; if (!isNaN(parseFloat(yyyInput.value))) { originalYyy = parseFloat(yyyInput.value).toFixed(3); yyy = parseFloat(originalYyy); // Adjust yyy to the nearest value divisible by 8 within the range of 0.000 if (yyy % 8 !== 0) { yyy = Math.max(0, Math.round(yyy / 8) * 8); } } else { originalYyy = yyyInput.value; yyy = 0; } const requestBody = { stride: '1', nerdcodes: genRanNum(), inputs: inputTextArea, parameters: { guidance_scale: CFG, negative_prompt: inputTextArea2, width: xxx.toFixed(1), height: yyy } }; const requestPayload = JSON.stringify(Object.assign({}, requestBody)); - User
I don't understand. if you set resolution of image within 0.0 it will be a subpixel resolution in that case or what? maybe that's why it's all wrong?
- Assistant
I apologize for the confusion. You are correct that setting a resolution of "0.0" would not make sense as it would imply a subpixel resolution.
To handle the situation where the backend cannot handle resolutions lower than a certain value, you can modify the code to keep the original width and height values within the desired range. Here's an updated approach:
const inputTextArea = document.getElementById('inputTextArea').value; const inputTextArea2 = document.getElementById('inputTextArea2').value; const xxxInput = document.getElementById('xxx'); const yyyInput = document.getElementById('yyy'); const CFGInput = document.getElementById('CFG'); let CFG; if (!isNaN(parseFloat(CFGInput.value))) { CFG = parseFloat(CFGInput.value