Skip to content

Commit 559833f

Browse files
committed
Upscale
1 parent f948004 commit 559833f

File tree

4 files changed

+68
-4
lines changed

4 files changed

+68
-4
lines changed

src/embeds/imageResult.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export default function(queueItem: QueueItem): BotEmbed {
4646
{name: 'Seed', value: codeBlock(queueItem.seed.toString()), inline: false},
4747
{name: 'Prompt ID', value: codeBlock(queueItem.uuid), inline: false}
4848
])
49-
.setImage(`attachment://stable-confusion_${queueItem.uuid}_upscale.png`)
49+
.setImage(`attachment://stable-confusion_${queueItem.uuid}_upscaled.jpeg`)
5050
]
5151
break
5252

@@ -87,6 +87,7 @@ export default function(queueItem: QueueItem): BotEmbed {
8787
])
8888
]
8989
break
90+
9091
case QueueItemType.Regenerated:
9192
case QueueItemType.Default:
9293
default:

src/embeds/imageSelectPrompt.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export default function(queueItem: QueueItem): BotEmbed {
77
new EmbedBuilder()
88
.setColor('#6aaa64')
99
.setTitle('Pick An Image')
10-
.setDescription('Select an image with the dropdown below.')
10+
.setDescription('Select an image with the dropdown below.\n\nClick the dropdown and wait a second or two before selecting your choice. If you see `Interaction Failed` after waiting, this is a bug and can be ignored.')
1111
.setTimestamp()
1212
.setImage(`attachment://stable-confusion_${queueItem.uuid}_collage.png`)
1313
],

src/events/buttonImagineUpscale.ts

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import { AttachmentBuilder, Interaction } from "discord.js"
2+
import { isEmpty, isNil } from "ramda"
3+
import { Bot } from '../bot'
4+
import { BotEvent, QueueItemType } from '../types'
5+
6+
import imageResult from "../embeds/imageResult"
7+
import imageSelectPrompt from "../embeds/imageSelectPrompt"
8+
9+
const botEvent: BotEvent = {
10+
name: 'Button Handler - Imagine Upscale',
11+
event: 'interactionCreate',
12+
once: false,
13+
async execute(bot: Bot, interaction: Interaction) {
14+
if (!interaction.isButton() && !interaction.isSelectMenu()) return
15+
if (interaction.customId === 'image-select-prompt-upscaled' && interaction.isSelectMenu()) {
16+
// TODO: Lock this action to user who triggered prompt?
17+
18+
const referenceQueueItem = bot.findLatestQueueItemReferenceByMessageID(interaction.message.id)
19+
if (isNil(referenceQueueItem) || isNil(referenceQueueItem.imageData) || isEmpty(referenceQueueItem.imageData)) {
20+
await interaction.reply({
21+
ephemeral: true,
22+
content: 'There is no reference of this image generation. Most likely, this generation is too old to modify.'
23+
})
24+
return
25+
}
26+
27+
// We can cheat here, we don't really need to generate anything. We just take the image out of the collage.
28+
// Maybe we add ai upscaling here in the future?
29+
const [selectedImage] = interaction.values
30+
const imageResultEmbed = imageResult({...referenceQueueItem, type: QueueItemType.Upscaled})
31+
32+
const file = new AttachmentBuilder(referenceQueueItem.imageData[+selectedImage], {
33+
name: `stable-confusion_${referenceQueueItem.uuid}_upscaled.jpeg`,
34+
description: referenceQueueItem.prediction.prompt
35+
})
36+
37+
await referenceQueueItem.interaction.editReply({
38+
embeds: imageResultEmbed.embeds,
39+
components: imageResultEmbed.components,
40+
files: [file]
41+
})
42+
} else if (interaction.customId === 'button-imagine-result-upscale' && interaction.isButton()) {
43+
const referenceQueueItem = bot.findLatestQueueItemReferenceByMessageID(interaction.message.id)
44+
if (isNil(referenceQueueItem)) {
45+
await interaction.reply({
46+
ephemeral: true,
47+
content: 'There is no reference of this image generation. Most likely, this generation is too old to modify.'
48+
})
49+
return
50+
}
51+
52+
const imageSelectPromptEmbed = imageSelectPrompt({...referenceQueueItem, type: QueueItemType.Upscaled})
53+
54+
await referenceQueueItem.interaction.editReply({
55+
embeds: imageSelectPromptEmbed.embeds,
56+
components: imageSelectPromptEmbed.components
57+
})
58+
}
59+
return
60+
}
61+
}
62+
63+
export default botEvent

src/events/buttonImagineVariantOf.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Interaction } from "discord.js"
2-
import { compose, isEmpty, isNil } from "ramda"
2+
import { isEmpty, isNil } from "ramda"
33
import { Bot } from '../bot'
44
import { BotEvent, QueueItem, QueueItemType } from '../types'
55
import imageSelectPrompt from '../embeds/imageSelectPrompt'
@@ -23,7 +23,7 @@ const botEvent: BotEvent = {
2323
})
2424
return
2525
}
26-
26+
2727
const [selectedImage] = interaction.values
2828

2929
// Ensure PNG

0 commit comments

Comments
 (0)