Skip to content

Commit

Permalink
bug 🐛: Fixed circular dep
Browse files Browse the repository at this point in the history
  • Loading branch information
Geoffery10 committed Sep 8, 2024
1 parent bed22ca commit 4814ef1
Showing 1 changed file with 29 additions and 31 deletions.
60 changes: 29 additions & 31 deletions buttons.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import discord
from discord import ui
from embed_decode import decode
from sd_requests import sd_request
from models.ImageRequest import ImageRequest
from models.RequestTypes import RequestTypes
import txt2img


class TryAgain(discord.ui.Button):
def __init__(self):
Expand All @@ -27,9 +28,8 @@ async def callback(self, interaction: discord.Interaction):
print('Payload: ')
print(img_request.get_payload())


# Send request to stable diffusion
await sd_request(interaction, img_request)
await txt2img.process_request(interaction=interaction, img_request=img_request, defer=True)
# Respond to the interaction with nothing incase it fails
try:
await interaction.response.send_message("")
Expand All @@ -55,14 +55,15 @@ async def callback(self, interaction: discord.Interaction):
embed.set_image(url="")

# add a new field to the embed saying that the image has been deleted
embed.add_field(name="Image deleted", value="This image has been deleted. Restoring is not yet possible.")
embed.add_field(
name="Image deleted", value="This image has been deleted. Restoring is not yet possible.")

# Send the embed
await interaction.followup.send(embed=embed)
except Exception as e:
print(e)
await interaction.followup.send("Something went wrong while deleting the image. Please try again later.", ephemeral=True)

try:
await interaction.response.send_message("")
except:
Expand Down Expand Up @@ -122,46 +123,43 @@ def __init__(self, img_request: ImageRequest, *args, **kwargs):
self.width.default = str(int(img_request.width))
self.height.default = str(int(img_request.height))


prompt = ui.TextInput(label='Prompt',
style=discord.TextStyle.paragraph,
placeholder='Enter your prompt here',
min_length=1,
max_length=2000,
required=True)
negative_prompt = ui.TextInput(label='Negative Prompt',
style=discord.TextStyle.paragraph,
placeholder='Enter your negative prompt here',
min_length=0,
max_length=2000,
required=False)
# Steps integer input
style=discord.TextStyle.paragraph,
placeholder='Enter your negative prompt here',
min_length=0,
max_length=2000,
required=False)
# Steps integer input
steps = ui.TextInput(label='Steps',
style=discord.TextStyle.short,
placeholder='Enter the number of steps',
min_length=1,
max_length=2,
required=True)
placeholder='Enter the number of steps',
min_length=1,
max_length=2,
required=True)
# width integer input
width = ui.TextInput(label='Width',
style=discord.TextStyle.short,
placeholder='Enter the width of the image',
min_length=1,
max_length=4,
required=True)
style=discord.TextStyle.short,
placeholder='Enter the width of the image',
min_length=1,
max_length=4,
required=True)
# height integer input
height = ui.TextInput(label='Height',
style=discord.TextStyle.short,
placeholder='Enter the height of the image',
min_length=1,
max_length=4,
required=True)


style=discord.TextStyle.short,
placeholder='Enter the height of the image',
min_length=1,
max_length=4,
required=True)

async def on_submit(self, interaction: discord.Interaction):
# Get the values from the text inputs

img_request = ImageRequest()
img_request.set_prompt(str(self.prompt.value))
img_request.set_negative_prompt(str(self.negative_prompt.value))
Expand All @@ -170,15 +168,15 @@ async def on_submit(self, interaction: discord.Interaction):
img_request.set_height(int(self.height.value))
img_request.set_request_type(RequestTypes.TXT2IMG)
img_request.set_seed(-1)

# Acknowledge the interaction
try:
await interaction.response.defer()
except:
pass

# Send the request to stable diffusion
await sd_request(interaction, img_request, defer=True)
await txt2img.process_request(interaction=interaction, img_request=img_request, defer=True)

async def on_error(self, interaction: discord.Interaction, error):
await interaction.response.send_message(f'An error occurred: {error}', ephemeral=True)

0 comments on commit 4814ef1

Please sign in to comment.