Khrisna commited on
Commit
4e9e9e0
·
verified ·
1 Parent(s): be8ba04

Update index.js

Browse files
Files changed (1) hide show
  1. index.js +1 -200
index.js CHANGED
@@ -7,13 +7,9 @@ const PDFDocument = require('pdfkit')
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 Upscaler = require('upscaler/node')
12
- const nsfwjs = require('nsfwjs')
13
- const jpegjs = require('jpeg-js')
14
  const Jimp = require('jimp')
15
  const fileType = require("file-type")
16
- const Waifu2X = require('@ibaraki-douji/waifu2x')
17
  //const Stress = require('./lib/ddos.js');
18
  //const { BingChat } = (await import("bing-chat")).default
19
  const { acytoo, chatgpt_4 } = require("./lib/chatgpt.js")
@@ -191,74 +187,7 @@ app.post('/api/upscaler', async (req, res) => {
191
  res.json({ error: true, message: e === '[object Object]' ? 'Internal Server Error' : e })
192
  }
193
  })
194
- app.post('/api/upscaler2', async (req, res) => {
195
- try {
196
- console.log(req.body)
197
- const { images, status } = req.body
198
- if (!images) return res.json({ success: false, message: 'Required an images!' })
199
- if (!status) return res.json({ success: false, message: 'Required an status text!' })
200
-
201
- if(status !== apikey) return res.json({ success: false, message: 'Invalid status!' })
202
- if (/^(https?|http):\/\//i.test(images)) {
203
- const data_img = await axios.request({
204
- method: "GET",
205
- url: images,
206
- responseType: "arraybuffer"
207
- })
208
- const response = await upscaleImage(data_img.data)
209
- const type_img = await fileType.fromBuffer(response)
210
- res.setHeader('Content-Type', type_img.mime)
211
- res.send(response)
212
- } else if (images && typeof images == 'string' && isBase64(images)) {
213
- const response = await upscaleImage(Buffer.from(images, "base64"))
214
- const type_img = await fileType.fromBuffer(response)
215
- res.setHeader('Content-Type', type_img.mime)
216
- res.send(response)
217
- } else {
218
- res.json({
219
- success: false, message: 'No url or base64 detected!!'
220
- })
221
- }
222
- } catch (e) {
223
- console.log(e)
224
- e = String(e)
225
- res.json({ error: true, message: e === '[object Object]' ? 'Internal Server Error' : e })
226
- }
227
- })
228
- app.post('/api/upscaler3', async (req, res) => {
229
- try {
230
- console.log(req.body)
231
- const { images, status } = req.body
232
- if (!images) return res.json({ success: false, message: 'Required an images!' })
233
- if (!status) return res.json({ success: false, message: 'Required an status text!' })
234
 
235
- if(status !== apikey) return res.json({ success: false, message: 'Invalid status!' })
236
- if (/^(https?|http):\/\//i.test(images)) {
237
- const data_img = await axios.request({
238
- method: "GET",
239
- url: images,
240
- responseType: "arraybuffer"
241
- })
242
- const response = await upscaleImageV2(data_img.data)
243
- const type_img = await fileType.fromBuffer(response)
244
- res.setHeader('Content-Type', type_img.mime)
245
- res.send(response)
246
- } else if (images && typeof images == 'string' && isBase64(images)) {
247
- const response = await upscaleImageV2(Buffer.from(images, "base64"))
248
- const type_img = await fileType.fromBuffer(response)
249
- res.setHeader('Content-Type', type_img.mime)
250
- res.send(response)
251
- } else {
252
- res.json({
253
- success: false, message: 'No url or base64 detected!!'
254
- })
255
- }
256
- } catch (e) {
257
- console.log(e)
258
- e = String(e)
259
- res.json({ error: true, message: e === '[object Object]' ? 'Internal Server Error' : e })
260
- }
261
- })
262
  app.post('/api/img2img', async (req, res) => {
263
  try {
264
  console.log(req.body)
@@ -329,54 +258,7 @@ app.post('/api/toanime2', async (req, res) => {
329
  res.json({ error: true, message: e === '[object Object]' ? 'Internal Server Error' : e })
330
  }
331
  })
332
- app.post('/api/nsfw-check', async (req, res) => {
333
- try {
334
- console.log(req.body)
335
- const { images, status } = req.body
336
- if (!images) return res.json({ success: false, message: 'Required an images!' })
337
- if (!status) return res.json({ success: false, message: 'Required an status text!' })
338
 
339
- if(status !== apikey) return res.json({ success: false, message: 'Invalid status!' })
340
- if (/^(https?|http):\/\//i.test(images)) {
341
- const data_img = await axios.request({
342
- method: "GET",
343
- url: images,
344
- responseType: "arraybuffer"
345
- })
346
- const response = await check_nsfw(data_img.data)
347
- res.json({
348
- status: "ok",
349
- result: response
350
- })
351
- } else if (images && typeof images == 'string' && isBase64(images)) {
352
- const img = Buffer.from(images, "base64")
353
- const type = await fileType.fromBuffer(img)
354
- if (type.ext == "jpg") {
355
- let response = await check_nsfw(img)
356
- res.json({
357
- status: "ok",
358
- result: response
359
- })
360
- }
361
- if (type.ext == "webp") {
362
- let converting = await allToJpg(img)
363
- let response = await check_nsfw(converting)
364
- res.json({
365
- status: "ok",
366
- result: response
367
- })
368
- }
369
- } else {
370
- res.json({
371
- success: false, message: 'No url or base64 detected!!'
372
- })
373
- }
374
- } catch (e) {
375
- console.log(e)
376
- e = String(e)
377
- res.json({ error: true, message: e === '[object Object]' ? 'Internal Server Error' : e })
378
- }
379
- })
380
  app.post('/api/instagram/stalk', async (req, res) => {
381
  try {
382
  console.log(req.body)
@@ -561,53 +443,6 @@ function toPDF(urls) {
561
  })
562
  }
563
 
564
- async function upscaleImage(imageBuffer) {
565
- return new Promise(async (resolve, reject) => {
566
- try {
567
- const upscaler = new Upscaler();
568
- const imageTensor = tfjs.tensor3d(new Uint8Array(imageBuffer), [imageBuffer.height, imageBuffer.width, 3]);
569
-
570
- const upscaledTensor = await upscaler.upscale(imageTensor, {
571
- scale: 4, // upscale by a factor of 4
572
- sharpen: true, // apply sharpening
573
- denoise: true, // apply denoising
574
- contrast: 1.5, // increase contrast by 50%
575
- colorEnhance: true, // enhance colors
576
- });
577
-
578
- const upscaledImageBuffer = await tfjs.tensor3dToBuffer(upscaledTensor);
579
-
580
- // dispose the tensors!
581
- imageTensor.dispose();
582
- upscaledTensor.dispose();
583
- resolve(upscaledImageBuffer);
584
- } catch (error) {
585
- reject(error);
586
- }
587
- });
588
- }
589
-
590
- async function upscaleImageV2(imageBuffer) {
591
- return new Promise(async (resolve, reject) => {
592
- try {
593
- const upscale = await Waifu2X.upscale(imageBuffer, null, {
594
- noise: 0,
595
- scale: 2,
596
- gpu: -1,
597
- ramLimit: 500,
598
- outputAsBuffer: true
599
- });
600
-
601
- upscale.finishedPromise().then(() => {
602
- const outputBuffer = upscale.endBuffer;
603
- resolve(outputBuffer); // ArrayBuffer
604
- });
605
- } catch(e) {
606
- reject(e.message);
607
- }
608
- });
609
- }
610
-
611
  async function processImageUpscaler(images, denoise, format, type) {
612
  return new Promise(async (resolve, reject) => {
613
  try {
@@ -725,38 +560,4 @@ async function processImageAnime(inputBuffer) {
725
  console.error(err);
726
  throw err;
727
  }
728
- }
729
-
730
-
731
-
732
- async function check_nsfw(buffer) {
733
- let _model = await load_model()
734
- const convert = async (img) => {
735
- // Decoded image in UInt8 Byte array
736
- const image = await jpegjs.decode(img, { useTArray: true })
737
-
738
- const numChannels = 3
739
- const numPixels = image.width * image.height
740
- const values = new Int32Array(numPixels * numChannels)
741
-
742
- for (let i = 0; i < numPixels; i++)
743
- for (let c = 0; c < numChannels; ++c)
744
- values[i * numChannels + c] = image.data[i * 4 + c]
745
-
746
- return tfjs.tensor3d(values, [image.height, image.width, numChannels], 'int32')
747
- }
748
- const image = await convert(buffer)
749
- const predictions = await _model.classify(image)
750
- image.dispose();
751
- const results = predictions.map(v => {
752
- return {
753
- class_name: v.className,
754
- probability: v.probability,
755
- probability_percent: (v.probability * 100).toFixed(2)
756
- }
757
- })
758
- return results
759
- }
760
- async function load_model() {
761
- return await nsfwjs.load()
762
  }
 
7
  const axios = require("axios")
8
  const FormData = require("form-data")
9
  const ytdl = require('ytdl-core')
 
 
 
 
10
  const Jimp = require('jimp')
11
  const fileType = require("file-type")
12
+
13
  //const Stress = require('./lib/ddos.js');
14
  //const { BingChat } = (await import("bing-chat")).default
15
  const { acytoo, chatgpt_4 } = require("./lib/chatgpt.js")
 
187
  res.json({ error: true, message: e === '[object Object]' ? 'Internal Server Error' : e })
188
  }
189
  })
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
190
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
191
  app.post('/api/img2img', async (req, res) => {
192
  try {
193
  console.log(req.body)
 
258
  res.json({ error: true, message: e === '[object Object]' ? 'Internal Server Error' : e })
259
  }
260
  })
 
 
 
 
 
 
261
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
262
  app.post('/api/instagram/stalk', async (req, res) => {
263
  try {
264
  console.log(req.body)
 
443
  })
444
  }
445
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
446
  async function processImageUpscaler(images, denoise, format, type) {
447
  return new Promise(async (resolve, reject) => {
448
  try {
 
560
  console.error(err);
561
  throw err;
562
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
563
  }