mirror of
https://gitlab.com/bignutty/labscore.git
synced 2025-06-10 07:03:08 -04:00
stable diffusion
This commit is contained in:
parent
640bcc61f9
commit
4408cf362f
1 changed files with 61 additions and 0 deletions
61
commands/message/image/stablediffusion.js
Normal file
61
commands/message/image/stablediffusion.js
Normal file
|
@ -0,0 +1,61 @@
|
|||
const { createEmbed } = require("../../../labscore/utils/embed");
|
||||
const { editOrReply } = require("../../../labscore/utils/message");
|
||||
|
||||
const superagent = require('superagent');
|
||||
|
||||
module.exports = {
|
||||
name: 'stability',
|
||||
label: 'query',
|
||||
aliases: ['genimg'],
|
||||
metadata: {
|
||||
description: 'Uses Stable Diffusion to generate four images from a text prompt.',
|
||||
description_short: 'Stable Diffusion image generation',
|
||||
examples: ['genimg Otter, digital art'],
|
||||
category: 'image',
|
||||
usage: 'stability <text>'
|
||||
},
|
||||
ratelimit: {
|
||||
type: 'guild',
|
||||
limit: 1,
|
||||
duration: 5000
|
||||
},
|
||||
run: async (context, args) => {
|
||||
let response = await editOrReply(context, { embeds: [createEmbed("loading", context, `Synthesizing images...`)] })
|
||||
|
||||
let noticeTimer = setTimeout(()=>{
|
||||
let emb = createEmbed("loading", context, `Synthesizing images...`)
|
||||
emb.footer = {
|
||||
text: "This might take several minutes to complete."
|
||||
};
|
||||
response.edit({ embeds: [ emb ] });
|
||||
}, 45000)
|
||||
|
||||
try{
|
||||
let t = Date.now();
|
||||
|
||||
let img = await superagent.get(`${process.env.STABLE_DIFFUSION_SERVER}/generate`)
|
||||
.query({
|
||||
prompt: args.query
|
||||
})
|
||||
|
||||
clearTimeout(noticeTimer)
|
||||
|
||||
if(img.body.message) return await response.edit({embeds:[createEmbed("warning", context, img.body.message)]})
|
||||
|
||||
let embeds = [];
|
||||
let files = [];
|
||||
|
||||
for(let i = 0; i < 4; i++){
|
||||
embeds.push(createEmbed("default", context, {image: {url:`attachment://stability${i}.jpeg`}, url: `https://example.com`, footer: { iconUrl: `https://cdn.discordapp.com/avatars/${context.application.id}/${context.application.icon}.png?size=256`, text: `${context.application.name} • Took ${((Date.now() - t) / 1000).toFixed(2)}s` }}))
|
||||
files.push({
|
||||
filename: `stability${i}.jpeg`,
|
||||
value: Buffer.from(img.body.images[i].replace('data:image/jpeg;base64,',''), 'base64')
|
||||
})
|
||||
}
|
||||
|
||||
await response.edit({ embeds, files })
|
||||
}catch(e){
|
||||
await response.edit({embeds:[createEmbed("error", context, `Image generation failed.`)]})
|
||||
}
|
||||
},
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue