Fix redo and change a bit of telegram logic to allow pm

pull/4/head
Guillermo Rodriguez 2023-01-17 07:06:18 -03:00
parent ab893393e3
commit 122de1af9c
No known key found for this signature in database
GPG Key ID: EC3AB66D5D83B392
2 changed files with 22 additions and 15 deletions

View File

@ -290,7 +290,8 @@ async def open_rpc_service(sock, dgpu_bus, db_pool, tls_whitelist, tls_key):
if prompt: if prompt:
req = DiffusionParameters( req = DiffusionParameters(
prompt=prompt, prompt=prompt,
**user_config **user_config,
image=False
) )
rid, img, meta = await dgpu_stream_one_img(req) rid, img, meta = await dgpu_stream_one_img(req)
result = { result = {

View File

@ -22,12 +22,18 @@ from . import *
PREFIX = 'tg' PREFIX = 'tg'
def prepare_metainfo_caption(meta: dict) -> str: def prepare_metainfo_caption(tguser, meta: dict) -> str:
prompt = meta["prompt"] prompt = meta["prompt"]
if len(prompt) > 256: if len(prompt) > 256:
prompt = prompt[:256] prompt = prompt[:256]
meta_str = f'prompt: \"{prompt}\"\n' if tguser.username:
user = tguser.username
else:
user = f'{tguser.first_name} id: {tguser.id}'
meta_str = f'by {user}\n'
meta_str += f'prompt: \"{prompt}\"\n'
meta_str += f'seed: {meta["seed"]}\n' meta_str += f'seed: {meta["seed"]}\n'
meta_str += f'step: {meta["step"]}\n' meta_str += f'step: {meta["step"]}\n'
meta_str += f'guidance: {meta["guidance"]}\n' meta_str += f'guidance: {meta["guidance"]}\n'
@ -87,8 +93,8 @@ async def run_skynet_telegram(
@bot.message_handler(commands=['txt2img']) @bot.message_handler(commands=['txt2img'])
async def send_txt2img(message): async def send_txt2img(message):
chat = message.chat chat = message.chat
if chat.type != 'group' and chat.id != GROUP_ID: # if chat.type != 'group' and chat.id != GROUP_ID:
return # return
prompt = ' '.join(message.text.split(' ')[1:]) prompt = ' '.join(message.text.split(' ')[1:])
@ -116,8 +122,8 @@ async def run_skynet_telegram(
img = Image.open(io.BytesIO(img_raw)) img = Image.open(io.BytesIO(img_raw))
await bot.send_photo( await bot.send_photo(
message.chat.id, GROUP_ID,
caption=prepare_metainfo_caption(result['meta']['meta']), caption=prepare_metainfo_caption(message.from_user, result['meta']['meta']),
photo=img, photo=img,
reply_to_message_id=message.id reply_to_message_id=message.id
) )
@ -128,8 +134,8 @@ async def run_skynet_telegram(
@bot.message_handler(func=lambda message: True, content_types=['photo']) @bot.message_handler(func=lambda message: True, content_types=['photo'])
async def send_img2img(message): async def send_img2img(message):
chat = message.chat chat = message.chat
if chat.type != 'group' and chat.id != GROUP_ID: # if chat.type != 'group' and chat.id != GROUP_ID:
return # return
if not message.caption.startswith('/img2img'): if not message.caption.startswith('/img2img'):
return return
@ -165,8 +171,8 @@ async def run_skynet_telegram(
img = Image.open(io.BytesIO(img_raw)) img = Image.open(io.BytesIO(img_raw))
await bot.send_photo( await bot.send_photo(
message.chat.id, GROUP_ID,
caption=prepare_metainfo_caption(result['meta']['meta']), caption=prepare_metainfo_caption(message.from_user, result['meta']['meta']),
photo=img, photo=img,
reply_to_message_id=message.id reply_to_message_id=message.id
) )
@ -177,8 +183,8 @@ async def run_skynet_telegram(
@bot.message_handler(commands=['redo']) @bot.message_handler(commands=['redo'])
async def redo_txt2img(message): async def redo_txt2img(message):
chat = message.chat chat = message.chat
if chat.type != 'group' and chat.id != GROUP_ID: # if chat.type != 'group' and chat.id != GROUP_ID:
return # return
resp = await _rpc_call(message.from_user.id, 'redo') resp = await _rpc_call(message.from_user.id, 'redo')
@ -194,8 +200,8 @@ async def run_skynet_telegram(
img = Image.open(io.BytesIO(img_raw)) img = Image.open(io.BytesIO(img_raw))
await bot.send_photo( await bot.send_photo(
message.chat.id, GROUP_ID,
caption=prepare_metainfo_caption(result['meta']['meta']), caption=prepare_metainfo_caption(message.from_user, result['meta']['meta']),
photo=img, photo=img,
reply_to_message_id=message.id reply_to_message_id=message.id
) )