Advertisement
samiroexpikachu

Imagine

Apr 1st, 2024 (edited)
312
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. global.api = {
  2.   samirApi: "https://apis-samir.onrender.com"
  3. };
  4.  
  5. const axios = require('axios');
  6.  
  7. module.exports = {
  8.   config: {
  9.     name: "imagine",
  10.     aliases: ["sdi"],
  11.     author: "Samir Œ/ Architectdevs",
  12.     version: "1.0",
  13.     countDown: 10,
  14.     role: 0,
  15.     shortDescription: "Generates an image from a text description",
  16.     longDescription: "Generates an image from a text description",
  17.     category: "ai",
  18.     guide: {
  19.       en: "{pn} prompt | model \n Models:\n 1: animagineXL \n 2: dreamshaperXL\n 3: dynavisionXL \n 4: juggernautXL \n 5: realismEngineSDXL \n 6:  realvisxlV40 \n 7: sd_xl_base \n 8: inpaint \n 9:turbovisionXL",
  20.     }
  21.   },
  22.  
  23.   langs: {
  24.     en: {
  25.       loading: "Generating image, please wait...",
  26.       error: "An error occurred, please try again later"
  27.     }
  28.   },
  29.  
  30.   onStart: async function ({ event, message, getLang, threadsData, api, args }) {
  31.     const { threadID } = event;
  32.  
  33.     const info = args.join(" ");
  34.     if (!info) {
  35.       return message.reply(`- baka, type your imagination!`);
  36.     } else {
  37.       const msg = info.split("|");
  38.       const text = msg[0];
  39.       const model = msg[1] || '1';
  40.       const timestamp = new Date().getTime();
  41.  
  42.       try {
  43.         let msgSend = message.reply(getLang("loading"));
  44.         const { data } = await axios.get(
  45.           `${global.api.samirApi}/sdxl/generate?prompt=${text}&model=${model}`
  46.         );
  47.  
  48.         const imageUrls = data.imageUrls[0];
  49.         const shortLink = await global.utils.uploadImgbb(imageUrls);
  50.        
  51.         let fUrl = shortLink.image.url;
  52.         await message.unsend((await msgSend).messageID);
  53.         if (imageUrls) {
  54.           message.reply({
  55.             body: `Here's your AI generated image \n prompt "${text}" \n HD download Link: ${fUrl}`,
  56.            attachment: await global.utils.getStreamFromURL(imageUrls)
  57.          });
  58.        } else {
  59.          throw new Error("Failed to fetch the generated image. Contact the administration group to resolve the issue. Group link: https://www.facebook.com/groups/761805065901067/?ref=share");
  60.        }
  61.      } catch (err) {
  62.        console.error(err);
  63.        return message.reply(getLang("error"));
  64.      }
  65.    }
  66.  }
  67. };
  68.  
  69. function getModelName(model) {
  70.  switch (model) {
  71.    case '1': return "animagineXL";
  72.    case '2': return "dreamshaperXL";
  73.    case '3': return "dynavisionXL";
  74.    case '4': return "juggernautXL";
  75.    case '5': return "realismEngineSDXL";
  76.    case '6': return "realvisxlV40";
  77.    case '7': return "sd_xl_base";
  78.    case '8': return "inpaint";
  79.    case '9': return "turbovisionXL";
  80.    default: return "animagineXL";
  81.  }
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement