mirror of https://github.com/skygpu/skynet.git
Bump version number, also telegram max image limit and disable in private for now
parent
dc7c43fc95
commit
89c413a612
|
@ -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
|
||||||
|
|
|
@ -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,8 +253,19 @@ class SkynetTelegramFrontend:
|
||||||
reply_markup=build_redo_menu(),
|
reply_markup=build_redo_menu(),
|
||||||
parse_mode='HTML'
|
parse_mode='HTML'
|
||||||
)
|
)
|
||||||
|
return
|
||||||
|
|
||||||
|
png_img = resp.raw
|
||||||
|
with Image.open(io.BytesIO(resp.raw)) as image:
|
||||||
|
w, h = image.size
|
||||||
|
|
||||||
|
if w > TG_MAX_WIDTH or h > TG_MAX_HEIGHT:
|
||||||
|
logging.warning(f'result is of size {image.size}')
|
||||||
|
image.thumbnail((TG_MAX_WIDTH, TG_MAX_HEIGHT))
|
||||||
|
tmp_buf = io.BytesIO()
|
||||||
|
image.save(tmp_buf, format='PNG')
|
||||||
|
png_img = tmp_buf.getvalue()
|
||||||
|
|
||||||
else:
|
|
||||||
logging.info(f'success! sending generated image')
|
logging.info(f'success! sending generated image')
|
||||||
await self.bot.delete_message(
|
await self.bot.delete_message(
|
||||||
chat_id=status_msg.chat.id, message_id=status_msg.id)
|
chat_id=status_msg.chat.id, message_id=status_msg.id)
|
||||||
|
@ -262,7 +275,7 @@ class SkynetTelegramFrontend:
|
||||||
media=[
|
media=[
|
||||||
InputMediaPhoto(file_id),
|
InputMediaPhoto(file_id),
|
||||||
InputMediaPhoto(
|
InputMediaPhoto(
|
||||||
resp.raw,
|
png_img,
|
||||||
caption=caption,
|
caption=caption,
|
||||||
parse_mode='HTML'
|
parse_mode='HTML'
|
||||||
)
|
)
|
||||||
|
@ -273,7 +286,7 @@ class SkynetTelegramFrontend:
|
||||||
await self.bot.send_photo(
|
await self.bot.send_photo(
|
||||||
status_msg.chat.id,
|
status_msg.chat.id,
|
||||||
caption=caption,
|
caption=caption,
|
||||||
photo=resp.raw,
|
photo=png_img,
|
||||||
reply_markup=build_redo_menu(),
|
reply_markup=build_redo_menu(),
|
||||||
parse_mode='HTML'
|
parse_mode='HTML'
|
||||||
)
|
)
|
||||||
|
|
|
@ -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)
|
||||||
|
|
Loading…
Reference in New Issue