UNPKG

notmebotz-tools

Version:

Sebuah Tools yang berfungsi untuk mendownload Video atau Foto dari media sosial, serta sebagai tools yang berguna untuk aplikasi kamu seperti untuk BOT

85 lines (74 loc) 3.25 kB
const WebSocket = require("ws"); const axios = require("axios"); const sharp = require("sharp"); const up = require('../../lib/uploadFile') async function img2anime(imgUrl, options = {}) { const { prompt = "(masterpiece), best quality, anime artwork", negative_prompt = "(low quality, worst quality:1.4), text, watermark", strength = 0.6, } = options; const res = await axios.get(imgUrl, { responseType: "arraybuffer" }); const imgBuffer = Buffer.from(res.data); const b64Img = imgBuffer.toString("base64"); const sessHash = Math.random().toString(36).slice(2); return new Promise((resolve, reject) => { const ws = new WebSocket("wss://pixnova.ai/demo-photo2anime/queue/join", { headers: { Origin: "https://pixnova.ai", "User-Agent": "Mozilla/5.0", Connection: "Upgrade", Upgrade: "websocket", "Sec-WebSocket-Version": "13", }, }); ws.on("message", async (data) => { const msg = JSON.parse(data.toString()); if (msg.msg === "send_hash") { ws.send(JSON.stringify({ session_hash: sessHash })); } else if (msg.msg === "send_data") { ws.send( JSON.stringify({ data: { negative_prompt, prompt, source_image: `data:image/jpeg;base64,${b64Img}`, strength, }, }) ); } else if (msg.msg === "process_completed" && msg.success) { const resultUrl = `https://oss-global.pixnova.ai/${msg.output.result[0]}`; ws.close(); // Ambil hasilnya dan ubah ke JPEG dalam buffer const resultRes = await axios.get(resultUrl, { responseType: "arraybuffer" }); const webpBuffer = Buffer.from(resultRes.data); const jpegBuffer = await sharp(webpBuffer).jpeg().toBuffer(); resolve(jpegBuffer); } else if (msg.msg === "process_completed") { ws.close(); reject("Processing failed"); } }); ws.on("error", (err) => reject(err)); }); } async function i2z(imgUrl) { const jpegBuffer = await img2anime(imgUrl, { prompt: `Image to zombie detect the image what is this object like human or animals turn into zombie , cinematic, hyper real, photorealistic, volumetric lighting, cinematic in a morbid dark brutalist dystopian futuristic city, octane render Image to zombie detect the image what is this object like human or animals turn into zombie zombies in a zombie apocalypse, no crop, hyper realistic, cinematic look, high resolution, eerie atmosphere, —aspect 4:3 Image to zombie detect the image what is this object like human or animals turn into zombie and walk through walls full of eyeballs Image to zombie detect the image what is this object like human or animals turn into zombie and start screaming all around a place where there is a lot of people inside of it, horror, horror Image to zombie detect the image what is this object like human or animals turn into zombie human, drool dripping oozing off human skin Image to zombie detect the image what is this object like human or animals turn into zombie —ar 9:16`, negative_prompt: "blurry, deformed hands, 3d render, text, error image, random image color, error color", strength: 0.8, }); let za = await up(jpegBuffer) return { author: "Herza", status: 200, img_url: za } } module.exports = { i2z }