Merge pull request #60 from Hikari-Haru/bigger-images

Changed the image resizing to go by the guild filesize limit
Kaveen Kumarasinghe 2 years ago committed by GitHub
commit 04d1a06a9e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -47,7 +47,7 @@ class DrawDallEService(discord.Cog, name="DrawDallEService"):
try:
file, image_urls = await self.model.send_image_request(
prompt, vary=vary if not draw_from_optimizer else None
ctx, prompt, vary=vary if not draw_from_optimizer else None
)
except ValueError as e:
(

@ -183,7 +183,7 @@ class DrawButton(discord.ui.Button["OptimizeView"]):
await self.image_service_cog.encapsulated_send(
user_id,
prompt,
None,
interaction,
msg,
True,
True,

@ -414,7 +414,7 @@ class Model:
return response
async def send_image_request(self, prompt, vary=None) -> tuple[File, list[Any]]:
async def send_image_request(self, ctx, prompt, vary=None) -> tuple[File, list[Any]]:
# Validate that all the parameters are in a good state before we send the request
words = len(prompt.split(" "))
if words < 3 or words > 75:
@ -537,17 +537,21 @@ class Model:
)
# Print the filesize of new_im, in mega bytes
image_size = os.path.getsize(temp_file.name) / 1000000
image_size = os.path.getsize(temp_file.name) / 1048576
if ctx.guild is None:
guild_file_limit = 8
else:
guild_file_limit = ctx.guild.filesize_limit / 1048576
# If the image size is greater than 8MB, we can't return this to the user, so we will need to downscale the
# image and try again
safety_counter = 0
while image_size > 8:
while image_size > guild_file_limit:
safety_counter += 1
if safety_counter >= 3:
break
print(
f"Image size is {image_size}MB, which is too large for discord. Downscaling and trying again"
f"Image size is {image_size}MB, which is too large for this server {guild_file_limit}MB. Downscaling and trying again"
)
# We want to do this resizing asynchronously, so that it doesn't block the main thread during the resize.
# We can use the asyncio.run_in_executor method to do this

Loading…
Cancel
Save