Update index.js
Browse files
index.js
CHANGED
|
@@ -19,7 +19,6 @@ const Waifu2X = require('@ibaraki-douji/waifu2x')
|
|
| 19 |
const { acytoo, chatgpt_4 } = require("./lib/chatgpt.js")
|
| 20 |
const { sss_instagram, gramvio } = require("./lib/instagram.js")
|
| 21 |
const { allToJpg } = require("./lib/convertFormat.js")
|
| 22 |
-
const { Blob } = require("formdata-node")
|
| 23 |
const apikey = "@SadTeam77"
|
| 24 |
|
| 25 |
const app = express()
|
|
@@ -260,6 +259,40 @@ app.post('/api/upscaler3', async (req, res) => {
|
|
| 260 |
res.json({ error: true, message: e === '[object Object]' ? 'Internal Server Error' : e })
|
| 261 |
}
|
| 262 |
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 263 |
app.post('/api/toanime2', async (req, res) => {
|
| 264 |
try {
|
| 265 |
console.log(req.body)
|
|
@@ -631,13 +664,18 @@ async function processImageUpscaler(images, denoise, format, type) {
|
|
| 631 |
}
|
| 632 |
|
| 633 |
async function processImage2Img(imgBuffer, prompt) {
|
|
|
|
|
|
|
| 634 |
const type = fileType(imgBuffer);
|
| 635 |
const convertingBlob = new Blob([imgBuffer], { type: type.mime });
|
|
|
|
|
|
|
|
|
|
| 636 |
|
| 637 |
const app = await Client.connect("Manjushri/SDXL-Turbo-Img2Img-CPU");
|
| 638 |
const result = await app.predict("/predict", [
|
| 639 |
-
|
| 640 |
-
|
| 641 |
1, // number (numeric value between 1 and 5) in 'Number of Iterations' Slider component
|
| 642 |
0, // number (numeric value between 0 and 987654321987654321) in 'Seed' Slider component
|
| 643 |
0.1, // number (numeric value between 0.1 and 1) in 'Strength' Slider component
|
|
|
|
| 19 |
const { acytoo, chatgpt_4 } = require("./lib/chatgpt.js")
|
| 20 |
const { sss_instagram, gramvio } = require("./lib/instagram.js")
|
| 21 |
const { allToJpg } = require("./lib/convertFormat.js")
|
|
|
|
| 22 |
const apikey = "@SadTeam77"
|
| 23 |
|
| 24 |
const app = express()
|
|
|
|
| 259 |
res.json({ error: true, message: e === '[object Object]' ? 'Internal Server Error' : e })
|
| 260 |
}
|
| 261 |
})
|
| 262 |
+
app.post('/api/', async (req, res) => {
|
| 263 |
+
try {
|
| 264 |
+
console.log(req.body)
|
| 265 |
+
const { images, status } = req.body
|
| 266 |
+
if (!images) return res.json({ success: false, message: 'Required an images!' })
|
| 267 |
+
if (!status) return res.json({ success: false, message: 'Required an status text!' })
|
| 268 |
+
|
| 269 |
+
if(status !== apikey) return res.json({ success: false, message: 'Invalid status!' })
|
| 270 |
+
if (/^(https?|http):\/\//i.test(images)) {
|
| 271 |
+
const data_img = await axios.request({
|
| 272 |
+
method: "GET",
|
| 273 |
+
url: images,
|
| 274 |
+
responseType: "arraybuffer"
|
| 275 |
+
})
|
| 276 |
+
const response = await upscaleImageV2(data_img.data)
|
| 277 |
+
const type_img = await fileType.fromBuffer(response)
|
| 278 |
+
res.setHeader('Content-Type', type_img.mime)
|
| 279 |
+
res.send(response)
|
| 280 |
+
} else if (images && typeof images == 'string' && isBase64(images)) {
|
| 281 |
+
const response = await upscaleImageV2(Buffer.from(images, "base64"))
|
| 282 |
+
const type_img = await fileType.fromBuffer(response)
|
| 283 |
+
res.setHeader('Content-Type', type_img.mime)
|
| 284 |
+
res.send(response)
|
| 285 |
+
} else {
|
| 286 |
+
res.json({
|
| 287 |
+
success: false, message: 'No url or base64 detected!!'
|
| 288 |
+
})
|
| 289 |
+
}
|
| 290 |
+
} catch (e) {
|
| 291 |
+
console.log(e)
|
| 292 |
+
e = String(e)
|
| 293 |
+
res.json({ error: true, message: e === '[object Object]' ? 'Internal Server Error' : e })
|
| 294 |
+
}
|
| 295 |
+
})
|
| 296 |
app.post('/api/toanime2', async (req, res) => {
|
| 297 |
try {
|
| 298 |
console.log(req.body)
|
|
|
|
| 664 |
}
|
| 665 |
|
| 666 |
async function processImage2Img(imgBuffer, prompt) {
|
| 667 |
+
const FormData = require('formdata-node');
|
| 668 |
+
const Blob = require('formdata-node/Blob');
|
| 669 |
const type = fileType(imgBuffer);
|
| 670 |
const convertingBlob = new Blob([imgBuffer], { type: type.mime });
|
| 671 |
+
|
| 672 |
+
const form = new FormData();
|
| 673 |
+
form.append('image', convertingBlob, "image" + type.ext);
|
| 674 |
|
| 675 |
const app = await Client.connect("Manjushri/SDXL-Turbo-Img2Img-CPU");
|
| 676 |
const result = await app.predict("/predict", [
|
| 677 |
+
form, // blob in 'Raw Image.' Image component
|
| 678 |
+
prompt, // string in 'Prompt Input Text. 77 Token (Keyword or Symbol) Maximum' Textbox component
|
| 679 |
1, // number (numeric value between 1 and 5) in 'Number of Iterations' Slider component
|
| 680 |
0, // number (numeric value between 0 and 987654321987654321) in 'Seed' Slider component
|
| 681 |
0.1, // number (numeric value between 0.1 and 1) in 'Strength' Slider component
|