Add frontend image reduction and fix ipfs sudo issue

add-txt2txt-models
Guillermo Rodriguez 2023-05-28 20:44:47 -03:00
parent e63d395d5c
commit a85518152a
No known key found for this signature in database
GPG Key ID: EC3AB66D5D83B392
2 changed files with 31 additions and 9 deletions

View File

@ -140,16 +140,22 @@ async def work_request(
if file_id:
image_raw = await bot.download_file(file_path)
image = Image.open(io.BytesIO(image_raw))
with Image.open(io.BytesIO(image_raw)) as image:
w, h = image.size
logging.info(f'user sent img of size {image.size}')
if w > 512 or h > 512:
logging.warning(f'user sent img of size {image.size}')
image.thumbnail((512, 512))
logging.warning(f'resized it to {image.size}')
img_byte_arr = io.BytesIO()
image.save(img_byte_arr, format='PNG')
image_raw = img_byte_arr.getvalue()
binary = image_raw.hex()
else:
binary = ''
ec, out = cleos.push_action(
'telos.gpu', 'enqueue', [account, body, binary, '20.0000 GPU'], f'{account}@{permission}'
)

View File

@ -1,5 +1,6 @@
#!/usr/bin/python
import os
import logging
from pathlib import Path
@ -7,6 +8,7 @@ from contextlib import contextmanager as cm
import docker
from docker.types import Mount
from docker.models.containers import Container
@ -48,13 +50,27 @@ def open_ipfs_node():
'4001/tcp': 4001,
'5001/tcp': ('127.0.0.1', 5001)
},
volumes=[
str(Path().resolve() / 'tmp/ipfs-docker-staging') + ':/export',
str(Path().resolve() / 'tmp/ipfs-docker-data') + ':/data/ipfs'
mounts=[
Mount(
'/export',
str(Path().resolve() / 'tmp/ipfs-docker-staging'),
'bind'
),
Mount(
'/data/ipfs',
str(Path().resolve() / 'tmp/ipfs-docker-data'),
'bind'
)
],
detach=True,
remove=True
)
uid = os.getuid()
gid = os.getgid()
ec, out = container.exec_run(['chown', f'{uid}:{gid}', '-R', '/export'])
assert ec == 0
ec, out = container.exec_run(['chown', f'{uid}:{gid}', '-R', '/data/ipfs'])
assert ec == 0
try:
for log in container.logs(stream=True):