Skip to content

Commit

Permalink
removed reliance on persisting interactions
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron Fisher (S3840619) committed Aug 25, 2023
1 parent 68baf69 commit ff8e8ac
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
12 changes: 6 additions & 6 deletions bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ async def generate_alternatives_and_send(self, interaction, button):
images = await generate_alternatives(self.images[index], self.prompt, self.negative_prompt)
collage_path = create_collage(images)
final_message = f"{interaction.user.mention} here are your alternative images"
await interaction.followup.send(content=final_message, file=discord.File(fp=collage_path, filename='collage.png'), view=Buttons(self.prompt, self.negative_prompt, images))
await interaction.channel.send(content=final_message, file=discord.File(fp=collage_path, filename='collage.png'), view=Buttons(self.prompt, self.negative_prompt, images))

async def upscale_and_send(self, interaction, button):
index = int(button.label[1:]) - 1 # Extract index from label
Expand All @@ -123,19 +123,19 @@ async def upscale_and_send(self, interaction, button):
upscaled_image_path = f"./out/upscaledImage_{timestamp}.png"
upscaled_image.save(upscaled_image_path)
final_message = f"{interaction.user.mention} here is your upscaled image"
await interaction.followup.send(content=final_message, file=discord.File(fp=upscaled_image_path, filename='upscaled_image.png'))
await interaction.channel.send(content=final_message, file=discord.File(fp=upscaled_image_path, filename='upscaled_image.png'))

@discord.ui.button(label="Re-roll", style=discord.ButtonStyle.green, emoji="🎲", row=0)
async def reroll_image(self, interaction, btn):
await interaction.response.send_message(f"{interaction.user.mention} asked me to re-imagine \"{self.prompt}\", this shouldn't take too long...")
btn.disabled = True
await interaction.message.edit(view=self)
# Generate a new image with the same prompt
images = await generate_images(self.prompt,self.negative_prompt,interaction)
images = await generate_images(self.prompt,self.negative_prompt)

# Construct the final message with user mention
final_message = f"{interaction.user.mention} asked me to re-imagine \"{self.prompt}\", here is what I imagined for them."
await interaction.followup.send(content=final_message, file=discord.File(fp=create_collage(images), filename='collage.png'), view = Buttons(self.prompt,self.negative_prompt,images))
await interaction.channel.send(content=final_message, file=discord.File(fp=create_collage(images), filename='collage.png'), view = Buttons(self.prompt,self.negative_prompt,images))

@tree.command(name="imagine", description="Generate an image based on input text")
@app_commands.describe(prompt='Prompt for the image being generated')
Expand All @@ -145,11 +145,11 @@ async def slash_command(interaction: discord.Interaction, prompt: str, negative_
await interaction.response.send_message(f"{interaction.user.mention} asked me to imagine \"{prompt}\", this shouldn't take too long...")

# Generate the image and get progress updates
images = await generate_images(prompt,negative_prompt,interaction)
images = await generate_images(prompt,negative_prompt)

# Construct the final message with user mention
final_message = f"{interaction.user.mention} asked me to imagine \"{prompt}\", here is what I imagined for them."
await interaction.followup.send(content=final_message, file=discord.File(fp=create_collage(images), filename='collage.png'), view=Buttons(prompt,negative_prompt,images))
await interaction.channel.send(content=final_message, file=discord.File(fp=create_collage(images), filename='collage.png'), view=Buttons(prompt,negative_prompt,images))

# run the bot
client.run(TOKEN)
2 changes: 1 addition & 1 deletion imageGen.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ async def close(self):
if self.ws:
await self.ws.close()

async def generate_images(prompt: str,negative_prompt: str,interaction):
async def generate_images(prompt: str,negative_prompt: str):
with open(text2img_config, 'r') as file:
workflow = json.load(file)

Expand Down

0 comments on commit ff8e8ac

Please sign in to comment.