From 4ff1dc7a5d7940e64a966bcf348e58065979e2fd Mon Sep 17 00:00:00 2001 From: Guillermo Rodriguez Date: Fri, 6 Jan 2023 15:14:39 -0300 Subject: [PATCH] Fix a couple bugs on telegram frontend image deseralization and sending metainfo back --- skynet/frontend/telegram.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/skynet/frontend/telegram.py b/skynet/frontend/telegram.py index 5b7cdaf..a209032 100644 --- a/skynet/frontend/telegram.py +++ b/skynet/frontend/telegram.py @@ -105,22 +105,24 @@ async def run_skynet_telegram( logging.info(f'resp to {message.id} arrived') resp_txt = '' + result = MessageToDict(resp.result) if 'error' in resp.result: resp_txt = resp.result['message'] else: - logging.info(resp.result['id']) - img_raw = zlib.decompress(bytes.fromhex(resp.result['img'])) + logging.info(result['id']) + img_raw = zlib.decompress(bytes.fromhex(result['img'])) logging.info(f'got image of size: {len(img_raw)}') size = (512, 512) - if resp.result['meta']['upscaler'] == 'x4': + meta = result['meta']['meta'] + if meta['upscaler'] == 'x4': size = (2048, 2048) img = Image.frombytes('RGB', size, img_raw) await bot.send_photo( message.chat.id, - caption=prepare_metainfo_caption(resp.result['meta']), + caption=prepare_metainfo_caption(meta), photo=img, reply_to_message_id=message.id ) @@ -137,22 +139,24 @@ async def run_skynet_telegram( resp = await _rpc_call(message.from_user.id, 'redo') resp_txt = '' + result = MessageToDict(resp.result) if 'error' in resp.result: resp_txt = resp.result['message'] else: - img_raw = zlib.decompress(bytes.fromhex(resp.result['img'])) + logging.info(result['id']) + img_raw = zlib.decompress(bytes.fromhex(result['img'])) logging.info(f'got image of size: {len(img_raw)}') size = (512, 512) - logging.info(resp.result['meta']) - if resp.result['meta']['upscaler'] == 'x4': + meta = result['meta']['meta'] + if meta['upscaler'] == 'x4': size = (2048, 2048) img = Image.frombytes('RGB', size, img_raw) await bot.send_photo( message.chat.id, - caption=prepare_metainfo_caption(resp.result['meta']), + caption=prepare_metainfo_caption(meta), photo=img, reply_to_message_id=message.id )