unitlab 1.7.9__tar.gz → 1.8.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {unitlab-1.7.9 → unitlab-1.8.0}/PKG-INFO +1 -1
- {unitlab-1.7.9 → unitlab-1.8.0}/setup.py +1 -1
- {unitlab-1.7.9 → unitlab-1.8.0}/src/unitlab/core.py +51 -47
- {unitlab-1.7.9 → unitlab-1.8.0}/src/unitlab.egg-info/PKG-INFO +1 -1
- {unitlab-1.7.9 → unitlab-1.8.0}/LICENSE.md +0 -0
- {unitlab-1.7.9 → unitlab-1.8.0}/MANIFEST.in +0 -0
- {unitlab-1.7.9 → unitlab-1.8.0}/README.md +0 -0
- {unitlab-1.7.9 → unitlab-1.8.0}/setup.cfg +0 -0
- {unitlab-1.7.9 → unitlab-1.8.0}/src/unitlab/__init__.py +0 -0
- {unitlab-1.7.9 → unitlab-1.8.0}/src/unitlab/client.py +0 -0
- {unitlab-1.7.9 → unitlab-1.8.0}/src/unitlab/exceptions.py +0 -0
- {unitlab-1.7.9 → unitlab-1.8.0}/src/unitlab/pretty.py +0 -0
- {unitlab-1.7.9 → unitlab-1.8.0}/src/unitlab/run.py +0 -0
- {unitlab-1.7.9 → unitlab-1.8.0}/src/unitlab.egg-info/SOURCES.txt +0 -0
- {unitlab-1.7.9 → unitlab-1.8.0}/src/unitlab.egg-info/dependency_links.txt +0 -0
- {unitlab-1.7.9 → unitlab-1.8.0}/src/unitlab.egg-info/entry_points.txt +0 -0
- {unitlab-1.7.9 → unitlab-1.8.0}/src/unitlab.egg-info/requires.txt +0 -0
- {unitlab-1.7.9 → unitlab-1.8.0}/src/unitlab.egg-info/top_level.txt +0 -0
@@ -1,8 +1,6 @@
|
|
1
1
|
import argparse
|
2
2
|
import asyncio
|
3
|
-
import errno
|
4
3
|
import glob
|
5
|
-
import logging
|
6
4
|
import os
|
7
5
|
import re
|
8
6
|
from io import BytesIO
|
@@ -116,54 +114,60 @@ def task_statistics(namespace):
|
|
116
114
|
|
117
115
|
|
118
116
|
def task_upload_datasources(namespace):
|
119
|
-
|
117
|
+
if not os.path.exists(namespace.input_dir):
|
118
|
+
raise ValueError(f"Directory {namespace.input_dir} does not exist.")
|
119
|
+
|
120
|
+
async def upload_images(session, endpoint, task_id, images, progress_bar):
|
121
|
+
for file_path in images:
|
122
|
+
with open(file_path, "rb") as image:
|
123
|
+
async with session.post(
|
124
|
+
endpoint,
|
125
|
+
data=aiohttp.FormData(fields={"task": task_id, "image": image}),
|
126
|
+
) as response:
|
127
|
+
if response.status != 201:
|
128
|
+
raise Exception(
|
129
|
+
f"Failed to upload file {file_path}. HTTP status code: {response.status}"
|
130
|
+
)
|
131
|
+
progress_bar.update(os.path.getsize(file_path))
|
132
|
+
await response.read()
|
133
|
+
|
134
|
+
async def upload_images_in_batches(
|
135
|
+
folder: str, api_key: str, task_id: str, batch_size=1000
|
136
|
+
):
|
137
|
+
images = [
|
138
|
+
image
|
139
|
+
for images_list in [
|
140
|
+
glob.glob(os.path.join(folder, "") + extension)
|
141
|
+
for extension in ["*jpg", "*png"]
|
142
|
+
]
|
143
|
+
for image in images_list
|
144
|
+
]
|
145
|
+
total_size = sum(os.path.getsize(f) for f in images)
|
146
|
+
endpoint = ENPOINTS[namespace.func.__name__]
|
147
|
+
|
148
|
+
with tqdm.tqdm(total=total_size, unit="B", unit_scale=True) as progress_bar:
|
149
|
+
async with aiohttp.ClientSession(
|
150
|
+
headers={"Authorization": f"Api-Key {api_key}"}
|
151
|
+
) as session:
|
152
|
+
for i in range(0, len(images), batch_size):
|
153
|
+
batch_images = images[i : i + batch_size]
|
154
|
+
tasks = [
|
155
|
+
asyncio.create_task(
|
156
|
+
upload_images(
|
157
|
+
session, endpoint, task_id, batch_images, progress_bar
|
158
|
+
)
|
159
|
+
)
|
160
|
+
]
|
161
|
+
await asyncio.gather(*tasks)
|
120
162
|
|
121
163
|
try:
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
raise
|
126
|
-
|
127
|
-
async def post_image(session: aiohttp.ClientSession, image: str, task_id: str):
|
128
|
-
with open(image, "rb") as img:
|
129
|
-
await session.request(
|
130
|
-
"POST",
|
131
|
-
url=ENPOINTS[namespace.func.__name__],
|
132
|
-
data=aiohttp.FormData(fields={"task": task_id, "image": img}),
|
164
|
+
asyncio.run(
|
165
|
+
upload_images_in_batches(
|
166
|
+
namespace.input_dir, namespace.api_key, namespace.uuid, batch_size=1000
|
133
167
|
)
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
async with aiohttp.ClientSession(
|
138
|
-
headers={"Authorization": f"Api-Key {api_key}"}
|
139
|
-
) as session:
|
140
|
-
total_bytes = 0
|
141
|
-
tasks = []
|
142
|
-
images = [
|
143
|
-
image
|
144
|
-
for images_list in [
|
145
|
-
glob.glob(os.path.join(folder, "") + extension)
|
146
|
-
for extension in ["*jpg", "*png"]
|
147
|
-
]
|
148
|
-
for image in images_list
|
149
|
-
]
|
150
|
-
for image in images:
|
151
|
-
total_bytes += os.path.getsize(image)
|
152
|
-
for image in images:
|
153
|
-
tasks.append(post_image(session=session, image=image, task_id=task_id))
|
154
|
-
|
155
|
-
pbar = tqdm.tqdm(
|
156
|
-
total=total_bytes,
|
157
|
-
unit="B",
|
158
|
-
unit_scale=True,
|
159
|
-
unit_divisor=1024,
|
160
|
-
ncols=80,
|
161
|
-
)
|
162
|
-
for f in asyncio.as_completed(tasks):
|
163
|
-
value = await f
|
164
|
-
pbar.update(value)
|
165
|
-
|
166
|
-
asyncio.run(data_upload(namespace.input_dir, namespace.api_key, namespace.uuid))
|
168
|
+
)
|
169
|
+
except Exception as e:
|
170
|
+
print(str(e))
|
167
171
|
|
168
172
|
|
169
173
|
def task_download_data(namespace):
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|