-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathimg2img.js
59 lines (56 loc) · 1.87 KB
/
img2img.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
const axios = require("axios");
const path = require("path");
const fs = require("fs");
const util = require("util");
const ckptSD = require("./index");
const arr = require("./arrayVar")
module.exports.imgToimg = function imgToimg(respImage, fileName) {
var imgToimgData = JSON.stringify({
"init_images": respImage,
"prompt": "Winter season",
"sampler_name": "Heun",
"denoising_strength": 0.75,
// "height": 1024,
// "width": 1024,
});
const imgToimgConfig = {
method: 'post',
url: 'http://127.0.0.1:7860/sdapi/v1/img2img',
headers: {
'Content-Type': 'application/json'
},
data: imgToimgData
};
const model = ckptSD.ckptSD;
async function imgToImg() {
try {
console.log("Generating img2img");
const imgResp = await axios(imgToimgConfig);
const { images, parameters } = imgResp.data;
const arrOfImg = arr.keyOfImg;
let obj = parameters;
let newObj = {};
for (const key in obj) {
arrOfImg.forEach(element => {
if (key === element) {
newObj[key] = obj[key]
}
});
newObj = {
...newObj,
Model: model
}
}
for (const imgToImg of images) {
const imgBuffer = Buffer.from(imgToImg, "base64");
const imgToImgPath = path.join("img2img", `${fileName}.png`);
const textFile = path.join("img2img", `${fileName}.txt`)
fs.writeFileSync(imgToImgPath, imgBuffer);
fs.writeFileSync(textFile, util.inspect(newObj, false, 2, false));
}
} catch (e) {
console.log("Error", e);
}
}
imgToImg();
}