Skip to content

Commit

Permalink
image generation
Browse files Browse the repository at this point in the history
  • Loading branch information
artifishvr committed May 13, 2024
1 parent f7b2879 commit 5dc3c8f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
27 changes: 27 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ client.on("messageCreate", async message => {
return;
}

if (message.content.startsWith("%pic")) {
imageGen(message);
return;
}

let imageDetails = await imageRecognition(message)

// Send message to CharacterAI
Expand Down Expand Up @@ -205,6 +210,28 @@ async function imageRecognition(message) {
}
}

async function imageGen(message) {
const prompt = message.content.split(' ').slice(1).join(' ');

try {
let response = await fetch(`https://api.cloudflare.com/client/v4/accounts/${process.env.CF_ACCOUNT}/ai/run/@cf/bytedance/stable-diffusion-xl-lightning`, {
method: 'POST',
headers: {
'Authorization': `Bearer ${process.env.CF_TOKEN}`,
},
body: JSON.stringify({
prompt: `Spongebob taking a selfie, ${prompt}`
})
});
response = await response.arrayBuffer();
const imageBuffer = Buffer.from(response);
message.channel.send({ files: [imageBuffer] });
} catch (error) {
console.error(error);
return message.reply(`❌ Error in image generation! Try again later.`);
};
}

async function tts(message, text) {
const tts = new MsEdgeTTS();
await tts.setMetadata("en-US-AnaNeural", MsEdgeTTS.OUTPUT_FORMAT.AUDIO_24KHZ_96KBITRATE_MONO_MP3);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "spongegpt",
"version": "1.29.5",
"version": "1.30.0",
"description": "custom AI chatbot for discord",
"main": "index.js",
"type": "module",
Expand Down

0 comments on commit 5dc3c8f

Please sign in to comment.