Added regen buttons to neural

This commit is contained in:
7trail 2023-09-05 18:34:11 -05:00 committed by GitHub
parent 535dfd92a8
commit 66ca3b6310
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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!")