-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from shin202/feature/AI-art-generator-and-new-…
…chat-mode BREAKING CHANGE: supported image generator with Stable Diffusion AI and add new chat mode that help users create prompt
- Loading branch information
Showing
17 changed files
with
242 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import {IReplicateModel, ReplicateModel} from "../types/types"; | ||
import Replicate from "replicate"; | ||
|
||
const REPLICATE_API_TOKEN = process.env.REPLICATE_API_TOKEN; | ||
class ReplicateService { | ||
private REPLICATE_MODELS: IReplicateModel = { | ||
stableDiffusion: { | ||
owner: "stability-ai", | ||
name: "stable-diffusion", | ||
version: "db21e45d3f7023abc2a46ee38a23973f6dce16bb082a930b0c49861f96d1e5bf" | ||
}, | ||
dreamShaper: { | ||
owner: "cjwbw", | ||
name: "dreamshaper", | ||
version: "ed6d8bee9a278b0d7125872bddfb9dd3fc4c401426ad634d8246a660e387475b" | ||
}, | ||
openJourney: { | ||
owner: "prompthero", | ||
name: "openjourney", | ||
version: "9936c2001faa2194a261c01381f90e65261879985476014a0a37a334593a05eb" | ||
}, | ||
portraitPlus: { | ||
owner: "cjwbw", | ||
name: "portraitplus", | ||
version: "629a9fe82c7979c1dab323aedac2c03adaae2e1aecf6be278a51fde0245e20a4" | ||
}, | ||
anythingV3: { | ||
owner: "cjwbw", | ||
name: "anything-v3-better-vae", | ||
version: "09a5805203f4c12da649ec1923bb7729517ca25fcac790e640eaa9ed66573b65" | ||
}, | ||
pastelMix: { | ||
owner: "elct9620", | ||
name: "pastel-mix", | ||
version: "ba8b1f407cd6418fa589ca73e5c623c081600ecff19f7fc3249fa536d762bb29" | ||
} | ||
} | ||
|
||
public generateImage = async (prompt: string, negative_prompt: string, model: ReplicateModel) => { | ||
const replicate = new Replicate({ | ||
auth: REPLICATE_API_TOKEN!, | ||
}); | ||
|
||
const {owner, name, version} = this.REPLICATE_MODELS[model]; | ||
|
||
prompt = model === ReplicateModel.OpenJourney ? `mdjrny-v4 style ${prompt}` : | ||
model === ReplicateModel.PortraitPlus ? `portrait+ style ${prompt}` : prompt; | ||
|
||
const input = { | ||
prompt: prompt, | ||
negative_prompt: negative_prompt, | ||
num_outputs: 4 | ||
} | ||
|
||
const response = await replicate.run(`${owner}/${name}:${version}`, { | ||
input: input, | ||
}); | ||
|
||
return response as string[]; | ||
} | ||
} | ||
|
||
export default new ReplicateService(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import {AttachmentBuilder, CommandInteractionOptionResolver, SlashCommandBuilder} from "discord.js"; | ||
import {ISlashCommand, ReplicateModel} from "../types/types"; | ||
import ReplicateService from "../services/ReplicateService"; | ||
|
||
const command: ISlashCommand = { | ||
command: new SlashCommandBuilder() | ||
.setName("draw") | ||
.setDescription("Using prompt to generate image with SD AI") | ||
.addStringOption(option => | ||
option.setName("model") | ||
.setDescription("Model use for generate.") | ||
.setRequired(true) | ||
.addChoices( | ||
{name: "Stable Diffusion", value: ReplicateModel.StableDiffusion}, | ||
{name: "Open Journey", value: ReplicateModel.OpenJourney}, | ||
{name: "Dream Shaper", value: ReplicateModel.DreamShaper}, | ||
{name: "Portrait Plus", value: ReplicateModel.PortraitPlus}, | ||
{name: "Anything V3", value: ReplicateModel.AnythingV3}, | ||
{name: "Pastel Mix", value: ReplicateModel.PastelMix} | ||
) | ||
) | ||
.addStringOption(option => | ||
option.setName("prompt") | ||
.setDescription("Your prompt") | ||
.setRequired(true) | ||
) | ||
.addStringOption(option => | ||
option.setName("negative_prompt") | ||
.setDescription("Things that you don't want to see in the output.") | ||
.setRequired(false) | ||
), | ||
execute: async (interaction) => { | ||
const model = (interaction.options as CommandInteractionOptionResolver).get("model"); | ||
const prompt = (interaction.options as CommandInteractionOptionResolver).getString("prompt"); | ||
const negative_prompt = (interaction.options as CommandInteractionOptionResolver).getString("negative_prompt") || ""; | ||
|
||
|
||
await interaction.deferReply(); | ||
const images = await ReplicateService.generateImage(prompt!, negative_prompt, model?.value as ReplicateModel); | ||
const files = images.map(image => new AttachmentBuilder(image)); | ||
await interaction.editReply({ | ||
content: `${prompt}`, | ||
files: files, | ||
}); | ||
}, | ||
cooldown: 300 | ||
} | ||
|
||
export default command; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.