From 66ca3b6310d0c4275892971ac7e5f29ac68d59d5 Mon Sep 17 00:00:00 2001 From: 7trail <72806227+7trail@users.noreply.github.com> Date: Tue, 5 Sep 2023 18:34:11 -0500 Subject: [PATCH] Added regen buttons to neural --- neural.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/neural.py b/neural.py index 8c6d3b1..05e570b 100644 --- a/neural.py +++ b/neural.py @@ -6,6 +6,19 @@ from PIL import Image import discord import re +class ViewWithButton(discord.ui.View): + channel = 0 + prompt = "test" + def __init__(self, *, timeout=180, parameter, p2): + super().__init__(timeout=timeout) + self.channel = parameter + self.prompt = p2 + @discord.ui.button(label="Regenerate!",style=discord.ButtonStyle.green) + async def blurple_button(self,button:discord.ui.Button,interaction:discord.Interaction): + embedVar = discord.Embed(title=f'Regeneration Started', description=f"Prompt: '{self.prompt}'", color=0xff0000) + #await interaction.response.send_message(embed=embedVar) + await Generate(self.prompt,self.channel) + def create_image(links): images=[] @@ -67,13 +80,21 @@ async def Generate(prompt, channel, count=2, negativePrompt = "",size="square"): data2 = response2.json() if data2["status"]["isReady"]: links = [] + view = ViewWithButton(parameter=channel,p2=prompt) # Establish an instance of the discord.ui.View class + + #e = discord.Embed(title="Results are in!") for i in range(data2["input"]["amount"]): data3 = data2["output"][i] links.append(data3["full"]) + style = discord.ButtonStyle.gray # The button will be gray in color + item = discord.ui.Button(style=style, label="Full #"+str(i+1), url=data3["full"]) # Create an item to pass into the view class. + view.add_item(item=item) # Add that item into the view class with BytesIO() as image_binary: create_image(links).save(image_binary, 'PNG') image_binary.seek(0) - await channel.send(file=discord.File(fp=image_binary, filename='image.png')) + + #await message.channel.send(embed=HelpEmbed, components=[action_row]) + await channel.send(file=discord.File(fp=image_binary, filename='image.png'),view=view) break elif data2["status"]["code"] == 998: await channel.send("All results were NSFW, aborting!")