Facebook
From Aliester Crowley, 7 Months ago, written in JavaScript.
Embed
Download Paste or View Raw
Hits: 234
  1. const axios = require('axios');
  2.  
  3. module.exports = {
  4.   config: {
  5.     name: "imagine",
  6.     aliases: ["text2image"],
  7.     version: "3.0",
  8.     author: "Aliester Crowley",
  9.     countDown: 0,
  10.     role: 0,
  11.     shortDescription: {
  12.       en: 'Create AI Art from Text'
  13.     },
  14.     longDescription: {
  15.       en: "Transform text into stunning AI-generated art using stable diffusion models."
  16.     },
  17.     category: "image"
  18.   },
  19.  
  20.   onStart: async function ({ message, args }) {
  21.     const text = args.join(" ");
  22.     if (!text) {
  23.       return message.reply("Please provide a prompt along with a model number if desired.\n\nimagine {prompt}\nExample: imagine a beautiful girl\n\nimagine {prompt}:{model number}\nExample: imagine a beautiful girl:43\n\nSupported models:\n" +
  24.         "0. Absolute Reality V16\n" +
  25.         "1. Absolute Reality V181\n" +
  26.         "2. Analog Diffusion 1.0\n" +
  27.         "3. Anything V3.0 (Pruned)\n" +
  28.         "4. Anything V4.5 (Pruned)\n" +
  29.         "5. Anything V5 (PrtRE)\n" +
  30.         "6. AOM3A3 Orange Mix\n" +
  31.         "7. Children's Stories V13D\n" +
  32.         "8. Children's Stories V1 Semi-Real\n" +
  33.         "9. Children's Stories V1 Toon Anime\n" +
  34.         "10. Cyberrealistic V33\n" +
  35.         "11. Deliberate V2\n" +
  36.         "12. Dreamlike Anime 1.0\n" +
  37.         "13. Dreamlike Diffusion 1.0\n" +
  38.         "14. Dreamlike Photoreal 2.0\n" +
  39.         "15. Dreamshaper 6 (Baked VAE)\n" +
  40.         "16. Dreamshaper 7\n" +
  41.         "17. Dreamshaper 8\n" +
  42.         "18. Edge of Realism Eor V20\n" +
  43.         "19. Eimis Anime Diffusion V1\n" +
  44.         "20. Elldreth's Vivid Mix\n" +
  45.         "21. Epic Realism Natural Sin RC1VAE\n" +
  46.         "22. I Can't Believe It's Not Photography Seco\n" +
  47.         "23. Juggernaut Aftermath\n" +
  48.         "24. Lyriel V16\n" +
  49.         "25. Mechamix V10\n" +
  50.         "26. Meinamix Meina V9\n" +
  51.         "27. Meinamix Meina V11\n" +
  52.         "28. Open Journey V4\n" +
  53.         "29. Portrait Plus V1.0\n" +
  54.         "30. Realistic Vision V1.4 (Pruned, FP16)\n" +
  55.         "31. Realistic Vision V2.0\n" +
  56.         "32. Realistic Vision V4.0\n" +
  57.         "33. Realistic Vision V5.0\n" +
  58.         "34. Redshift Diffusion V10\n" +
  59.         "35. Rev Animated V122\n" +
  60.         "36. Run DiffusionFX 25D V10\n" +
  61.         "37. Run DiffusionFX V10\n" +
  62.         "38. SD V1.4\n" +
  63.         "39. V1.5 (Pruned, Emaonly)\n" +
  64.         "40. Shonin's Beautiful V10\n" +
  65.         "41. The Ally's Mix II (Churned)\n" +
  66.         "42. Timeless 1.0\n" +
  67.         "43. ToonYou Beta 6"
  68.       );
  69.     }
  70.  
  71.     let prompt, model;
  72.     if (text.includes(":")) {
  73.       const [promptText, modelText] = text.split(":").map((str) => str.trim());
  74.       prompt = promptText;
  75.       model = modelText;
  76.  
  77.       if (isNaN(model) || model < 0 || model > 43) {
  78.         return message.reply("❗ Invalid model number. Please specify a model number between 0 and 43.");
  79.       }
  80.     } else {
  81.       prompt = text;
  82.       model = "0";
  83.     }
  84.  
  85.     try {
  86.       message.reply("✅ Processing your prompt. Please wait...");
  87.       const API = `https://aliestercrowley.com/api/crowgen.php?model=${model}&prompt;=${encodeURIComponent(prompt)}`;
  88.       const responsePromise = axios.get(API, { responseType: "arraybuffer" });
  89.  
  90.       const timeoutPromise = new Promise((_, reject) => {
  91.         setTimeout(() => {
  92.           reject(new Error("Timeout: Processing took longer than 20 seconds."));
  93.         }, 20000);
  94.       });
  95.  
  96.       const response = await Promise.race([responsePromise, timeoutPromise]);
  97.  
  98.       if (response instanceof Error) {
  99.         throw response;
  100.       }
  101.  
  102.       const imageStream = await global.utils.getStreamFromURL(API);
  103.  
  104.       await message.reply({
  105.         attachment: imageStream
  106.       });
  107.     } catch (error) {
  108.       console.error(error);
  109.       if (error.message === "Timeout: Processing took longer than 20 seconds.") {
  110.         message.reply("❌ An error occurred while processing your prompt. Please try again later");
  111.       } else {
  112.         message.reply("❌ An error occurred while processing your prompt. Please try again later.");
  113.       }
  114.     }
  115.   }
  116. };
  117.