Fix help text, increase ipfs get image timeout, fix work_request increment generated bug pointed out by zoltan

pull/17/head
Guillermo Rodriguez 2023-07-28 11:06:11 -03:00
parent 713884e192
commit c201b78bf0
No known key found for this signature in database
GPG Key ID: EC3AB66D5D83B392
6 changed files with 49 additions and 30 deletions

View File

@ -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 <attach_image> TEXT - request an image base on an image and a promtp
/img2img <attach_image> 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',
@ -123,7 +126,16 @@ quality.
'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

View File

@ -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

View File

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

View File

@ -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()}] <b>timeout processing request</b>',
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

View File

@ -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

View File

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