Spaces:
Running
Running
File size: 14,068 Bytes
095af13 2fb0118 84574b6 87c3c2a 51ed446 38f35ec 0eb04e4 4deaaad 85ce074 7a0283e 095af13 bea0315 22d0bb6 3597a5d 22d0bb6 095af13 2201892 9494916 095af13 59f11b4 095af13 58d61a1 7a0283e 58d61a1 7a0283e d5c31be 7a0283e a014c9f 7a0283e d5c31be 7a0283e 8dd1a05 a014c9f 8dd1a05 685d9ff 11cf37d 8dd1a05 2af4d6d 9f8372e 2af4d6d 5af4057 9f8372e 52f5da4 9f8372e f7f0a4c 9f8372e 45b4d1a 9f8372e 45b4d1a 9f8372e 2af4d6d 0b4abe4 87c3c2a e30d518 87c3c2a 38f35ec f12a8d4 38f35ec 85ce074 38f35ec 87c3c2a 4deaaad 0eb04e4 0b4abe4 2af4d6d 0eb04e4 58d61a1 095af13 3f43266 211b824 bcaeb16 095af13 4ca849c 095af13 87c3c2a 095af13 4ca849c ceeb8a8 4ca849c 095af13 4ca849c 095af13 4ca849c 095af13 8c53df2 58d61a1 2af4d6d 9f8372e 2af4d6d 9f8372e 239892a 2af4d6d 9f8372e 239892a 2af4d6d 3366c30 b1819dc 3366c30 5af4057 87c3c2a 1f10f3f 3dd73af 51ed446 3dd73af 7f476e3 a1c6dd2 3dd73af 211b824 a8b15f5 7e84ef0 e30d518 87c3c2a e30d518 211b824 e8434c9 7a0283e |
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 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 |
const os = require('os')
const bytes = require('bytes')
const sharp = require('sharp')
const morgan = require('morgan')
const express = require('express')
const PDFDocument = require('pdfkit')
const axios = require("axios")
const FormData = require("form-data")
const tfjs = require('@tensorflow/tfjs-node')
const nsfwjs = require('nsfwjs')
const jpegjs = require('jpeg-js')
const fileType = require("file-type")
//const { BingChat } = (await import("bing-chat")).default
const { insta_iwaId, insta_iwaIdUrl, insta_iwa, insta_iwaTag } = require("./lib/instagram.js")
const { allToJpg } = require("./lib/convertFormat.js")
const apikey = "@SadTeam77"
const app = express()
app.set('json spaces', 4)
app.use(morgan('dev'))
app.use(express.json({ limit: "500mb" }))
app.use(express.urlencoded({ limit: '500mb', extended: true }))
app.use((req, res, next) => {
load_model(),
next()
})
app.all('/', (req, res) => {
const status = {}
const used = process.memoryUsage()
for (let key in used) status[key] = formatSize(used[key])
const totalmem = os.totalmem()
const freemem = os.freemem()
status.memoryUsage = `${formatSize(totalmem - freemem)} / ${formatSize(totalmem)}`
res.json({
creator: "@SadTeams",
message: 'Hello World!!',
uptime: new Date(process.uptime() * 1000).toUTCString().split(' ')[4],
status
})
})
app.post('/imagetopdf', async (req, res) => {
try {
console.log(req.body)
const { images } = req.body
if (!images) return res.json({ success: false, message: 'Required an array image url' })
const buffer = await toPDF(images)
res.setHeader('Content-Disposition', `attachment; filename=${Math.random().toString(36).slice(2)}.pdf`)
res.setHeader('Content-Type', 'application/pdf')
res.setHeader('Content-Length', buffer.byteLength)
res.send(buffer)
} catch (e) {
console.log(e)
e = String(e)
res.json({ error: true, message: e === '[object Object]' ? 'Internal Server Error' : e })
}
})
app.post('/api/chatgpt', async (req, res) => {
try {
console.log(req.body)
const { prompt, model, status } = req.body
if (!prompt) return res.json({ success: false, message: 'Required an prompt text!' })
if (!model) return res.json({ success: false, message: 'Required an model version!' })
if (!status) return res.json({ success: false, message: 'Required an prompt text!' })
if(status !== apikey) return res.json({ success: false, message: 'Invalid status!' })
const response = await acytoo(prompt, model)
res.json({
status: "ok",
result: response
})
} catch (e) {
console.log(e)
e = String(e)
res.json({ error: true, message: e === '[object Object]' ? 'Internal Server Error' : e })
}
})
app.post('/api/chatgpt2', async (req, res) => {
try {
console.log(req.body)
const { data, prompt, status } = req.body
if (!data) return res.json({ success: false, message: 'Required an data text!' })
if (!prompt) return res.json({ success: false, message: 'Required an prompt text!' })
if (!status) return res.json({ success: false, message: 'Required an status text!' })
if(status !== apikey) return res.json({ success: false, message: 'Invalid status!' })
const response = await axios.request({
method: "GET",
url: `https://aemt.me/prompt/gpt?prompt=${data}&text=${prompt}`
})
res.json({
status: "ok",
result: response.data.result
})
} catch (e) {
console.log(e)
e = String(e)
res.json({ error: true, message: e === '[object Object]' ? 'Internal Server Error' : e })
}
})
app.post('/api/toanime', async (req, res) => {
try {
console.log(req.body)
const { url, status } = req.body
if (!url) return res.json({ success: false, message: 'Required an url!' })
if (!status) return res.json({ success: false, message: 'Required an status text!' })
if(status !== apikey) return res.json({ success: false, message: 'Invalid status!' })
const response = await axios.request({
method: "GET",
url: `https://aemt.me/toanime?url=${url}`
})
const image = await axios.request({
method: "GET",
url: response.data.url.img_crop_single,
responseType: "arraybuffer"
})
res.setHeader('Content-Type', 'image/jpeg')
res.send(image.data)
} catch (e) {
console.log(e)
e = String(e)
res.json({ error: true, message: e === '[object Object]' ? 'Internal Server Error' : e })
}
})
app.post('/api/waifu2x', async (req, res) => {
try {
console.log(req.body)
const { images, format, status } = req.body
if (!images) return res.json({ success: false, message: 'Required an images!' })
if (!format) return res.json({ success: false, message: 'Required an format size!' })
if (!status) return res.json({ success: false, message: 'Required an status text!' })
if(status !== apikey) return res.json({ success: false, message: 'Invalid status!' })
if (/^(https?|http):\/\//i.test(images)) {
const data_img = await axios.request({
method: "GET",
url: images,
responseType: "arraybuffer"
})
const response = await waifu2x(data_img.data, format)
res.setHeader('Content-Type', 'image/jpg')
res.send(response)
} else if (images && typeof images == 'string' && isBase64(images)) {
const response = await waifu2x(Buffer.from(images, "base64"), format)
res.setHeader('Content-Type', 'image/jpg')
res.send(response)
} else {
res.json({
success: false, message: 'No url or base64 detected!!'
})
}
} catch (e) {
console.log(e)
e = String(e)
res.json({ error: true, message: e === '[object Object]' ? 'Internal Server Error' : e })
}
})
app.post('/api/nsfw-check', async (req, res) => {
try {
console.log(req.body)
const { images, status } = req.body
if (!images) return res.json({ success: false, message: 'Required an images!' })
if (!status) return res.json({ success: false, message: 'Required an status text!' })
if(status !== apikey) return res.json({ success: false, message: 'Invalid status!' })
if (/^(https?|http):\/\//i.test(images)) {
const data_img = await axios.request({
method: "GET",
url: images,
responseType: "arraybuffer"
})
const response = await check_nsfw(data_img.data)
res.json({
status: "ok",
result: response
})
} else if (images && typeof images == 'string' && isBase64(images)) {
const img = Buffer.from(images, "base64")
const type = await fileType.fromBuffer(img)
if (type.ext == "jpg") {
let response = await check_nsfw(img)
res.json({
status: "ok",
result: response
})
}
if (type.ext == "webp") {
let converting = await allToJpg(img)
let response = await check_nsfw(converting)
res.json({
status: "ok",
result: response
})
}
} else {
res.json({
success: false, message: 'No url or base64 detected!!'
})
}
} catch (e) {
console.log(e)
e = String(e)
res.json({ error: true, message: e === '[object Object]' ? 'Internal Server Error' : e })
}
})
app.post('/api/instagram-stalk', async (req, res) => {
try {
console.log(req.body)
const { username, status } = req.body
if (!username) return res.json({ success: false, message: 'Required an data text!' })
if (!status) return res.json({ success: false, message: 'Required an status text!' })
if(status !== apikey) return res.json({ success: false, message: 'Invalid status!' })
const response = await insta_iwa(username)
res.json({
status: "ok",
result: response
})
} catch (e) {
console.log(e)
e = String(e)
res.json({ error: true, message: e === '[object Object]' ? 'Internal Server Error' : e })
}
})
/*app.post('/api/bingchat', async (req, res) => {
try {
console.log(req.body)
const { prompt, status } = req.body
if (!prompt) return res.json({ success: false, message: 'Required an prompt text!' })
if (!status) return res.json({ success: false, message: 'Required an status text!' })
if(status !== apikey) return res.json({ success: false, message: 'Invalid status!' })
const api = new BingChat({
cookie: process.env.BING_COOKIE
})
const resonse = await api.sendMessage(prompt)
res.json({
status: "ok",
result: response.text
})
} catch (e) {
console.log(e)
e = String(e)
res.json({ error: true, message: e === '[object Object]' ? 'Internal Server Error' : e })
}
})*/
const PORT = process.env.PORT || 7860
app.listen(PORT, () => {
console.log('App running on port', PORT)
})
function formatSize(num) {
return bytes(+num || 0, { unitSeparator: ' ' })
}
function isBase64(str) {
try {
return btoa(atob(str)) === str
} catch {
return false
}
}
function toPDF(urls) {
return new Promise(async (resolve, reject) => {
try {
if (!Array.isArray(urls)) urls = [urls]
const doc = new PDFDocument({ margin: 0, size: 'A4' })
const buffers = []
for (let i = 0; i < urls.length; i++) {
const response = await fetch(urls[i], { headers: { referer: urls[i] }})
if (!response.ok) continue
const type = response.headers.get('content-type')
if (!/image/.test(type)) continue
let buffer = Buffer.from(await response.arrayBuffer())
if (/gif|webp/.test(type)) buffer = await sharp(buffer).png().toBuffer()
doc.image(buffer, 0, 0, { fit: [595.28, 841.89], align: 'center', valign: 'center' })
if (urls.length !== i + 1) doc.addPage()
}
doc.on('data', (chunk) => buffers.push(chunk))
doc.on('end', () => resolve(Buffer.concat(buffers)))
doc.on('error', reject)
doc.end()
} catch (e) {
console.log(e)
reject(e)
}
})
}
async function acytoo(text, model) {
let res = await axios.request({
method: "POST",
url: "https://chat.acytoo.com/api/completions",
data: JSON.stringify({
key: "",
messages: [{
role: "user",
content: text,
createAt: "",
}],
model: model,
password: "",
temprature: 1
}),
headres: {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36",
"Origin": "https://chat.acytoo.com"
}
})
return res.data
}
async function waifu2x(image, formats) {
// data
//let img = await axios.get(urls, { responseType: "arraybuffer"})
let random_numbers = Math.floor(Math.random() * 1000)
let format
if(formats == "Medium") {
format = "1"
} else if(formats == "High") {
format = "2"
} else if(!formats) {
format = "0"
}
// memasukan data api
const formData = new FormData()
formData.append("denoise", format)
formData.append("scale", "true")
formData.append("file", image, {
filename: "images_" + random_numbers.toString().padStart(3, '0') + ".jpg",
contentType: "image/jpeg"
})
// request ke api untuk mendapatkan hash nya
const response = await axios.request({
method: "POST",
url: "https://api.alcaamado.es/api/v1/waifu2x/convert",
data: formData,
headers: {
"Accept": "application/json",
"Referer": "https://waifu2x.pro/",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36 Edg/119.0.0.0"
}
})
const ress = await axios.request({
method: "GET",
url: "https://api.alcaamado.es/api/v2/waifu2x/check?hash=" + response.data.hash,
headers: {
"Accept": "application/json",
"Referer": "https://waifu2x.pro/",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36 Edg/119.0.0.0"
}
})
if(!ress.data.finished) return "Images Not Supported!!"
const images = await axios.request({
method: "GET",
url: "https://api.alcaamado.es/api/v2/waifu2x/get?hash=" + response.data.hash + "&type=jpg",
headers: {
"Accept": "image/webp,image/apng,image/svg+xml,image/*,*/*;q=0.8",
"Content-Type": "image/jpg",
"Referer": "https://waifu2x.pro/",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36 Edg/119.0.0.0"
},
responseType: "arraybuffer"
})
return images.data
}
async function check_nsfw(buffer) {
let _model = await load_model()
const convert = async (img) => {
// Decoded image in UInt8 Byte array
const image = await jpegjs.decode(img, { useTArray: true })
const numChannels = 3
const numPixels = image.width * image.height
const values = new Int32Array(numPixels * numChannels)
for (let i = 0; i < numPixels; i++)
for (let c = 0; c < numChannels; ++c)
values[i * numChannels + c] = image.data[i * 4 + c]
return tfjs.tensor3d(values, [image.height, image.width, numChannels], 'int32')
}
const image = await convert(buffer)
const predictions = await _model.classify(image)
image.dispose();
const results = predictions.map(v => {
return {
class_name: v.className,
probability: v.probability,
probability_percent: (v.probability * 100).toFixed(2)
}
})
return results
}
async function load_model() {
return await nsfwjs.load()
} |