ksort commited on
Commit
0a69bfa
·
1 Parent(s): d75f30e

update upload

Browse files
Files changed (1) hide show
  1. serve/upload.py +28 -26
serve/upload.py CHANGED
@@ -80,15 +80,16 @@ def create_remote_directory(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
 
@@ -99,24 +100,25 @@ def upload_ssh_all(states, output_dir, data, data_path):
99
  output_file_list = []
100
  image_list = []
101
  for i in range(len(states)):
102
- output_file = os.path.join(output_dir, f"{i}.jpg")
103
- output_file_list.append(output_file)
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)
 
80
 
81
 
82
  def upload_images(i, image_list, output_file_list, sftp_client):
83
+ with sftp_client as sftp:
84
+ if isinstance(image_list[i], str):
85
+ print("get url image")
86
+ image_list[i] = get_image_from_url(image_list[i])
87
+ with io.BytesIO() as image_byte_stream:
88
+ image_list[i] = image_list[i].resize((512, 512), Image.ANTIALIAS)
89
+ image_list[i].save(image_byte_stream, format='JPEG')
90
+ image_byte_stream.seek(0)
91
+ sftp.putfo(image_byte_stream, output_file_list[i])
92
+ print(f"Successfully uploaded image to {output_file_list[i]}")
93
 
94
 
95
 
 
100
  output_file_list = []
101
  image_list = []
102
  for i in range(len(states)):
103
+ output_file = os.path.join(output_dir, f"{i}.jpg")
104
+ output_file_list.append(output_file)
105
+ image_list.append(states[i].output)
106
+
107
+
108
+ with concurrent.futures.ThreadPoolExecutor() as executor:
109
+ futures = [executor.submit(upload_images, i, image_list, output_file_list, sftp_client) for i in range(len(output_file_list))]
110
+
111
+ # for i in range(len(output_file_list)):
112
+ # if isinstance(image_list[i], str):
113
+ # print("get url image")
114
+ # image_list[i] = get_image_from_url(image_list[i])
115
+ # with io.BytesIO() as image_byte_stream:
116
+ # image_list[i] = image_list[i].resize((512, 512), Image.ANTIALIAS)
117
+ # image_list[i].save(image_byte_stream, format='JPEG')
118
+ # image_byte_stream.seek(0)
119
+ # sftp.putfo(image_byte_stream, output_file_list[i])
120
+ # print(f"Successfully uploaded image to {output_file_list[i]}")
121
  with sftp_client as sftp:
 
 
 
 
 
 
 
 
 
 
 
 
 
122
  json_data = json.dumps(data, indent=4)
123
  with io.BytesIO(json_data.encode('utf-8')) as json_byte_stream:
124
  sftp.putfo(json_byte_stream, data_path)