Spaces:
Paused

MarkusSpace / Bot.js
ChatMarkus1's picture
Update Bot.js
d1bc146 verified
Raw History Blame Contribute Delete
3.28 kB
import express from "express";
import puppeteer from "puppeteer";
import { spawn } from "child_process";
import https from "https";
const app = express();
const PORT = 7860;
// 🕵️ GRADIO BRIDGE (More stable than /v1/ for free vision)
async function callVision(b64) {
return new Promise((resolve) => {
// Gradio/HuggingFace style payload for Umint/LLM7
const payload = JSON.stringify({
data: [
{ "name": "s.jpg", "data": `data:image/jpeg;base64,${b64}` },
"Task: I am on a Windows VPS. Locate the Start button or browser. Output ONLY: CLICK X,Y"
]
});
const req = https.request({
hostname: 'umint-ai.hf.space', // 🚀 The actual engine behind the links
path: '/run/predict',
method: 'POST',
headers: {
'Content-Type': 'application/json'
// No Authorization header needed for Gradio predict routes
}
}, (res) => {
let body = '';
res.on('data', d => body += d);
res.on('end', () => {
try {
const data = JSON.parse(body);
// Gradio returns data in an array
const reply = data.data[0] || "WAIT";
resolve(reply.trim());
} catch { resolve("WAIT"); }
});
});
req.setTimeout(10000, () => { req.destroy(); resolve("WAIT"); });
req.on('error', () => resolve("WAIT"));
req.write(payload); req.end();
});
}
async function startBot() {
console.log(">>> [BOOT]: Launching Browser...");
const browser = await puppeteer.launch({
executablePath: process.env.PUPPETEER_EXECUTABLE_PATH || '/usr/bin/chromium',
headless: "new",
args: ["--no-sandbox", "--disable-setuid-sandbox", "--disable-dev-shm-usage"]
});
const page = await browser.newPage();
await page.setViewport({ width: 1280, height: 720 });
// 📺 TWITCH (Ensure key is correct)
spawn("ffmpeg", ["-f", "x11grab", "-s", "1280x720", "-r", "30", "-i", ":99.0", "-vcodec", "libx264", "-preset", "ultrafast", "-pix_fmt", "yuv420p", "-f", "flv", "rtmp://live.twitch.tv/app/live_1469793213_Vb3SfqZyxc5KQugU8fZuMIdITIUwAf"]);
console.log(">>> [NAVIGATING]: Loading AppOnFly...");
await page.goto("https://app.apponfly.com/trial", { waitUntil: 'networkidle2' });
// ⏱️ REDIRECT WAIT
try {
await page.waitForFunction(() => window.location.href.includes('trial') && document.querySelector('canvas'), { timeout: 30000 });
console.log(">>> [SUCCESS]: Trial redirect detected.");
} catch (e) { console.log(">>> [WARN]: Proceeding to loop..."); }
setInterval(async () => {
try {
// 📸 Higher quality for the AI to actually see buttons
const b64 = await page.screenshot({ encoding: "base64", type: "jpeg", quality: 60 });
const decision = await callVision(b64);
console.log(">>> [AI]:", decision);
if (decision.includes("CLICK")) {
const coords = decision.match(/\d+/g);
if (coords && coords.length >= 2) {
await page.mouse.click(parseInt(coords[0]), parseInt(coords[1]));
}
}
} catch (err) { console.log(">>> [LOOP ERR]:", err.message); }
}, 12000); // ⏱️ Slightly faster loop
}
app.get("/", (req, res) => res.send("🤖 Markus Vision Active"));
app.listen(PORT, "0.0.0.0", () => startBot());