mirror of https://github.com/skygpu/skynet.git
Add frontend image reduction and fix ipfs sudo issue
parent
e63d395d5c
commit
a85518152a
|
@ -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:
|
||||||
|
logging.warning(f'user sent img of size {image.size}')
|
||||||
image.thumbnail((512, 512))
|
image.thumbnail((512, 512))
|
||||||
logging.warning(f'resized it to {image.size}')
|
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}'
|
||||||
)
|
)
|
||||||
|
|
|
@ -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):
|
||||||
|
|
Loading…
Reference in New Issue