delete old code

pull/369/head
Abdullah Alfaraj 2023-11-13 14:41:59 +03:00
parent 4fd73c7df8
commit 0a3d8daf12
5 changed files with 2 additions and 215 deletions

View File

@ -97,7 +97,7 @@ const {
comfyui, comfyui,
comfyui_util, comfyui_util,
comfyui_main_ui, comfyui_main_ui,
diffusion_chain,
comfyapi, comfyapi,
} = require('./typescripts/dist/bundle') } = require('./typescripts/dist/bundle')
@ -1821,6 +1821,3 @@ async function openFileFromUrlExe(url, format = 'gif') {
await openFileFromUrl(url, format) await openFileFromUrl(url, format)
}) })
} }
let comfy_server = new diffusion_chain.ComfyServer('http://127.0.0.1:8188')
let comfy_object_info = diffusion_chain.ComfyApi.objectInfo(comfy_server)

24
package-lock.json generated
View File

@ -13,7 +13,6 @@
"@types/react": "^18.2.6", "@types/react": "^18.2.6",
"@types/react-dom": "^18.2.4", "@types/react-dom": "^18.2.4",
"changedpi": "^1.0.4", "changedpi": "^1.0.4",
"diffusion-chain": "file:../diffusion-chain",
"fastify": "^4.10.2", "fastify": "^4.10.2",
"jimp": "^0.16.2", "jimp": "^0.16.2",
"madge": "^6.0.0", "madge": "^6.0.0",
@ -50,16 +49,6 @@
"yazl": "^2.5.1" "yazl": "^2.5.1"
} }
}, },
"../diffusion-chain": {
"version": "1.0.7",
"license": "MIT",
"dependencies": {
"@types/node": "^20.4.0",
"mkdirp": "^3.0.1",
"ts-node": "^10.9.1",
"typescript": "^5.1.6"
}
},
"node_modules/@ampproject/remapping": { "node_modules/@ampproject/remapping": {
"version": "2.2.1", "version": "2.2.1",
"resolved": "https://registry.npmjs.org/@ampproject/remapping/-/remapping-2.2.1.tgz", "resolved": "https://registry.npmjs.org/@ampproject/remapping/-/remapping-2.2.1.tgz",
@ -4742,10 +4731,6 @@
"node": ">=4.2.0" "node": ">=4.2.0"
} }
}, },
"node_modules/diffusion-chain": {
"resolved": "../diffusion-chain",
"link": true
},
"node_modules/dir-glob": { "node_modules/dir-glob": {
"version": "3.0.1", "version": "3.0.1",
"resolved": "https://registry.npmjs.org/dir-glob/-/dir-glob-3.0.1.tgz", "resolved": "https://registry.npmjs.org/dir-glob/-/dir-glob-3.0.1.tgz",
@ -13383,15 +13368,6 @@
} }
} }
}, },
"diffusion-chain": {
"version": "file:../diffusion-chain",
"requires": {
"@types/node": "^20.4.0",
"mkdirp": "^3.0.1",
"ts-node": "^10.9.1",
"typescript": "^5.1.6"
}
},
"dir-glob": { "dir-glob": {
"version": "3.0.1", "version": "3.0.1",
"resolved": "https://registry.npmjs.org/dir-glob/-/dir-glob-3.0.1.tgz", "resolved": "https://registry.npmjs.org/dir-glob/-/dir-glob-3.0.1.tgz",

View File

@ -9,7 +9,6 @@
"@types/react": "^18.2.6", "@types/react": "^18.2.6",
"@types/react-dom": "^18.2.4", "@types/react-dom": "^18.2.4",
"changedpi": "^1.0.4", "changedpi": "^1.0.4",
"diffusion-chain": "file:../diffusion-chain",
"fastify": "^4.10.2", "fastify": "^4.10.2",
"jimp": "^0.16.2", "jimp": "^0.16.2",
"madge": "^6.0.0", "madge": "^6.0.0",

View File

@ -3,9 +3,6 @@ const { base64ToBase64Url } = require('./utility/general')
const py_re = require('./utility/sdapi/python_replacement') const py_re = require('./utility/sdapi/python_replacement')
const Enum = require('./enum') const Enum = require('./enum')
const { control_net } = require('./typescripts/dist/bundle')
const { mapPluginSettingsToControlNet, getEnableControlNet, getModuleDetail } =
control_net
const api = require('./utility/api') const api = require('./utility/api')
//javascript plugin can't read images from local directory so we send a request to local server to read the image file and send it back to plugin as image string base64 //javascript plugin can't read images from local directory so we send a request to local server to read the image file and send it back to plugin as image string base64
@ -359,186 +356,6 @@ async function requestExtraSingleImage(payload) {
} }
} }
//REFACTOR: reuse the same code for (requestControlNetTxt2Img,requestControlNetImg2Img)
async function requestControlNetTxt2Img(plugin_settings) {
console.log('requestControlNetTxt2Img: ')
// const full_url = `${g_sd_url}/controlnet/txt2img`
const full_url = `${g_sd_url}/sdapi/v1/txt2img`
const control_net_settings = mapPluginSettingsToControlNet(plugin_settings)
let control_networks = []
// let active_control_networks = 0
for (let index = 0; index < g_controlnet_max_models; index++) {
if (!getEnableControlNet(index)) {
control_networks[index] = false
continue
}
control_networks[index] = true
if (!control_net_settings['controlnet_units'][index]['input_image']) {
app.showAlert('you need to add a valid ControlNet input image')
throw 'you need to add a valid ControlNet input image'
}
if (!control_net_settings['controlnet_units'][index]['module']) {
app.showAlert('you need to select a valid ControlNet Module')
throw 'you need to select a valid ControlNet Module'
}
if (
(!control_net_settings['controlnet_units'][index]['model'] &&
!getModuleDetail()[
control_net_settings['controlnet_units'][index]['module']
].model_free) ||
control_net_settings['controlnet_units'][index]['model'] === 'none'
) {
app.showAlert('you need to select a valid ControlNet Model')
throw 'you need to select a valid ControlNet Model'
}
// active_control_networks++
}
let request = await fetch(full_url, {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify(control_net_settings),
})
let json = await request.json()
console.log('json:', json)
//update the mask in controlNet tab
const numOfImages = json['images'].length
let numberOfAnnotations =
numOfImages - g_generation_session.last_settings.batch_size
if (numberOfAnnotations < 0) numberOfAnnotations = 0
const base64_mask = json['images'].slice(numOfImages - numberOfAnnotations)
let mask_index = 0
for (let index = 0; index < control_networks.length; index++) {
if (
control_networks[index] == false ||
mask_index >= numberOfAnnotations
)
continue
control_net.setControlDetectMapSrc(base64_mask[mask_index], index)
g_generation_session.controlNetMask[index] = base64_mask[mask_index]
mask_index++
}
// g_generation_session.controlNetMask = base64_mask
const standard_response = await py_re.convertToStandardResponse(
control_net_settings,
json['images'].slice(0, numOfImages - numberOfAnnotations),
plugin_settings['uniqueDocumentId']
)
console.log('standard_response:', standard_response)
return standard_response
}
//REFACTOR: reuse the same code for (requestControlNetTxt2Img,requestControlNetImg2Img)
async function requestControlNetImg2Img(plugin_settings) {
console.log('requestControlNetImg2Img: ')
const full_url = `${g_sd_url}/sdapi/v1/img2img`
const control_net_settings = mapPluginSettingsToControlNet(plugin_settings)
// let control_networks = 0
let control_networks = []
for (let index = 0; index < g_controlnet_max_models; index++) {
if (!getEnableControlNet(index)) {
control_networks[index] = false
continue
}
control_networks[index] = true
if (!control_net_settings['controlnet_units'][index]['input_image']) {
app.showAlert('you need to add a valid ControlNet input image')
throw 'you need to add a valid ControlNet input image'
}
if (!control_net_settings['controlnet_units'][index]['module']) {
app.showAlert('you need to select a valid ControlNet Module')
throw 'you need to select a valid ControlNet Module'
}
if (
(!control_net_settings['controlnet_units'][index]['model'] &&
!getModuleDetail()[
control_net_settings['controlnet_units'][index]['module']
].model_free) ||
control_net_settings['controlnet_units'][index]['model'] === 'none'
) {
app.showAlert('you need to select a valid ControlNet Model')
throw 'you need to select a valid ControlNet Model'
}
}
let request = await fetch(full_url, {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify(control_net_settings),
// body: JSON.stringify(payload),
})
let json = await request.json()
console.log('json:', json)
//update the mask in controlNet tab
const numOfImages = json['images'].length
let numberOfAnnotations =
numOfImages - g_generation_session.last_settings.batch_size
if (numberOfAnnotations < 0) numberOfAnnotations = 0
// To fix a bug: when Ultimate SD Upscale is active and running, the detection maps wont be retrieved.
// So set its value to 0 to avoid the result images being loaded in the annotation map interface.
if (
scripts.script_store.isInstalled() &&
scripts.script_store.is_active &&
scripts.script_store.selected_script_name !== 'None' &&
scripts.script_store.is_selected_script_available
) {
numberOfAnnotations = 0
}
const base64_mask = json['images'].slice(numOfImages - numberOfAnnotations)
let mask_index = 0
for (let index = 0; index < control_networks.length; index++) {
if (
control_networks[index] == false ||
mask_index >= numberOfAnnotations
)
continue
control_net.setControlDetectMapSrc(base64_mask[mask_index], index)
g_generation_session.controlNetMask[index] = base64_mask[mask_index]
mask_index++
}
// g_generation_session.controlNetMask = base64_mask
const standard_response = await py_re.convertToStandardResponse(
control_net_settings,
json['images'].slice(0, numOfImages - numberOfAnnotations),
plugin_settings['uniqueDocumentId']
)
console.log('standard_response:', standard_response)
// //get all images except last because it's the mask
// for (const image of json['images'].slice(0, -1)) {
// await io.IO.base64ToLayer(image)
// }
return standard_response
}
async function isWebuiRunning() { async function isWebuiRunning() {
console.log('isWebuiRunning: ') console.log('isWebuiRunning: ')
let json = [] let json = []
@ -577,7 +394,5 @@ module.exports = {
// requestHordeStatus, // requestHordeStatus,
requestExtraSingleImage, requestExtraSingleImage,
requestControlNetTxt2Img,
requestControlNetImg2Img,
isWebuiRunning, isWebuiRunning,
} }

View File

@ -43,5 +43,5 @@ export { toJS } from 'mobx'
export { default as node_fs } from 'fs' export { default as node_fs } from 'fs'
export { default as comfyui_util } from './comfyui/util' export { default as comfyui_util } from './comfyui/util'
export { default as comfyui_main_ui } from './comfyui/main_ui' export { default as comfyui_main_ui } from './comfyui/main_ui'
export * as diffusion_chain from 'diffusion-chain'
export { default as comfyapi } from './comfyui/comfyapi' export { default as comfyapi } from './comfyui/comfyapi'