Neon-AI commited on
Commit
d27cfac
·
verified ·
1 Parent(s): 03e5497

Update index.js

Browse files
Files changed (1) hide show
  1. index.js +7 -17
index.js CHANGED
@@ -5,13 +5,10 @@ const fs = require("fs");
5
  async function generateImage(text) {
6
 
7
  const browser = await puppeteer.launch({
8
- headless: true,
9
- executablePath: "/usr/bin/google-chrome",
10
- args: [
11
- "--no-sandbox",
12
- "--disable-setuid-sandbox"
13
- ]
14
- });
15
 
16
  const page = await browser.newPage();
17
 
@@ -28,23 +25,16 @@ async function generateImage(text) {
28
 
29
  console.log("Submitting form...");
30
 
31
- await Promise.all([
32
- page.click("#submit"),
33
- page.waitForNavigation({ waitUntil: "networkidle2" })
34
- ]);
35
 
36
  console.log("Waiting for generated image...");
37
 
38
- const imageSelector = ".result-image img";
39
-
40
- await page.waitForSelector(imageSelector, { timeout: 20000 });
41
 
42
- const imageUrl = await page.$eval(imageSelector, img => img.src);
43
 
44
  console.log("Image URL:", imageUrl);
45
 
46
- console.log("Downloading image...");
47
-
48
  const response = await axios.get(imageUrl, {
49
  responseType: "arraybuffer"
50
  });
 
5
  async function generateImage(text) {
6
 
7
  const browser = await puppeteer.launch({
8
+ headless: true,
9
+ executablePath: "/usr/bin/google-chrome",
10
+ args: ["--no-sandbox", "--disable-setuid-sandbox"]
11
+ });
 
 
 
12
 
13
  const page = await browser.newPage();
14
 
 
25
 
26
  console.log("Submitting form...");
27
 
28
+ await page.click("#submit");
 
 
 
29
 
30
  console.log("Waiting for generated image...");
31
 
32
+ await page.waitForSelector(".thumbnail img", { timeout: 60000 });
 
 
33
 
34
+ const imageUrl = await page.$eval(".thumbnail img", el => el.src);
35
 
36
  console.log("Image URL:", imageUrl);
37
 
 
 
38
  const response = await axios.get(imageUrl, {
39
  responseType: "arraybuffer"
40
  });