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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: unitlab
3
- Version: 2.3.47
3
+ Version: 2.3.48
4
4
  Home-page: https://github.com/teamunitlab/unitlab-sdk
5
5
  Author: Unitlab Inc.
6
6
  Author-email: team@unitlab.ai
@@ -2,7 +2,7 @@ from setuptools import find_packages, setup
2
2
 
3
3
  setup(
4
4
  name="unitlab",
5
- version="2.3.47",
5
+ version="2.3.48",
6
6
  license="MIT",
7
7
  author="Unitlab Inc.",
8
8
  author_email="team@unitlab.ai",
@@ -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, project_id, directory, batch_size=100, sentences_per_chunk=10
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, max size is {max_file_size_mb:.2f} MB"
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
- folder = f"dataset-files-{dataset_id}"
228
- os.makedirs(folder, exist_ok=True)
229
- dataset_files = [
230
- dataset_file
231
- for dataset_file in response
232
- if not os.path.isfile(os.path.join(folder, dataset_file["file_name"]))
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(dataset_files), ncols=80) as pbar:
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=dataset_file)
256
- for dataset_file in dataset_files
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), directory=directory, sentences_per_chunk=sentences_per_chunk
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
- return get_client(api_key).dataset_download(pk, export_type, split_type)
117
- get_client(api_key).dataset_download_files(pk)
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__":
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: unitlab
3
- Version: 2.3.47
3
+ Version: 2.3.48
4
4
  Home-page: https://github.com/teamunitlab/unitlab-sdk
5
5
  Author: Unitlab Inc.
6
6
  Author-email: team@unitlab.ai
File without changes
File without changes
File without changes
File without changes