synapse-sdk 1.0.0a82__py3-none-any.whl → 1.0.0a83__py3-none-any.whl

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.

Potentially problematic release.


This version of synapse-sdk might be problematic. Click here for more details.

@@ -1,7 +1,7 @@
1
1
  import json
2
2
  from datetime import datetime
3
3
  from enum import Enum
4
- from typing import Annotated, Any, Dict, List, Optional
4
+ from typing import Annotated, Any, Dict, List, Optional, Tuple
5
5
 
6
6
  import requests
7
7
  from pydantic import AfterValidator, BaseModel, field_validator
@@ -382,7 +382,7 @@ class ToTaskAction(Action):
382
382
  data_file = files.get(target_specification_name)
383
383
 
384
384
  # Extract primary file URL from task data
385
- primary_file_url = self._extract_primary_file_url(task)
385
+ primary_file_url, primary_file_original_name = self._extract_primary_file_url(task)
386
386
  if not primary_file_url:
387
387
  error_msg = 'Primary image URL not found in task data'
388
388
  self.run.log_message(f'{error_msg} for task {task_id}')
@@ -396,6 +396,13 @@ class ToTaskAction(Action):
396
396
  return {'success': False, 'error': error_msg}
397
397
 
398
398
  data_file_url = data_file.get('url')
399
+ data_file_original_name = data_file.get('file_name_original')
400
+ if not data_file_original_name:
401
+ error_msg = 'File original name not found'
402
+ self.run.log_message(f'{error_msg} for task {task_id}')
403
+ self.run.log_annotate_task_data({'task_id': task_id, 'error': error_msg}, AnnotateTaskDataStatus.FAILED)
404
+ return {'success': False, 'error': error_msg}
405
+
399
406
  if not data_file_url:
400
407
  error_msg = 'URL not found'
401
408
  self.run.log_message(f'{error_msg} for task {task_id}')
@@ -406,7 +413,9 @@ class ToTaskAction(Action):
406
413
  try:
407
414
  # Convert data to task object
408
415
  annotation_to_task = self.entrypoint(self.run)
409
- converted_data = annotation_to_task.convert_data_from_file(primary_file_url, data_file_url)
416
+ converted_data = annotation_to_task.convert_data_from_file(
417
+ primary_file_url, primary_file_original_name, data_file_url, data_file_original_name
418
+ )
410
419
  except requests.RequestException as e:
411
420
  error_msg = f'Failed to fetch data from URL: {str(e)}'
412
421
  self.run.log_message(f'{error_msg} for task {task_id}')
@@ -467,7 +476,7 @@ class ToTaskAction(Action):
467
476
  return pre_processor_status
468
477
 
469
478
  # Extract primary file URL from task data
470
- primary_file_url = self._extract_primary_file_url(task)
479
+ primary_file_url, _ = self._extract_primary_file_url(task)
471
480
  if not primary_file_url:
472
481
  error_msg = 'Primary image URL not found in task data'
473
482
  self.run.log_message(f'{error_msg} for task {task_id}')
@@ -609,23 +618,23 @@ class ToTaskAction(Action):
609
618
  except Exception as e:
610
619
  return {'success': False, 'error': f'Failed to restart pre-processor: {str(e)}'}
611
620
 
612
- def _extract_primary_file_url(self, task: Dict[str, Any]) -> Optional[str]:
621
+ def _extract_primary_file_url(self, task: Dict[str, Any]) -> Tuple[str, str]:
613
622
  """Extract the primary file URL from task data.
614
623
 
615
624
  Args:
616
625
  task (Dict[str, Any]): The task data.
617
626
 
618
627
  Returns:
619
- Optional[str]: The primary file URL if found, None otherwise.
628
+ Tuple[str, str]: The primary file URL and original name.
620
629
  """
621
630
  data_unit = task.get('data_unit', {})
622
631
  files = data_unit.get('files', {})
623
632
 
624
633
  for file_info in files.values():
625
634
  if isinstance(file_info, dict) and file_info.get('is_primary') and file_info.get('url'):
626
- return file_info['url']
635
+ return file_info['url'], file_info['file_name_original']
627
636
 
628
- return None
637
+ return None, None
629
638
 
630
639
  def _run_inference(
631
640
  self, client: BackendClient, pre_processor_code: str, pre_processor_version: str, primary_file_url: str
@@ -7,12 +7,20 @@ class AnnotationToTask:
7
7
  """
8
8
  self.run = run
9
9
 
10
- def convert_data_from_file(self, primary_file_url: str, data_file_url: str) -> dict:
10
+ def convert_data_from_file(
11
+ self,
12
+ primary_file_url: str,
13
+ primary_file_original_name: str,
14
+ data_file_url: str,
15
+ data_file_original_name: str,
16
+ ) -> dict:
11
17
  """Convert the data from a file to a task object.
12
18
 
13
19
  Args:
14
20
  primary_file_url (str): primary file url.
21
+ primary_file_original_name (str): primary file original name.
15
22
  data_file_url (str): data file url.
23
+ data_file_original_name (str): data file original name.
16
24
 
17
25
  Returns:
18
26
  dict: The converted data.
@@ -116,12 +116,13 @@ class COCOToDMConverter(ToDMConverter):
116
116
  result[img_filename] = (dm_json, img_path)
117
117
  return result
118
118
 
119
- def convert_single_file(self, data: Dict[str, Any], original_file: IO) -> Dict[str, Any]:
119
+ def convert_single_file(self, data: Dict[str, Any], original_file: IO, original_image_name: str) -> Dict[str, Any]:
120
120
  """Convert a single COCO annotation data and corresponding image to DM format.
121
121
 
122
122
  Args:
123
123
  data: COCO format data dictionary (JSON content)
124
124
  original_file: File object for the corresponding original image
125
+ original_image_name: Original image name
125
126
 
126
127
  Returns:
127
128
  Dictionary containing DM format data for the single file
@@ -147,7 +148,7 @@ class COCOToDMConverter(ToDMConverter):
147
148
  matched_img = None
148
149
  for img in images:
149
150
  for key in ['file_name', 'filename', 'name']:
150
- if key in img and os.path.basename(img[key]) == img_basename:
151
+ if key in img and os.path.basename(img[key]) == original_image_name:
151
152
  matched_img = img
152
153
  break
153
154
  if matched_img:
@@ -157,7 +158,6 @@ class COCOToDMConverter(ToDMConverter):
157
158
  raise ValueError(f'No matching image found in COCO data for file: {img_basename}')
158
159
 
159
160
  img_id = matched_img['id']
160
- print('img_id : ', img_id)
161
161
  cat_map = {cat['id']: cat for cat in categories}
162
162
  anns = [ann for ann in annotations if ann['image_id'] == img_id]
163
163
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: synapse-sdk
3
- Version: 1.0.0a82
3
+ Version: 1.0.0a83
4
4
  Summary: synapse sdk
5
5
  Author-email: datamaker <developer@datamaker.io>
6
6
  License: MIT
@@ -152,11 +152,11 @@ synapse_sdk/plugins/categories/post_annotation/templates/plugin/post_annotation.
152
152
  synapse_sdk/plugins/categories/pre_annotation/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
153
153
  synapse_sdk/plugins/categories/pre_annotation/actions/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
154
154
  synapse_sdk/plugins/categories/pre_annotation/actions/pre_annotation.py,sha256=6ib3RmnGrjpsQ0e_G-mRH1lfFunQ3gh2M831vuDn7HU,344
155
- synapse_sdk/plugins/categories/pre_annotation/actions/to_task.py,sha256=pmoOkDE5vidvlW_ZNabdOf7CuoRKZlQ0p_bvA7leCyw,31572
155
+ synapse_sdk/plugins/categories/pre_annotation/actions/to_task.py,sha256=otUpG2TfDPMyigFFe0GuqPc2myh9hZC1iBzx-L7QMio,32138
156
156
  synapse_sdk/plugins/categories/pre_annotation/templates/config.yaml,sha256=VREoCp9wsvZ8T2E1d_MEKlR8TC_herDJGVQtu3ezAYU,589
157
157
  synapse_sdk/plugins/categories/pre_annotation/templates/plugin/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
158
158
  synapse_sdk/plugins/categories/pre_annotation/templates/plugin/pre_annotation.py,sha256=HBHxHuv2gMBzDB2alFfrzI_SZ1Ztk6mo7eFbR5GqHKw,106
159
- synapse_sdk/plugins/categories/pre_annotation/templates/plugin/to_task.py,sha256=2lGOIAns1V8GWt-lUU-i9lpdk-AJ6vNY8s7Ks7a72BY,883
159
+ synapse_sdk/plugins/categories/pre_annotation/templates/plugin/to_task.py,sha256=LfM3pWfBYZfTJjpCDq89eo--uAKi-sgs8PWkilj31tI,1135
160
160
  synapse_sdk/plugins/categories/smart_tool/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
161
161
  synapse_sdk/plugins/categories/smart_tool/actions/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
162
162
  synapse_sdk/plugins/categories/smart_tool/actions/auto_label.py,sha256=fHiqA8ntmzjs2GMVMuByR7Clh2zhLie8OPF9B8OmwxM,1279
@@ -199,7 +199,7 @@ synapse_sdk/utils/string.py,sha256=rEwuZ9SAaZLcQ8TYiwNKr1h2u4CfnrQx7SUL8NWmChg,2
199
199
  synapse_sdk/utils/converters/__init__.py,sha256=xQi_n7xS9BNyDiolsxH2jw1CtD6avxMPj2cHnwvidi8,11311
200
200
  synapse_sdk/utils/converters/coco/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
201
201
  synapse_sdk/utils/converters/coco/from_dm.py,sha256=B9zvb8Kph9haYLVIZhzneWiHCImFbuWqAaE7g6Nk0lI,11365
202
- synapse_sdk/utils/converters/coco/to_dm.py,sha256=YmD_NHKSUL8RZbzWX52FgDaJG0uX4I8f8Omp7ilhSec,9054
202
+ synapse_sdk/utils/converters/coco/to_dm.py,sha256=SOzzACYlK0vJE6SIpmFwMUV1ZbdmsQ_t5mceG0SQahE,9105
203
203
  synapse_sdk/utils/converters/dm/__init__.py,sha256=_B6w814bMPhisNCNlSPEiQOs9RH0EZHQqd89LnVhD1U,1983
204
204
  synapse_sdk/utils/converters/dm/from_v1.py,sha256=4BG_NA_7YdW5rI1F8LCFg39M-IJZVfRgi2b9FBxTAmw,26059
205
205
  synapse_sdk/utils/converters/dm/to_v1.py,sha256=A123zAR_dLqEW83BgAl5_J1ACstjZWTHivlW5qvOu_E,13432
@@ -220,9 +220,9 @@ synapse_sdk/utils/storage/providers/gcp.py,sha256=i2BQCu1Kej1If9SuNr2_lEyTcr5M_n
220
220
  synapse_sdk/utils/storage/providers/http.py,sha256=2DhIulND47JOnS5ZY7MZUex7Su3peAPksGo1Wwg07L4,5828
221
221
  synapse_sdk/utils/storage/providers/s3.py,sha256=ZmqekAvIgcQBdRU-QVJYv1Rlp6VHfXwtbtjTSphua94,2573
222
222
  synapse_sdk/utils/storage/providers/sftp.py,sha256=_8s9hf0JXIO21gvm-JVS00FbLsbtvly4c-ETLRax68A,1426
223
- synapse_sdk-1.0.0a82.dist-info/licenses/LICENSE,sha256=bKzmC5YAg4V1Fhl8OO_tqY8j62hgdncAkN7VrdjmrGk,1101
224
- synapse_sdk-1.0.0a82.dist-info/METADATA,sha256=tCCYQhZDkDvBXPSQa50Dzur5VrBpp9Hm7fWI6jHxFBA,3805
225
- synapse_sdk-1.0.0a82.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
226
- synapse_sdk-1.0.0a82.dist-info/entry_points.txt,sha256=VNptJoGoNJI8yLXfBmhgUefMsmGI0m3-0YoMvrOgbxo,48
227
- synapse_sdk-1.0.0a82.dist-info/top_level.txt,sha256=ytgJMRK1slVOKUpgcw3LEyHHP7S34J6n_gJzdkcSsw8,12
228
- synapse_sdk-1.0.0a82.dist-info/RECORD,,
223
+ synapse_sdk-1.0.0a83.dist-info/licenses/LICENSE,sha256=bKzmC5YAg4V1Fhl8OO_tqY8j62hgdncAkN7VrdjmrGk,1101
224
+ synapse_sdk-1.0.0a83.dist-info/METADATA,sha256=JFd43LG4HIkMQZECtk_O7CBHF3vBdNHd2LWH9W5VtjQ,3805
225
+ synapse_sdk-1.0.0a83.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
226
+ synapse_sdk-1.0.0a83.dist-info/entry_points.txt,sha256=VNptJoGoNJI8yLXfBmhgUefMsmGI0m3-0YoMvrOgbxo,48
227
+ synapse_sdk-1.0.0a83.dist-info/top_level.txt,sha256=ytgJMRK1slVOKUpgcw3LEyHHP7S34J6n_gJzdkcSsw8,12
228
+ synapse_sdk-1.0.0a83.dist-info/RECORD,,