Spaces:
Paused

File size: 3,276 Bytes
64e4ce0
8d63bbb
64e4ce0
8d63bbb
1fe5132
2188b65
64e4ce0
1fe5132
d1bc146
8d63bbb
 
d1bc146
8d63bbb
d1bc146
 
 
 
8d63bbb
 
 
d1bc146
 
8d63bbb
 
d1bc146
 
8d63bbb
 
 
 
 
 
 
d1bc146
 
 
8d63bbb
 
 
d1bc146
 
8d63bbb
 
 
 
 
64e4ce0
8d63bbb
64e4ce0
 
506f24e
8d63bbb
506f24e
64e4ce0
ed23b0f
64e4ce0
 
2188b65
d1bc146
 
8d63bbb
 
d05e2a0
8d63bbb
d1bc146
8d63bbb
d1bc146
506f24e
d1bc146
8d63bbb
 
 
d1bc146
 
8d63bbb
d1bc146
8d63bbb
 
 
 
d1bc146
 
 
8d63bbb
d1bc146
 
1fe5132
a24f9b7
d1bc146
 
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
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());