From c201b78bf04ba19e91baf57ae3e1e621d8e51f87 Mon Sep 17 00:00:00 2001 From: Guillermo Rodriguez Date: Fri, 28 Jul 2023 11:06:11 -0300 Subject: [PATCH] Fix help text, increase ipfs get image timeout, fix work_request increment generated bug pointed out by zoltan --- skynet/constants.py | 32 +++++++++++++++++++--------- skynet/frontend/discord/__init__.py | 8 ++++--- skynet/frontend/discord/handlers.py | 12 +++++------ skynet/frontend/telegram/__init__.py | 10 +++++---- skynet/frontend/telegram/handlers.py | 13 ++++++----- skynet/ipfs/__init__.py | 4 ++-- 6 files changed, 49 insertions(+), 30 deletions(-) diff --git a/skynet/constants.py b/skynet/constants.py index 743270f..e28646a 100755 --- a/skynet/constants.py +++ b/skynet/constants.py @@ -37,7 +37,7 @@ commands work on a user per user basis! config is individual to each user! /txt2img TEXT - request an image based on a prompt -/img2img TEXT - request an image base on an image and a promtp +/img2img TEXT - request an image base on an image and a prompt /redo - redo last command (only works for txt2img for now!) @@ -54,14 +54,17 @@ config is individual to each user! {N.join(SHORT_NAMES)} /config step NUMBER - set amount of iterations -/config seed NUMBER - set the seed, deterministic results! -/config size WIDTH HEIGHT - set size in pixels +/config seed [auto|NUMBER] - set the seed, deterministic results! +/config width NUMBER - set horizontal size in pixels +/config height NUMBER - set vertical size in pixels +/config upscaler [off/x4] - enable/disable x4 size upscaler /config guidance NUMBER - prompt text importance +/config strength NUMBER - importance of the input image for img2img ''' UNKNOWN_CMD_TEXT = 'Unknown command! Try sending \"/help\"' -DONATION_INFO = '0xf95335682DF281FFaB7E104EB87B69625d9622B6\ngoal: 25/650usd' +DONATION_INFO = '0xf95335682DF281FFaB7E104EB87B69625d9622B6\ngoal: 0.0465/1.0000 ETH' COOL_WORDS = [ 'cyberpunk', @@ -120,10 +123,19 @@ ing more may produce a slightly different picture, but not necessarily better \ quality. ''', -'guidance': ''' + 'guidance': ''' The guidance scale is a parameter that controls how much the image generation\ process follows the text prompt. The higher the value, the more image sticks\ - to a given text input. + to a given text input. Value range 0 to 20. Recomended range: 4.5-7.5. +''', + + 'strength': ''' +Noise is added to the image you use as an init image for img2img, and then the\ + diffusion process continues according to the prompt. The amount of noise added\ + depends on the \"Strength of img2img\"” parameter, which ranges from 0 to 1,\ + where 0 adds no noise at all and you will get the exact image you added, and\ + 1 completely replaces the image with noise and almost acts as if you used\ + normal txt2img instead of img2img. ''' } @@ -140,13 +152,13 @@ MAX_HEIGHT = 1024 MAX_GUIDANCE = 20 DEFAULT_SEED = None -DEFAULT_WIDTH = 512 -DEFAULT_HEIGHT = 512 +DEFAULT_WIDTH = 1024 +DEFAULT_HEIGHT = 1024 DEFAULT_GUIDANCE = 7.5 DEFAULT_STRENGTH = 0.5 -DEFAULT_STEP = 35 +DEFAULT_STEP = 28 DEFAULT_CREDITS = 10 -DEFAULT_MODEL = list(MODELS.keys())[0] +DEFAULT_MODEL = 'stablexl' DEFAULT_ROLE = 'pleb' DEFAULT_UPSCALER = None diff --git a/skynet/frontend/discord/__init__.py b/skynet/frontend/discord/__init__.py index 7687c3b..3e17cf2 100644 --- a/skynet/frontend/discord/__init__.py +++ b/skynet/frontend/discord/__init__.py @@ -121,7 +121,7 @@ class SkynetDiscordFrontend: ctx: discord.ext.commands.context.Context | discord.Message, file_id: str | None = None, binary_data: str = '' - ): + ) -> bool: send = ctx.channel.send if params['seed'] == None: @@ -168,7 +168,7 @@ class SkynetDiscordFrontend: await self.bot.channel.send( status_msg, 'skynet has suffered an internal error trying to fill this request') - return + return False enqueue_tx_id = res['transaction_id'] enqueue_tx_link = f'[**Your request on Skynet Explorer**](https://explorer.{DEFAULT_DOMAIN}/v2/explore/transaction/{enqueue_tx_id})' @@ -230,7 +230,7 @@ class SkynetDiscordFrontend: color=discord.Color.blue()) await message.edit(embed=embed) - return + return False tx_link = f'[**Your result on Skynet Explorer**](https://explorer.{DEFAULT_DOMAIN}/v2/explore/transaction/{tx_hash})' @@ -265,3 +265,5 @@ class SkynetDiscordFrontend: else: # txt2img embed.set_image(url=ipfs_link) await send(embed=embed, view=SkynetView(self)) + + return True diff --git a/skynet/frontend/discord/handlers.py b/skynet/frontend/discord/handlers.py index c6f2735..092714a 100644 --- a/skynet/frontend/discord/handlers.py +++ b/skynet/frontend/discord/handlers.py @@ -115,9 +115,9 @@ def create_handler_context(frontend: 'SkynetDiscordFrontend'): await db_call( 'update_user_stats', user.id, 'txt2img', last_prompt=prompt) - ec = await work_request(user, status_msg, 'txt2img', params, ctx) + success = await work_request(user, status_msg, 'txt2img', params, ctx) - if ec == None: + if success: await db_call('increment_generated', user.id) @bot.command(name='redo', help='Redo last request') @@ -153,13 +153,13 @@ def create_handler_context(frontend: 'SkynetDiscordFrontend'): **user_config } - ec = await work_request( + success = await work_request( user, status_msg, 'redo', params, ctx, file_id=file_id, binary_data=binary ) - if ec == None: + if success: await db_call('increment_generated', user.id) @bot.command(name='img2img', help='Responds with an image') @@ -243,13 +243,13 @@ def create_handler_context(frontend: 'SkynetDiscordFrontend'): last_binary=ipfs_hash ) - ec = await work_request( + success = await work_request( user, status_msg, 'img2img', params, ctx, file_id=file_id, binary_data=ipfs_hash ) - if ec == None: + if success: await db_call('increment_generated', user.id) diff --git a/skynet/frontend/telegram/__init__.py b/skynet/frontend/telegram/__init__.py index 22d9420..fd285b5 100644 --- a/skynet/frontend/telegram/__init__.py +++ b/skynet/frontend/telegram/__init__.py @@ -118,7 +118,7 @@ class SkynetTelegramFrontend: params: dict, file_id: str | None = None, binary_data: str = '' - ): + ) -> bool: if params['seed'] == None: params['seed'] = random.randint(0, 0xFFFFFFFF) @@ -161,7 +161,7 @@ class SkynetTelegramFrontend: await self.update_status_message( status_msg, 'skynet has suffered an internal error trying to fill this request') - return + return False enqueue_tx_id = res['transaction_id'] enqueue_tx_link = hlink( @@ -223,7 +223,7 @@ class SkynetTelegramFrontend: f'\n[{timestamp_pretty()}] timeout processing request', parse_mode='HTML' ) - return + return False tx_link = hlink( 'Your result on Skynet Explorer', @@ -253,7 +253,7 @@ class SkynetTelegramFrontend: reply_markup=build_redo_menu(), parse_mode='HTML' ) - return + return True png_img = resp.raw with Image.open(io.BytesIO(resp.raw)) as image: @@ -290,3 +290,5 @@ class SkynetTelegramFrontend: reply_markup=build_redo_menu(), parse_mode='HTML' ) + + return True diff --git a/skynet/frontend/telegram/handlers.py b/skynet/frontend/telegram/handlers.py index c6982e5..7695790 100644 --- a/skynet/frontend/telegram/handlers.py +++ b/skynet/frontend/telegram/handlers.py @@ -157,9 +157,9 @@ def create_handler_context(frontend: 'SkynetTelegramFrontend'): await db_call( 'update_user_stats', user.id, 'txt2img', last_prompt=prompt) - ec = await work_request(user, status_msg, 'txt2img', params) + success = await work_request(user, status_msg, 'txt2img', params) - if ec == 0: + if success: await db_call('increment_generated', user.id) @@ -243,13 +243,13 @@ def create_handler_context(frontend: 'SkynetTelegramFrontend'): last_binary=ipfs_hash ) - ec = await work_request( + success = await work_request( user, status_msg, 'img2img', params, file_id=file_id, binary_data=ipfs_hash ) - if ec == 0: + if success: await db_call('increment_generated', user.id) @@ -307,12 +307,15 @@ def create_handler_context(frontend: 'SkynetTelegramFrontend'): **user_config } - await work_request( + success = await work_request( user, status_msg, 'redo', params, file_id=file_id, binary_data=binary ) + if success: + await db_call('increment_generated', user.id) + # "proxy" handlers just request routers diff --git a/skynet/ipfs/__init__.py b/skynet/ipfs/__init__.py index 1a0d4ef..9ee7b42 100644 --- a/skynet/ipfs/__init__.py +++ b/skynet/ipfs/__init__.py @@ -24,10 +24,10 @@ class IPFSHTTP: ) -async def get_ipfs_file(ipfs_link: str): +async def get_ipfs_file(ipfs_link: str, timeout: int = 60): logging.info(f'attempting to get image at {ipfs_link}') resp = None - for i in range(20): + for i in range(timeout): try: resp = await asks.get(ipfs_link, timeout=3)