Compare commits
No commits in common. "c752eebd9a94f197674da6676c72a7cf39e016a7" and "9e621a88e8052c4b96cade5a26f92d702b82421b" have entirely different histories.
c752eebd9a
...
9e621a88e8
3 changed files with 2 additions and 79 deletions
|
@ -1,76 +0,0 @@
|
||||||
import { SlashCommandBuilder, EmbedBuilder } from 'discord.js';
|
|
||||||
import fetch from 'node-fetch';
|
|
||||||
import fs from 'node:fs';
|
|
||||||
import os from 'node:os';
|
|
||||||
|
|
||||||
const { stableHordeApi, stableHordeID } = process.env;
|
|
||||||
|
|
||||||
export default {
|
|
||||||
data: new SlashCommandBuilder()
|
|
||||||
.setName('img2img')
|
|
||||||
.setDescription('AI generated image with stable diffusion (If credit are low it may be slow)')
|
|
||||||
.addAttachmentOption(option =>
|
|
||||||
option.setName('image')
|
|
||||||
.setDescription('Image you want to modify')
|
|
||||||
.setRequired(true))
|
|
||||||
.addStringOption(option =>
|
|
||||||
option.setName('prompt')
|
|
||||||
.setDescription('What do you want the AI to generate?')
|
|
||||||
.setRequired(true)),
|
|
||||||
category: 'AI',
|
|
||||||
async execute(interaction, args, client) {
|
|
||||||
await interaction.deferReply();
|
|
||||||
fetch(args.image.url)
|
|
||||||
.then((res) => {
|
|
||||||
const dest = fs.createWriteStream(`${os.tmpdir()}/${args.image.name}`);
|
|
||||||
res.body.pipe(dest);
|
|
||||||
dest.on('finish', () => {
|
|
||||||
const b64Image = fs.readFileSync(`${os.tmpdir()}/${args.image.name}`, { encoding: 'base64' });
|
|
||||||
generate(interaction, args.prompt, b64Image, client);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
async function generate(i, prompt, b64Img) {
|
|
||||||
const body = {
|
|
||||||
prompt: prompt,
|
|
||||||
params: {
|
|
||||||
n: 1,
|
|
||||||
width: 512,
|
|
||||||
height: 512,
|
|
||||||
},
|
|
||||||
cfg_scale: 5,
|
|
||||||
use_gfpgan: true,
|
|
||||||
use_real_esrgan: true,
|
|
||||||
use_ldsr: true,
|
|
||||||
use_upscaling: true,
|
|
||||||
steps: 50,
|
|
||||||
nsfw: i.channel.nsfw ? true : false,
|
|
||||||
censor_nsfw: i.channel.nsfw ? true : false,
|
|
||||||
source_image: b64Img,
|
|
||||||
};
|
|
||||||
|
|
||||||
const fetchParameters = {
|
|
||||||
method: 'post',
|
|
||||||
body: JSON.stringify(body),
|
|
||||||
headers: { 'Content-Type': 'application/json', 'apikey': stableHordeApi },
|
|
||||||
};
|
|
||||||
|
|
||||||
let response = await fetch('https://stablehorde.net/api/v2/generate/sync', fetchParameters);
|
|
||||||
|
|
||||||
response = await response.json();
|
|
||||||
|
|
||||||
let creditResponse = await fetch(`https://stablehorde.net/api/v2/users/${stableHordeID}`);
|
|
||||||
creditResponse = await creditResponse.json();
|
|
||||||
|
|
||||||
const stableEmbed = new EmbedBuilder()
|
|
||||||
.setColor(i.member ? i.member.displayHexColor : 'Navy')
|
|
||||||
.setTitle(prompt)
|
|
||||||
.setURL('https://aqualxx.github.io/stable-ui/')
|
|
||||||
.setFooter({ text: `**Credit left: ${creditResponse.kudos}** Seed: ${response.generations[0].seed} worker ID: ${response.generations[0].worker_id} worker name: ${response.generations[0].worker_name}` });
|
|
||||||
|
|
||||||
fs.writeFileSync(`${os.tmpdir()}/${i.id}.png`, response.generations[0].img, 'base64');
|
|
||||||
|
|
||||||
await i.editReply({ embeds: [stableEmbed], files: [`${os.tmpdir()}/${i.id}.png`] });
|
|
||||||
}
|
|
|
@ -7,13 +7,13 @@ const { stableHordeApi, stableHordeID } = process.env;
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
data: new SlashCommandBuilder()
|
data: new SlashCommandBuilder()
|
||||||
.setName('txt2img')
|
.setName('stablediffusion')
|
||||||
.setDescription('AI generated image with stable diffusion (If credit are low it may be slow)')
|
.setDescription('AI generated image with stable diffusion (If credit are low it may be slow)')
|
||||||
.addStringOption(option =>
|
.addStringOption(option =>
|
||||||
option.setName('prompt')
|
option.setName('prompt')
|
||||||
.setDescription('What do you want the AI to generate?')
|
.setDescription('What do you want the AI to generate?')
|
||||||
.setRequired(true)),
|
.setRequired(true)),
|
||||||
category: 'AI',
|
category: 'fun',
|
||||||
async execute(interaction, args, client) {
|
async execute(interaction, args, client) {
|
||||||
await interaction.deferReply();
|
await interaction.deferReply();
|
||||||
generate(interaction, args.prompt, client);
|
generate(interaction, args.prompt, client);
|
|
@ -145,7 +145,6 @@ export default {
|
||||||
admin: '⚡\u2000Admin',
|
admin: '⚡\u2000Admin',
|
||||||
owner: '🛠️\u2000Owner',
|
owner: '🛠️\u2000Owner',
|
||||||
voice: '🗣️\u2000Voice',
|
voice: '🗣️\u2000Voice',
|
||||||
AI: '🦾\u2000AI',
|
|
||||||
}[category];
|
}[category];
|
||||||
|
|
||||||
embed.addFields({ name: title, value: `\`${object[category].join('` `')}\`` });
|
embed.addFields({ name: title, value: `\`${object[category].join('` `')}\`` });
|
||||||
|
|
Loading…
Reference in a new issue