Spaces:
Paused
Paused
Update index.js
Browse files
index.js
CHANGED
|
@@ -8,6 +8,7 @@ const axios = require("axios")
|
|
| 8 |
const FormData = require("form-data")
|
| 9 |
const ytdl = require('ytdl-core')
|
| 10 |
const tfjs = require('@tensorflow/tfjs-node')
|
|
|
|
| 11 |
const nsfwjs = require('nsfwjs')
|
| 12 |
const jpegjs = require('jpeg-js')
|
| 13 |
const Jimp = require('jimp')
|
|
@@ -169,7 +170,7 @@ app.post('/api/upscaler', async (req, res) => {
|
|
| 169 |
url: images,
|
| 170 |
responseType: "arraybuffer"
|
| 171 |
})
|
| 172 |
-
const response = await
|
| 173 |
const type_img = await fileType.fromBuffer(response)
|
| 174 |
res.setHeader('Content-Type', type_img.mime)
|
| 175 |
res.send(response)
|
|
@@ -189,6 +190,40 @@ app.post('/api/upscaler', async (req, res) => {
|
|
| 189 |
res.json({ error: true, message: e === '[object Object]' ? 'Internal Server Error' : e })
|
| 190 |
}
|
| 191 |
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 192 |
app.post('/api/toanime2', async (req, res) => {
|
| 193 |
try {
|
| 194 |
console.log(req.body)
|
|
@@ -455,62 +490,84 @@ function toPDF(urls) {
|
|
| 455 |
})
|
| 456 |
}
|
| 457 |
|
| 458 |
-
async function
|
| 459 |
-
|
| 460 |
-
|
| 461 |
-
|
| 462 |
-
|
| 463 |
-
|
| 464 |
-
|
| 465 |
-
|
| 466 |
-
|
| 467 |
-
|
| 468 |
-
formData.append("type", type);
|
| 469 |
-
formData.append("file", image, {
|
| 470 |
-
filename:
|
| 471 |
-
"images_" + random_numbers.toString().padStart(3, "0") + "." + type_img.ext,
|
| 472 |
-
contentType: type_img.mime,
|
| 473 |
-
});
|
| 474 |
-
|
| 475 |
-
const response = await axios.request({
|
| 476 |
-
method: "POST",
|
| 477 |
-
url: "https://api.alcaamado.es/ns-api-waifu2x/v1/convert",
|
| 478 |
-
data: formData,
|
| 479 |
-
debug: true,
|
| 480 |
-
headers: {
|
| 481 |
-
Authority: "api.alcaamado.es",
|
| 482 |
-
Accept: "application/json",
|
| 483 |
-
Referer: "https://waifu2x.pro/",
|
| 484 |
-
Origin: "https://waifu2x.pro",
|
| 485 |
-
"User-Agent":
|
| 486 |
-
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",
|
| 487 |
-
},
|
| 488 |
-
});
|
| 489 |
-
|
| 490 |
-
const images = await axios.request({
|
| 491 |
-
method: "GET",
|
| 492 |
-
url:
|
| 493 |
-
"https://api.alcaamado.es/api/v2/waifu2x/get?hash=" +
|
| 494 |
-
response.data.hash +
|
| 495 |
-
"&type=" +
|
| 496 |
-
format,
|
| 497 |
-
headers: {
|
| 498 |
-
Accept: "image/webp,image/apng,image/svg+xml,image/*,*/*;q=0.8",
|
| 499 |
-
"Content-Type": "image/jpg",
|
| 500 |
-
Referer: "https://waifu2x.pro/",
|
| 501 |
-
"User-Agent":
|
| 502 |
-
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",
|
| 503 |
-
},
|
| 504 |
-
responseType: "arraybuffer",
|
| 505 |
-
});
|
| 506 |
-
|
| 507 |
-
// Mengonversi arraybuffer ke Buffer
|
| 508 |
-
//const buffer = Buffer.from(images.data);
|
| 509 |
-
resolve(images.data);
|
| 510 |
-
} catch (error) {
|
| 511 |
-
reject(error);
|
| 512 |
-
}
|
| 513 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 514 |
}
|
| 515 |
|
| 516 |
async function processImageAnime(inputBuffer) {
|
|
|
|
| 8 |
const FormData = require("form-data")
|
| 9 |
const ytdl = require('ytdl-core')
|
| 10 |
const tfjs = require('@tensorflow/tfjs-node')
|
| 11 |
+
const Upscaler = require('upscaler')
|
| 12 |
const nsfwjs = require('nsfwjs')
|
| 13 |
const jpegjs = require('jpeg-js')
|
| 14 |
const Jimp = require('jimp')
|
|
|
|
| 170 |
url: images,
|
| 171 |
responseType: "arraybuffer"
|
| 172 |
})
|
| 173 |
+
const response = await processImageUpscaler(data_img.data, denoise, scale, format, type)
|
| 174 |
const type_img = await fileType.fromBuffer(response)
|
| 175 |
res.setHeader('Content-Type', type_img.mime)
|
| 176 |
res.send(response)
|
|
|
|
| 190 |
res.json({ error: true, message: e === '[object Object]' ? 'Internal Server Error' : e })
|
| 191 |
}
|
| 192 |
})
|
| 193 |
+
app.post('/api/upscaler2', async (req, res) => {
|
| 194 |
+
try {
|
| 195 |
+
console.log(req.body)
|
| 196 |
+
const { images } = req.body
|
| 197 |
+
if (!images) return res.json({ success: false, message: 'Required an images!' })
|
| 198 |
+
if (!status) return res.json({ success: false, message: 'Required an status text!' })
|
| 199 |
+
|
| 200 |
+
if(status !== apikey) return res.json({ success: false, message: 'Invalid status!' })
|
| 201 |
+
if (/^(https?|http):\/\//i.test(images)) {
|
| 202 |
+
const data_img = await axios.request({
|
| 203 |
+
method: "GET",
|
| 204 |
+
url: images,
|
| 205 |
+
responseType: "arraybuffer"
|
| 206 |
+
})
|
| 207 |
+
const response = await upscaleImage(data_img.data)
|
| 208 |
+
const type_img = await fileType.fromBuffer(response)
|
| 209 |
+
res.setHeader('Content-Type', type_img.mime)
|
| 210 |
+
res.send(response)
|
| 211 |
+
} else if (images && typeof images == 'string' && isBase64(images)) {
|
| 212 |
+
const response = await upscaleImage(Buffer.from(images, "base64"))
|
| 213 |
+
const type_img = await fileType.fromBuffer(response)
|
| 214 |
+
res.setHeader('Content-Type', type_img.mime)
|
| 215 |
+
res.send(response)
|
| 216 |
+
} else {
|
| 217 |
+
res.json({
|
| 218 |
+
success: false, message: 'No url or base64 detected!!'
|
| 219 |
+
})
|
| 220 |
+
}
|
| 221 |
+
} catch (e) {
|
| 222 |
+
console.log(e)
|
| 223 |
+
e = String(e)
|
| 224 |
+
res.json({ error: true, message: e === '[object Object]' ? 'Internal Server Error' : e })
|
| 225 |
+
}
|
| 226 |
+
})
|
| 227 |
app.post('/api/toanime2', async (req, res) => {
|
| 228 |
try {
|
| 229 |
console.log(req.body)
|
|
|
|
| 490 |
})
|
| 491 |
}
|
| 492 |
|
| 493 |
+
async function upscaleImage(images) {
|
| 494 |
+
const upscaler = new Upscaler();
|
| 495 |
+
const image = tfjs.node.decodeImage(images, 3);
|
| 496 |
+
|
| 497 |
+
const tensor = await upscaler.upscale(image, {
|
| 498 |
+
scale: 4, // upscale by a factor of 4
|
| 499 |
+
sharpen: true, // apply sharpening
|
| 500 |
+
denoise: true, // apply denoising
|
| 501 |
+
contrast: 1.5, // increase contrast by 50%
|
| 502 |
+
colorEnhance: true, // enhance colors
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 503 |
});
|
| 504 |
+
|
| 505 |
+
const upscaledTensor = await tf.node.encodePng(tensor);
|
| 506 |
+
const arrayBuffer = await upscaledTensor.arrayBuffer();
|
| 507 |
+
|
| 508 |
+
// dispose the tensors!
|
| 509 |
+
image.dispose();
|
| 510 |
+
tensor.dispose();
|
| 511 |
+
upscaledTensor.dispose();
|
| 512 |
+
|
| 513 |
+
return arrayBuffer;
|
| 514 |
+
}
|
| 515 |
+
|
| 516 |
+
async function processImageUpscaler(images, denoise, format, type) {
|
| 517 |
+
return new Promise(async (resolve, reject) => {
|
| 518 |
+
try {
|
| 519 |
+
const formData = new FormData();
|
| 520 |
+
formData.append("denoise", denoise);
|
| 521 |
+
formData.append("scale", "true");
|
| 522 |
+
formData.append("format", format);
|
| 523 |
+
formData.append("type", type);
|
| 524 |
+
formData.append("file", images, {
|
| 525 |
+
filename:
|
| 526 |
+
"images_" + "downlaod.jpg",
|
| 527 |
+
contentType: "image/jpeg",
|
| 528 |
+
});
|
| 529 |
+
|
| 530 |
+
// Convert FormData to Buffer
|
| 531 |
+
// const bufferFormData = await formData.getBuffer();
|
| 532 |
+
|
| 533 |
+
const response = await axios.request({
|
| 534 |
+
method: "POST",
|
| 535 |
+
url: "https://api.alcaamado.es/ns-api-waifu2x/v1/convert",
|
| 536 |
+
data: formData,
|
| 537 |
+
debug: true,
|
| 538 |
+
headers: {
|
| 539 |
+
Authority: "api.alcaamado.es",
|
| 540 |
+
Accept: "application/json",
|
| 541 |
+
Referer: "https://waifu2x.pro/",
|
| 542 |
+
Origin: "https://waifu2x.pro",
|
| 543 |
+
"User-Agent":
|
| 544 |
+
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",
|
| 545 |
+
"Content-Type": `multipart/form-data; boundary=${formData._boundary}`,
|
| 546 |
+
},
|
| 547 |
+
});
|
| 548 |
+
|
| 549 |
+
const images = await axios.request({
|
| 550 |
+
method: "GET",
|
| 551 |
+
url:
|
| 552 |
+
"https://api.alcaamado.es/api/v2/waifu2x/get?hash=" +
|
| 553 |
+
response.data.hash +
|
| 554 |
+
"&type=" +
|
| 555 |
+
format,
|
| 556 |
+
headers: {
|
| 557 |
+
Accept: "image/webp,image/apng,image/svg+xml,image/*,*/*;q=0.8",
|
| 558 |
+
"Content-Type": "image/jpg",
|
| 559 |
+
Referer: "https://waifu2x.pro/",
|
| 560 |
+
"User-Agent":
|
| 561 |
+
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",
|
| 562 |
+
},
|
| 563 |
+
responseType: "arraybuffer",
|
| 564 |
+
});
|
| 565 |
+
|
| 566 |
+
resolve(images.data)
|
| 567 |
+
} catch (error) {
|
| 568 |
+
reject(error);
|
| 569 |
+
}
|
| 570 |
+
});
|
| 571 |
}
|
| 572 |
|
| 573 |
async function processImageAnime(inputBuffer) {
|