Spaces:
Running
on
Zero
Running
on
Zero
update upload
Browse files- serve/upload.py +28 -10
serve/upload.py
CHANGED
|
@@ -5,6 +5,7 @@ from PIL import Image
|
|
| 5 |
import requests
|
| 6 |
import json
|
| 7 |
import random
|
|
|
|
| 8 |
from .constants import SSH_SERVER, SSH_PORT, SSH_USER, SSH_PASSWORD, SSH_LOG, SSH_MSCOCO
|
| 9 |
|
| 10 |
ssh_client = None
|
|
@@ -76,6 +77,20 @@ def create_remote_directory(remote_directory):
|
|
| 76 |
else:
|
| 77 |
print(f"Directory {remote_directory} created successfully.")
|
| 78 |
return f'{SSH_LOG}/{remote_directory}'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
|
| 80 |
def upload_ssh_all(states, output_dir, data, data_path):
|
| 81 |
global sftp_client
|
|
@@ -89,16 +104,19 @@ def upload_ssh_all(states, output_dir, data, data_path):
|
|
| 89 |
image_list.append(states[i].output)
|
| 90 |
|
| 91 |
with sftp_client as sftp:
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
|
|
|
|
|
|
|
|
|
| 102 |
json_data = json.dumps(data, indent=4)
|
| 103 |
with io.BytesIO(json_data.encode('utf-8')) as json_byte_stream:
|
| 104 |
sftp.putfo(json_byte_stream, data_path)
|
|
|
|
| 5 |
import requests
|
| 6 |
import json
|
| 7 |
import random
|
| 8 |
+
import concurrent.futures
|
| 9 |
from .constants import SSH_SERVER, SSH_PORT, SSH_USER, SSH_PASSWORD, SSH_LOG, SSH_MSCOCO
|
| 10 |
|
| 11 |
ssh_client = None
|
|
|
|
| 77 |
else:
|
| 78 |
print(f"Directory {remote_directory} created successfully.")
|
| 79 |
return f'{SSH_LOG}/{remote_directory}'
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
def upload_images(i, image_list, output_file_list, sftp_client):
|
| 83 |
+
if isinstance(image_list[i], str):
|
| 84 |
+
print("get url image")
|
| 85 |
+
image_list[i] = get_image_from_url(image_list[i])
|
| 86 |
+
with io.BytesIO() as image_byte_stream:
|
| 87 |
+
image_list[i] = image_list[i].resize((512, 512), Image.ANTIALIAS)
|
| 88 |
+
image_list[i].save(image_byte_stream, format='JPEG')
|
| 89 |
+
image_byte_stream.seek(0)
|
| 90 |
+
sftp.putfo(image_byte_stream, output_file_list[i])
|
| 91 |
+
print(f"Successfully uploaded image to {output_file_list[i]}")
|
| 92 |
+
|
| 93 |
+
|
| 94 |
|
| 95 |
def upload_ssh_all(states, output_dir, data, data_path):
|
| 96 |
global sftp_client
|
|
|
|
| 104 |
image_list.append(states[i].output)
|
| 105 |
|
| 106 |
with sftp_client as sftp:
|
| 107 |
+
with concurrent.futures.ThreadPoolExecutor() as executor:
|
| 108 |
+
futures = [executor.submit(upload_images, i, image_list, output_file_list, sftp_client) for i in range(len(output_file_list))]
|
| 109 |
+
|
| 110 |
+
# for i in range(len(output_file_list)):
|
| 111 |
+
# if isinstance(image_list[i], str):
|
| 112 |
+
# print("get url image")
|
| 113 |
+
# image_list[i] = get_image_from_url(image_list[i])
|
| 114 |
+
# with io.BytesIO() as image_byte_stream:
|
| 115 |
+
# image_list[i] = image_list[i].resize((512, 512), Image.ANTIALIAS)
|
| 116 |
+
# image_list[i].save(image_byte_stream, format='JPEG')
|
| 117 |
+
# image_byte_stream.seek(0)
|
| 118 |
+
# sftp.putfo(image_byte_stream, output_file_list[i])
|
| 119 |
+
# print(f"Successfully uploaded image to {output_file_list[i]}")
|
| 120 |
json_data = json.dumps(data, indent=4)
|
| 121 |
with io.BytesIO(json_data.encode('utf-8')) as json_byte_stream:
|
| 122 |
sftp.putfo(json_byte_stream, data_path)
|