unitlab 2.3.47__tar.gz → 2.3.48__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-2.3.47/src/unitlab.egg-info → unitlab-2.3.48}/PKG-INFO +1 -1
- {unitlab-2.3.47 → unitlab-2.3.48}/setup.py +1 -1
- {unitlab-2.3.47 → unitlab-2.3.48}/src/unitlab/client.py +50 -15
- {unitlab-2.3.47 → unitlab-2.3.48}/src/unitlab/main.py +13 -3
- {unitlab-2.3.47 → unitlab-2.3.48/src/unitlab.egg-info}/PKG-INFO +1 -1
- {unitlab-2.3.47 → unitlab-2.3.48}/LICENSE.md +0 -0
- {unitlab-2.3.47 → unitlab-2.3.48}/README.md +0 -0
- {unitlab-2.3.47 → unitlab-2.3.48}/setup.cfg +0 -0
- {unitlab-2.3.47 → unitlab-2.3.48}/src/unitlab/__init__.py +0 -0
- {unitlab-2.3.47 → unitlab-2.3.48}/src/unitlab/__main__.py +0 -0
- {unitlab-2.3.47 → unitlab-2.3.48}/src/unitlab/exceptions.py +0 -0
- {unitlab-2.3.47 → unitlab-2.3.48}/src/unitlab/utils.py +0 -0
- {unitlab-2.3.47 → unitlab-2.3.48}/src/unitlab.egg-info/SOURCES.txt +0 -0
- {unitlab-2.3.47 → unitlab-2.3.48}/src/unitlab.egg-info/dependency_links.txt +0 -0
- {unitlab-2.3.47 → unitlab-2.3.48}/src/unitlab.egg-info/entry_points.txt +0 -0
- {unitlab-2.3.47 → unitlab-2.3.48}/src/unitlab.egg-info/requires.txt +0 -0
- {unitlab-2.3.47 → unitlab-2.3.48}/src/unitlab.egg-info/top_level.txt +0 -0
|
@@ -117,7 +117,12 @@ class UnitlabClient:
|
|
|
117
117
|
return self._get(f"/api/sdk/projects/{project_id}/upload-info/")
|
|
118
118
|
|
|
119
119
|
def project_upload_data(
|
|
120
|
-
self,
|
|
120
|
+
self,
|
|
121
|
+
project_id,
|
|
122
|
+
directory,
|
|
123
|
+
batch_size=100,
|
|
124
|
+
sentences_per_chunk=10,
|
|
125
|
+
fps=1.0,
|
|
121
126
|
):
|
|
122
127
|
if not os.path.isdir(directory):
|
|
123
128
|
raise ValueError(f"Directory {directory} does not exist")
|
|
@@ -143,7 +148,8 @@ class UnitlabClient:
|
|
|
143
148
|
if file_size_bytes > max_file_size_bytes:
|
|
144
149
|
file_size_mb = file_size_bytes / 1024 / 1024
|
|
145
150
|
logger.warning(
|
|
146
|
-
f"File {file} is too large ({file_size_mb:.4f} MB) skipping,
|
|
151
|
+
f"File {file} is too large ({file_size_mb:.4f} MB) skipping, "
|
|
152
|
+
f"max size is {max_file_size_mb:.2f} MB"
|
|
147
153
|
)
|
|
148
154
|
continue
|
|
149
155
|
filtered_files.append(file)
|
|
@@ -159,6 +165,8 @@ class UnitlabClient:
|
|
|
159
165
|
)
|
|
160
166
|
if generic_type == "text":
|
|
161
167
|
form_data.add_field("sentences_per_chunk", str(sentences_per_chunk))
|
|
168
|
+
elif generic_type == "video":
|
|
169
|
+
form_data.add_field("fps", str(fps))
|
|
162
170
|
|
|
163
171
|
try:
|
|
164
172
|
await asyncio.sleep(0.1)
|
|
@@ -221,16 +229,44 @@ class UnitlabClient:
|
|
|
221
229
|
return os.path.abspath(filename)
|
|
222
230
|
|
|
223
231
|
def dataset_download_files(self, dataset_id):
|
|
232
|
+
"""Download files from a dataset.
|
|
233
|
+
|
|
234
|
+
Args:
|
|
235
|
+
dataset_id: UUID of the dataset/release to download.
|
|
236
|
+
|
|
237
|
+
Returns:
|
|
238
|
+
Path to the download folder.
|
|
239
|
+
"""
|
|
224
240
|
response = self._post(
|
|
225
241
|
f"/api/sdk/datasets/{dataset_id}/", data={"download_type": "files"}
|
|
226
242
|
)
|
|
227
|
-
|
|
228
|
-
os.makedirs(
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
243
|
+
base_folder = f"dataset-files-{dataset_id}"
|
|
244
|
+
os.makedirs(base_folder, exist_ok=True)
|
|
245
|
+
|
|
246
|
+
files_to_download = []
|
|
247
|
+
for dataset_file in response:
|
|
248
|
+
file_name = dataset_file["file_name"]
|
|
249
|
+
file_path = os.path.join(base_folder, file_name)
|
|
250
|
+
|
|
251
|
+
parent_dir = os.path.dirname(file_path)
|
|
252
|
+
if parent_dir:
|
|
253
|
+
os.makedirs(parent_dir, exist_ok=True)
|
|
254
|
+
|
|
255
|
+
if "content" in dataset_file:
|
|
256
|
+
if not os.path.isfile(file_path):
|
|
257
|
+
with open(file_path, "w", encoding="utf-8") as f:
|
|
258
|
+
f.write(dataset_file["content"])
|
|
259
|
+
elif "source" in dataset_file and not os.path.isfile(file_path):
|
|
260
|
+
files_to_download.append(
|
|
261
|
+
{
|
|
262
|
+
"file_name": file_name,
|
|
263
|
+
"source": dataset_file["source"],
|
|
264
|
+
"file_path": file_path,
|
|
265
|
+
}
|
|
266
|
+
)
|
|
267
|
+
|
|
268
|
+
if not files_to_download:
|
|
269
|
+
return base_folder
|
|
234
270
|
|
|
235
271
|
async def download_file(session: aiohttp.ClientSession, dataset_file: dict):
|
|
236
272
|
async with session.get(url=dataset_file["source"]) as r:
|
|
@@ -241,21 +277,20 @@ class UnitlabClient:
|
|
|
241
277
|
f"Error downloading file {dataset_file['file_name']} - {e}"
|
|
242
278
|
)
|
|
243
279
|
return 0
|
|
244
|
-
async with aiofiles.open(
|
|
245
|
-
os.path.join(folder, dataset_file["file_name"]), "wb"
|
|
246
|
-
) as f:
|
|
280
|
+
async with aiofiles.open(dataset_file["file_path"], "wb") as f:
|
|
247
281
|
async for chunk in r.content.iter_any():
|
|
248
282
|
await f.write(chunk)
|
|
249
283
|
return 1
|
|
250
284
|
|
|
251
285
|
async def main():
|
|
252
|
-
with tqdm.tqdm(total=len(
|
|
286
|
+
with tqdm.tqdm(total=len(files_to_download), ncols=80) as pbar:
|
|
253
287
|
async with aiohttp.ClientSession() as session:
|
|
254
288
|
tasks = [
|
|
255
|
-
download_file(session=session, dataset_file=
|
|
256
|
-
for
|
|
289
|
+
download_file(session=session, dataset_file=df)
|
|
290
|
+
for df in files_to_download
|
|
257
291
|
]
|
|
258
292
|
for f in asyncio.as_completed(tasks):
|
|
259
293
|
pbar.update(await f)
|
|
260
294
|
|
|
261
295
|
asyncio.run(main())
|
|
296
|
+
return base_folder
|
|
@@ -78,9 +78,18 @@ def upload(
|
|
|
78
78
|
help="Number of sentences per chunk for text projects (default: 10, range: 3-50)"
|
|
79
79
|
),
|
|
80
80
|
] = 10,
|
|
81
|
+
fps: Annotated[
|
|
82
|
+
float,
|
|
83
|
+
typer.Option(
|
|
84
|
+
help="Frames per second for video projects (default: 1.0, min: 0.25)"
|
|
85
|
+
),
|
|
86
|
+
] = 1.0,
|
|
81
87
|
):
|
|
82
88
|
get_client(api_key).project_upload_data(
|
|
83
|
-
str(pk),
|
|
89
|
+
str(pk),
|
|
90
|
+
directory=directory,
|
|
91
|
+
sentences_per_chunk=sentences_per_chunk,
|
|
92
|
+
fps=fps,
|
|
84
93
|
)
|
|
85
94
|
|
|
86
95
|
|
|
@@ -113,8 +122,9 @@ def dataset_download(
|
|
|
113
122
|
raise typer.BadParameter(
|
|
114
123
|
"Split type is required when download type is annotation"
|
|
115
124
|
)
|
|
116
|
-
|
|
117
|
-
|
|
125
|
+
print(get_client(api_key).dataset_download(pk, export_type, split_type))
|
|
126
|
+
else:
|
|
127
|
+
print(get_client(api_key).dataset_download_files(pk))
|
|
118
128
|
|
|
119
129
|
|
|
120
130
|
if __name__ == "__main__":
|
|
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
|