Fix a couple bugs on telegram frontend image deseralization and sending metainfo back

pull/1/head
Guillermo Rodriguez 2023-01-06 15:14:39 -03:00
parent 6c1799e342
commit 4ff1dc7a5d
No known key found for this signature in database
GPG Key ID: EC3AB66D5D83B392
1 changed files with 12 additions and 8 deletions

View File

@ -105,22 +105,24 @@ async def run_skynet_telegram(
logging.info(f'resp to {message.id} arrived') logging.info(f'resp to {message.id} arrived')
resp_txt = '' resp_txt = ''
result = MessageToDict(resp.result)
if 'error' in resp.result: if 'error' in resp.result:
resp_txt = resp.result['message'] resp_txt = resp.result['message']
else: else:
logging.info(resp.result['id']) logging.info(result['id'])
img_raw = zlib.decompress(bytes.fromhex(resp.result['img'])) img_raw = zlib.decompress(bytes.fromhex(result['img']))
logging.info(f'got image of size: {len(img_raw)}') logging.info(f'got image of size: {len(img_raw)}')
size = (512, 512) size = (512, 512)
if resp.result['meta']['upscaler'] == 'x4': meta = result['meta']['meta']
if meta['upscaler'] == 'x4':
size = (2048, 2048) size = (2048, 2048)
img = Image.frombytes('RGB', size, img_raw) img = Image.frombytes('RGB', size, img_raw)
await bot.send_photo( await bot.send_photo(
message.chat.id, message.chat.id,
caption=prepare_metainfo_caption(resp.result['meta']), caption=prepare_metainfo_caption(meta),
photo=img, photo=img,
reply_to_message_id=message.id 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 = await _rpc_call(message.from_user.id, 'redo')
resp_txt = '' resp_txt = ''
result = MessageToDict(resp.result)
if 'error' in resp.result: if 'error' in resp.result:
resp_txt = resp.result['message'] resp_txt = resp.result['message']
else: 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)}') logging.info(f'got image of size: {len(img_raw)}')
size = (512, 512) size = (512, 512)
logging.info(resp.result['meta']) meta = result['meta']['meta']
if resp.result['meta']['upscaler'] == 'x4': if meta['upscaler'] == 'x4':
size = (2048, 2048) size = (2048, 2048)
img = Image.frombytes('RGB', size, img_raw) img = Image.frombytes('RGB', size, img_raw)
await bot.send_photo( await bot.send_photo(
message.chat.id, message.chat.id,
caption=prepare_metainfo_caption(resp.result['meta']), caption=prepare_metainfo_caption(meta),
photo=img, photo=img,
reply_to_message_id=message.id reply_to_message_id=message.id
) )