Update PNG_info_web.js
Browse files- PNG_info_web.js +100 -79
PNG_info_web.js
CHANGED
|
@@ -305,108 +305,129 @@
|
|
| 305 |
return file;
|
| 306 |
}
|
| 307 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 308 |
|
| 309 |
-
|
| 310 |
-
setTimeout(()=>{
|
| 311 |
console.log(123)
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
|
| 315 |
-
|
| 316 |
-
|
| 317 |
-
|
| 318 |
-
|
| 319 |
-
|
| 320 |
-
|
| 321 |
-
|
| 322 |
-
|
| 323 |
-
|
| 324 |
-
|
| 325 |
-
|
| 326 |
-
|
| 327 |
-
|
| 328 |
-
|
| 329 |
-
|
| 330 |
-
|
| 331 |
-
|
| 332 |
-
|
| 333 |
-
|
| 334 |
-
|
| 335 |
-
|
| 336 |
-
|
| 337 |
-
|
| 338 |
-
|
| 339 |
|
| 340 |
-
|
| 341 |
-
|
| 342 |
|
| 343 |
|
| 344 |
-
|
| 345 |
-
|
| 346 |
|
| 347 |
-
|
| 348 |
-
|
| 349 |
|
| 350 |
-
|
| 351 |
-
|
| 352 |
|
| 353 |
-
|
| 354 |
-
|
| 355 |
|
| 356 |
-
|
| 357 |
-
|
| 358 |
|
| 359 |
-
|
| 360 |
-
|
| 361 |
|
| 362 |
-
|
| 363 |
-
|
| 364 |
|
| 365 |
-
|
| 366 |
-
|
| 367 |
|
| 368 |
-
|
| 369 |
-
|
| 370 |
|
| 371 |
-
|
| 372 |
-
|
| 373 |
|
| 374 |
-
|
| 375 |
-
|
| 376 |
|
| 377 |
-
|
| 378 |
-
|
| 379 |
|
| 380 |
-
|
| 381 |
-
|
| 382 |
|
| 383 |
-
|
| 384 |
-
|
| 385 |
-
|
| 386 |
|
| 387 |
-
|
| 388 |
|
| 389 |
-
|
| 390 |
-
|
| 391 |
|
| 392 |
-
|
| 393 |
-
|
| 394 |
|
| 395 |
-
|
| 396 |
-
|
| 397 |
|
| 398 |
-
|
| 399 |
-
|
| 400 |
|
| 401 |
-
|
| 402 |
-
|
| 403 |
|
| 404 |
-
|
| 405 |
-
|
| 406 |
|
| 407 |
-
|
| 408 |
-
|
| 409 |
-
|
| 410 |
-
|
| 411 |
-
|
| 412 |
-
)
|
|
|
|
|
|
|
|
|
| 305 |
return file;
|
| 306 |
}
|
| 307 |
|
| 308 |
+
let delayPng_info=function(){
|
| 309 |
+
return new Promise(resolve=>{
|
| 310 |
+
const shadowRoot = document.querySelector('gradio-app')
|
| 311 |
+
// console.log(shadowRoot)
|
| 312 |
+
const observer = new MutationObserver((mutations) => {
|
| 313 |
+
console.log(4)
|
| 314 |
+
mutations.forEach((mutation) => {
|
| 315 |
+
// 如果 id 为 pnginfo_image 的子元素被添加到 gradio-app 元素中
|
| 316 |
+
if (mutation.addedNodes.length && mutation.addedNodes[0].id === 'pnginfo_image') {
|
| 317 |
+
console.log(mutation.addedNodes[0])
|
| 318 |
+
// 取消监听
|
| 319 |
+
observer.disconnect();
|
| 320 |
+
// 获取 id 为 pnginfo_image 的元素并进行操作
|
| 321 |
+
resolve(mutation.addedNodes[0])
|
| 322 |
+
}
|
| 323 |
+
});
|
| 324 |
+
});
|
| 325 |
+
observer.observe(shadowRoot, { childList: true ,subtree:true});
|
| 326 |
+
})
|
| 327 |
+
}
|
| 328 |
|
| 329 |
+
async function png_info_edit() {
|
|
|
|
| 330 |
console.log(123)
|
| 331 |
+
const elem = document.querySelector('gradio-app');
|
| 332 |
+
const shadowRoot = elem
|
| 333 |
+
const png_info = await delayPng_info()
|
| 334 |
+
png_info.addEventListener('change', (e) => {
|
| 335 |
+
// 获取用户选择的文件
|
| 336 |
+
// const file = png_info.files[0];
|
| 337 |
+
setTimeout(async () => {
|
| 338 |
+
const png_info_img = await png_info.querySelector('img')
|
| 339 |
+
let png_info_img_convert = await convertDomImageToBlob(png_info_img)
|
| 340 |
+
console.log(png_info_img_convert)
|
| 341 |
+
let res=await readNovelAITag(png_info_img_convert)
|
| 342 |
+
console.log('res',res)
|
| 343 |
+
shadowRoot.querySelector('#component-677').innerText=res.length?res[0].text:'这不是一张stablediffusion图片'
|
| 344 |
+
|
| 345 |
+
//js对象形式转化
|
| 346 |
+
const result = {};
|
| 347 |
+
// const match = inputString.match(/(?<=prompt:)(.*)(?=Negative prompt:)/s)[0].trim();]
|
| 348 |
+
console.log(res[0].text)
|
| 349 |
+
result.prompt = res[0].text.match(/(.*)(?=Negative prompt:)/s)[0].trim();
|
| 350 |
+
result.negativePrompt = res[0].text.match(/(?<=Negative prompt:)(.*)(?=Steps:)/s)[0].trim();
|
| 351 |
+
let resArr=res[0].text.split(result.negativePrompt)[1].trim().split(',')
|
| 352 |
+
console.log(resArr)
|
| 353 |
+
resArr.forEach(e=>{result[e.split(':')[0].replaceAll(' ','')]=
|
| 354 |
+
e.split(':')[1].trim()
|
| 355 |
+
})
|
| 356 |
+
console.log(result)
|
| 357 |
+
console.log('result',result)
|
| 358 |
|
| 359 |
+
const inputEvent = new Event('input');
|
| 360 |
+
const changeEvent = new Event('change');
|
| 361 |
|
| 362 |
|
| 363 |
+
shadowRoot.querySelector('#txt2img_tab').onclick=()=>{
|
| 364 |
+
shadowRoot.querySelector('[class="tab-nav scroll-hide svelte-1g805jl"]').children[0].click()
|
| 365 |
|
| 366 |
+
shadowRoot.querySelectorAll('#setting_CLIP_stop_at_last_layers input')[0].value=Number(result.Clipskip)
|
| 367 |
+
shadowRoot.querySelectorAll('#setting_CLIP_stop_at_last_layers input')[0].dispatchEvent(inputEvent);
|
| 368 |
|
| 369 |
+
shadowRoot.querySelectorAll('#setting_CLIP_stop_at_last_layers input')[1].value=Number(result.Clipskip)
|
| 370 |
+
shadowRoot.querySelectorAll('#setting_CLIP_stop_at_last_layers input')[1].dispatchEvent(inputEvent);
|
| 371 |
|
| 372 |
+
shadowRoot.querySelector('#txt2img_prompt textarea').value=result.prompt
|
| 373 |
+
shadowRoot.querySelector('#txt2img_prompt textarea').dispatchEvent(inputEvent);
|
| 374 |
|
| 375 |
+
shadowRoot.querySelector('#txt2img_neg_prompt textarea').value=result.negativePrompt
|
| 376 |
+
shadowRoot.querySelector('#txt2img_neg_prompt textarea').dispatchEvent(inputEvent);
|
| 377 |
|
| 378 |
+
shadowRoot.querySelectorAll('#txt2img_steps input')[0].value=Number(result.Steps)
|
| 379 |
+
shadowRoot.querySelectorAll('#txt2img_steps input')[0].dispatchEvent(inputEvent);
|
| 380 |
|
| 381 |
+
shadowRoot.querySelectorAll('#txt2img_steps input')[1].value=Number(result.Steps)
|
| 382 |
+
shadowRoot.querySelectorAll('#txt2img_steps input')[1].dispatchEvent(inputEvent);
|
| 383 |
|
| 384 |
+
shadowRoot.querySelector(`[value="${result.Sampler}"]`).checked = true;
|
| 385 |
+
shadowRoot.querySelector(`[value="${result.Sampler}"]`).dispatchEvent(changeEvent);
|
| 386 |
|
| 387 |
+
shadowRoot.querySelectorAll('#txt2img_width input')[0].value=Number(result.Size.split('x')[0])
|
| 388 |
+
shadowRoot.querySelectorAll('#txt2img_width input')[0].dispatchEvent(inputEvent);
|
| 389 |
|
| 390 |
+
shadowRoot.querySelectorAll('#txt2img_width input')[1].value=Number(result.Size.split('x')[0])
|
| 391 |
+
shadowRoot.querySelectorAll('#txt2img_width input')[1].dispatchEvent(inputEvent);
|
| 392 |
|
| 393 |
+
shadowRoot.querySelectorAll('#txt2img_height input')[0].value=Number(result.Size.split('x')[1])
|
| 394 |
+
shadowRoot.querySelectorAll('#txt2img_height input')[0].dispatchEvent(inputEvent);
|
| 395 |
|
| 396 |
+
shadowRoot.querySelectorAll('#txt2img_height input')[1].value=Number(result.Size.split('x')[1])
|
| 397 |
+
shadowRoot.querySelectorAll('#txt2img_height input')[1].dispatchEvent(inputEvent);
|
| 398 |
|
| 399 |
+
shadowRoot.querySelector('#txt2img_seed input').value=Number(result.Seed)
|
| 400 |
+
shadowRoot.querySelector('#txt2img_seed input').dispatchEvent(inputEvent);
|
| 401 |
|
| 402 |
+
//高清修复
|
| 403 |
+
shadowRoot.querySelector('#txt2img_enable_hr input').checked = !!result.Hiresupscaler
|
| 404 |
+
shadowRoot.querySelectorAll('#txt2img_steps input')[1].dispatchEvent(changeEvent);
|
| 405 |
|
| 406 |
+
shadowRoot.querySelector('#txt2img_hr_upscaler .single-select').innerText = result.Hiresupscaler||'Latent'
|
| 407 |
|
| 408 |
+
shadowRoot.querySelectorAll('#txt2img_hires_steps input')[0].value=Number(result.Hiressteps)||0
|
| 409 |
+
shadowRoot.querySelectorAll('#txt2img_hires_steps input')[0].dispatchEvent(inputEvent);
|
| 410 |
|
| 411 |
+
shadowRoot.querySelectorAll('#txt2img_hires_steps input')[1].value=Number(result.Hiressteps)||0
|
| 412 |
+
shadowRoot.querySelectorAll('#txt2img_hires_steps input')[1].dispatchEvent(inputEvent);
|
| 413 |
|
| 414 |
+
shadowRoot.querySelectorAll('#txt2img_denoising_strength input')[0].value=Number(result.Denoisingstrength)||0
|
| 415 |
+
shadowRoot.querySelectorAll('#txt2img_denoising_strength input')[0].dispatchEvent(inputEvent);
|
| 416 |
|
| 417 |
+
shadowRoot.querySelectorAll('#txt2img_denoising_strength input')[1].value=Number(result.Denoisingstrength)||0
|
| 418 |
+
shadowRoot.querySelectorAll('#txt2img_denoising_strength input')[1].dispatchEvent(inputEvent);
|
| 419 |
|
| 420 |
+
shadowRoot.querySelectorAll('#txt2img_hr_scale input')[0].value=Number(result.Hiresupscale)||1
|
| 421 |
+
shadowRoot.querySelectorAll('#txt2img_hr_scale input')[0].dispatchEvent(inputEvent);
|
| 422 |
|
| 423 |
+
shadowRoot.querySelectorAll('#txt2img_hr_scale input')[1].value=Number(result.Hiresupscale)||1
|
| 424 |
+
shadowRoot.querySelectorAll('#txt2img_hr_scale input')[1].dispatchEvent(inputEvent);
|
| 425 |
|
| 426 |
+
}
|
| 427 |
+
},100)
|
| 428 |
+
});
|
| 429 |
+
}
|
| 430 |
+
|
| 431 |
+
document.addEventListener('DOMContentLoaded', () => {
|
| 432 |
+
png_info_edit()
|
| 433 |
+
});
|