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: if file_id:
image_raw = await bot.download_file(file_path) 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 w, h = image.size
logging.info(f'user sent img of size {image.size}')
if w > 512 or h > 512: if w > 512 or h > 512:
image.thumbnail((512, 512)) logging.warning(f'user sent img of size {image.size}')
logging.warning(f'resized it to {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() binary = image_raw.hex()
else:
binary = ''
ec, out = cleos.push_action( ec, out = cleos.push_action(
'telos.gpu', 'enqueue', [account, body, binary, '20.0000 GPU'], f'{account}@{permission}' 'telos.gpu', 'enqueue', [account, body, binary, '20.0000 GPU'], f'{account}@{permission}'
) )

View File

@ -1,5 +1,6 @@
#!/usr/bin/python #!/usr/bin/python
import os
import logging import logging
from pathlib import Path from pathlib import Path
@ -7,6 +8,7 @@ from contextlib import contextmanager as cm
import docker import docker
from docker.types import Mount
from docker.models.containers import Container from docker.models.containers import Container
@ -48,13 +50,27 @@ def open_ipfs_node():
'4001/tcp': 4001, '4001/tcp': 4001,
'5001/tcp': ('127.0.0.1', 5001) '5001/tcp': ('127.0.0.1', 5001)
}, },
volumes=[ mounts=[
str(Path().resolve() / 'tmp/ipfs-docker-staging') + ':/export', Mount(
str(Path().resolve() / 'tmp/ipfs-docker-data') + ':/data/ipfs' '/export',
str(Path().resolve() / 'tmp/ipfs-docker-staging'),
'bind'
),
Mount(
'/data/ipfs',
str(Path().resolve() / 'tmp/ipfs-docker-data'),
'bind'
)
], ],
detach=True, detach=True,
remove=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: try:
for log in container.logs(stream=True): for log in container.logs(stream=True):