Bump version number, also telegram max image limit and disable in private for now

pull/14/head
Guillermo Rodriguez 2023-07-22 16:53:00 -03:00
parent dc7c43fc95
commit 89c413a612
No known key found for this signature in database
GPG Key ID: EC3AB66D5D83B392
3 changed files with 55 additions and 30 deletions

View File

@ -1,6 +1,6 @@
#!/usr/bin/python #!/usr/bin/python
VERSION = '0.1a10' VERSION = '0.1a11'
DOCKER_RUNTIME_CUDA = 'skynet:runtime-cuda' DOCKER_RUNTIME_CUDA = 'skynet:runtime-cuda'
@ -172,3 +172,6 @@ CONFIG_ATTRS = [
DEFAULT_DOMAIN = 'skygpu.net' DEFAULT_DOMAIN = 'skygpu.net'
DEFAULT_IPFS_REMOTE = '/ip4/169.197.140.154/tcp/4001/p2p/12D3KooWKWogLFNEcNNMKnzU7Snrnuj84RZdMBg3sLiQSQc51oEv' DEFAULT_IPFS_REMOTE = '/ip4/169.197.140.154/tcp/4001/p2p/12D3KooWKWogLFNEcNNMKnzU7Snrnuj84RZdMBg3sLiQSQc51oEv'
TG_MAX_WIDTH = 1280
TG_MAX_HEIGHT = 1280

View File

@ -1,10 +1,12 @@
#!/usr/bin/python #!/usr/bin/python
from json import JSONDecodeError import io
import random import random
import logging import logging
import asyncio import asyncio
from PIL import Image
from json import JSONDecodeError
from decimal import Decimal from decimal import Decimal
from hashlib import sha256 from hashlib import sha256
from datetime import datetime from datetime import datetime
@ -66,7 +68,7 @@ class SkynetTelegramFrontend:
self.ipfs_node = self._exit_stack.enter_context( self.ipfs_node = self._exit_stack.enter_context(
open_ipfs_node()) open_ipfs_node())
self.ipfs_node.connect(self.remote_ipfs_node) # self.ipfs_node.connect(self.remote_ipfs_node)
logging.info( logging.info(
f'connected to remote ipfs node: {self.remote_ipfs_node}') f'connected to remote ipfs node: {self.remote_ipfs_node}')
@ -236,13 +238,13 @@ class SkynetTelegramFrontend:
parse_mode='HTML' parse_mode='HTML'
) )
caption = generate_reply_caption(
user, params, tx_hash, worker, reward)
# attempt to get the image and send it # attempt to get the image and send it
ipfs_link = f'https://ipfs.{DEFAULT_DOMAIN}/ipfs/{ipfs_hash}/image.png' ipfs_link = f'https://ipfs.{DEFAULT_DOMAIN}/ipfs/{ipfs_hash}/image.png'
resp = await get_ipfs_file(ipfs_link) resp = await get_ipfs_file(ipfs_link)
caption = generate_reply_caption(
user, params, tx_hash, worker, reward)
if not resp or resp.status_code != 200: if not resp or resp.status_code != 200:
logging.error(f'couldn\'t get ipfs hosted image at {ipfs_link}!') logging.error(f'couldn\'t get ipfs hosted image at {ipfs_link}!')
await self.update_status_message( await self.update_status_message(
@ -251,29 +253,40 @@ class SkynetTelegramFrontend:
reply_markup=build_redo_menu(), reply_markup=build_redo_menu(),
parse_mode='HTML' parse_mode='HTML'
) )
return
else: png_img = resp.raw
logging.info(f'success! sending generated image') with Image.open(io.BytesIO(resp.raw)) as image:
await self.bot.delete_message( w, h = image.size
chat_id=status_msg.chat.id, message_id=status_msg.id)
if file_id: # img2img
await self.bot.send_media_group(
status_msg.chat.id,
media=[
InputMediaPhoto(file_id),
InputMediaPhoto(
resp.raw,
caption=caption,
parse_mode='HTML'
)
],
)
else: # txt2img if w > TG_MAX_WIDTH or h > TG_MAX_HEIGHT:
await self.bot.send_photo( logging.warning(f'result is of size {image.size}')
status_msg.chat.id, image.thumbnail((TG_MAX_WIDTH, TG_MAX_HEIGHT))
caption=caption, tmp_buf = io.BytesIO()
photo=resp.raw, image.save(tmp_buf, format='PNG')
reply_markup=build_redo_menu(), png_img = tmp_buf.getvalue()
parse_mode='HTML'
) logging.info(f'success! sending generated image')
await self.bot.delete_message(
chat_id=status_msg.chat.id, message_id=status_msg.id)
if file_id: # img2img
await self.bot.send_media_group(
status_msg.chat.id,
media=[
InputMediaPhoto(file_id),
InputMediaPhoto(
png_img,
caption=caption,
parse_mode='HTML'
)
],
)
else: # txt2img
await self.bot.send_photo(
status_msg.chat.id,
caption=caption,
photo=png_img,
reply_markup=build_redo_menu(),
parse_mode='HTML'
)

View File

@ -118,6 +118,9 @@ def create_handler_context(frontend: 'SkynetTelegramFrontend'):
user = message.from_user user = message.from_user
chat = message.chat chat = message.chat
if chat.type == 'private':
return
reply_id = None reply_id = None
if chat.type == 'group' and chat.id == GROUP_ID: if chat.type == 'group' and chat.id == GROUP_ID:
reply_id = message.message_id reply_id = message.message_id
@ -174,6 +177,9 @@ def create_handler_context(frontend: 'SkynetTelegramFrontend'):
user = message.from_user user = message.from_user
chat = message.chat chat = message.chat
if chat.type == 'private':
return
reply_id = None reply_id = None
if chat.type == 'group' and chat.id == GROUP_ID: if chat.type == 'group' and chat.id == GROUP_ID:
reply_id = message.message_id reply_id = message.message_id
@ -263,6 +269,9 @@ def create_handler_context(frontend: 'SkynetTelegramFrontend'):
user = message.from_user user = message.from_user
chat = message.chat chat = message.chat
if chat.type == 'private':
return
init_msg = 'started processing redo request...' init_msg = 'started processing redo request...'
if is_query: if is_query:
status_msg = await bot.send_message(chat.id, init_msg) status_msg = await bot.send_message(chat.id, init_msg)