Skip to content

Commit

Permalink
Fix Retry using wrong image sizes (Closes #43)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jimmy committed Oct 1, 2022
1 parent f5fef75 commit b64fc39
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,14 +420,15 @@ def __init__(
self.short_id_parent = short_id_parent
self.strength = strength

old_docarray_loc = DOCARRAY_LOCATION_FN(short_id)
self.pixels_width, self.pixels_height = self.original_image_sizes()

def original_image_sizes(self):
old_docarray_loc = DOCARRAY_LOCATION_FN(self.short_id)
da = DocumentArray.load_binary(
old_docarray_loc, protocol='protobuf', compress='lz4'
)
loaded = document_to_pil(da[0])
orig_width, orig_height = loaded.size
self.pixels_width = orig_width
self.pixels_height = orig_height
return loaded.size

def serialize_to_json_and_store(self):
'''
Expand Down Expand Up @@ -566,35 +567,38 @@ async def handle_retry(self,
if original_request is None:
await interaction.channel.send('No original request could be found')

width, height = self.original_image_sizes()

if original_request['api'] == 'txt2img':
prompt = da[0].tags['text']
sampler = original_request['sampler']
scale = original_request['scale']
steps = int(original_request['steps'])
await _image(interaction.channel, interaction.user,
prompt,
height=self.pixels_height,
height=height,
sampler=sampler,
scale=scale,
steps=steps,
width=self.pixels_width)
width=width)
if original_request['api'] == 'stablediffuse':
sampler = original_request['sampler']
scale = original_request['scale']
steps = int(original_request['steps'])
latentless = original_request['latentless']
strength = original_request['strength']

await _riff(
interaction.channel, interaction.user,
self.short_id_parent, self.idx_parent,
height=self.pixels_height,
height=height,
latentless=latentless,
sampler=sampler,
scale=scale,
seed=random.randint(1, 2 ** 32 - 1),
steps=steps,
strength=strength,
width=self.pixels_width)
width=width)

async def handle_upscale(self,
interaction: discord.Interaction,
Expand Down Expand Up @@ -695,9 +699,12 @@ async def upscale_button_3(self, interaction: discord.Interaction,
options=[
discord.SelectOption(label='2:1 (landscape)', value='2:1'),
discord.SelectOption(label='3:2', value='3:2'),
discord.SelectOption(label='4:3', value='4:3'),
discord.SelectOption(label='1:1 (square)', value='1:1'),
discord.SelectOption(label='3:4', value='3:4'),
discord.SelectOption(label='2:3', value='2:3'),
discord.SelectOption(label='1:2 (portait)', value='1:2'),
discord.SelectOption(label='Original Image Size', value='original'),
])
async def select_aspect_ratio(self, interaction: discord.Interaction,
selection: discord.ui.Select):
Expand All @@ -709,15 +716,23 @@ async def select_aspect_ratio(self, interaction: discord.Interaction,
if sel == '3:2': # ish
self.pixels_height = 448
self.pixels_width = 704
if sel == '4:3':
self.pixels_height = 480
self.pixels_width = 640
if sel == '1:1':
self.pixels_height = 512
self.pixels_width = 512
if sel == '3:4':
self.pixels_height = 640
self.pixels_width = 480
if sel == '2:3': # ish
self.pixels_height = 704
self.pixels_width = 448
if sel == '1:2':
self.pixels_height = 768
self.pixels_width = 384
if sel == 'original':
self.pixels_width, self.pixels_height = self.original_image_sizes()
await interaction.response.defer()

@discord.ui.select(placeholder=RIFF_STRENGTH_PLACEHOLDER_MESSAGE, row=3,
Expand Down

0 comments on commit b64fc39

Please sign in to comment.