Skip to content

Commit 0a76211

Browse files
committed
2 parents 73fd6fc + 53a76e0 commit 0a76211

File tree

5 files changed

+166
-88
lines changed

5 files changed

+166
-88
lines changed

src/superannotate/lib/app/interface/sdk_interface.py

Lines changed: 40 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ def create_project(project_name: str, project_description: str, project_type: st
183183
name=project_name, description=project_description, project_type=project_type
184184
)
185185
if response.errors:
186-
raise Exception(response.errors)
186+
raise AppException(response.errors)
187187

188188
return ProjectSerializer(response.data).serialize()
189189

@@ -208,7 +208,7 @@ def create_project_from_metadata(project_metadata: dict):
208208
workflows=project_metadata.get("workflow", []),
209209
)
210210
if response.errors:
211-
raise Exception(response.errors)
211+
raise AppException(response.errors)
212212
return ProjectSerializer(response.data).serialize()
213213

214214

@@ -254,7 +254,7 @@ def clone_project(
254254
copy_contributors=copy_contributors,
255255
)
256256
if response.errors:
257-
raise AppValidationException(response.errors)
257+
raise AppException(response.errors)
258258
return ProjectSerializer(response.data).serialize()
259259

260260

@@ -292,7 +292,7 @@ def search_images(
292292
image_name_prefix=image_name_prefix,
293293
)
294294
if response.errors:
295-
raise AppValidationException(response.errors)
295+
raise AppException(response.errors)
296296

297297
if return_metadata:
298298
return [ImageSerializer(image).serialize() for image in response.data]
@@ -526,7 +526,7 @@ def copy_image(
526526

527527
project = controller.get_project_metadata(destination_project).data
528528
if project["project"].project_type == constances.ProjectType.VIDEO.value:
529-
raise AppValidationException(
529+
raise AppException(
530530
"The function does not support projects containing videos attached with URLs"
531531
)
532532

@@ -740,7 +740,7 @@ def copy_images(
740740
include_pin=copy_pin,
741741
)
742742
if res.errors:
743-
raise AppValidationException(res.errors)
743+
raise AppException(res.errors)
744744
skipped_images = res.data
745745
done_count = len(image_names) - len(skipped_images)
746746
message_postfix = "{from_path} to {to_path}."
@@ -781,7 +781,7 @@ def move_images(
781781

782782
project = controller.get_project_metadata(project_name).data
783783
if project["project"].project_type == constances.ProjectType.VIDEO.value:
784-
raise AppValidationException(
784+
raise AppException(
785785
"The function does not support projects containing videos attached with URLs"
786786
)
787787

@@ -909,7 +909,7 @@ def get_project_workflow(project: Union[str, dict]):
909909
project_name, folder_name = extract_project_folder(project)
910910
workflow = controller.get_project_workflow(project_name=project_name)
911911
if workflow.errors:
912-
raise AppValidationException(workflow.errors)
912+
raise AppException(workflow.errors)
913913
return workflow.data
914914

915915

@@ -993,7 +993,7 @@ def set_project_default_image_quality_in_editor(
993993
new_settings=[{"attribute": "ImageQuality", "value": image_quality_in_editor}],
994994
)
995995
if response.errors:
996-
raise AppValidationException(response.errors)
996+
raise AppException(response.errors)
997997
return response.data
998998

999999

@@ -1051,7 +1051,7 @@ def get_image_metadata(project: Union[str, dict], image_name: str, *_, **__):
10511051
project_name, folder_name = extract_project_folder(project)
10521052
response = controller.get_image_metadata(project_name, folder_name, image_name)
10531053
if response.errors:
1054-
raise AppValidationException(response.errors)
1054+
raise AppException(response.errors)
10551055

10561056
res_data = response.data
10571057
res_data["annotation_status"] = constances.AnnotationStatus.get_name(
@@ -1086,7 +1086,7 @@ def set_images_annotation_statuses(
10861086
project_name, folder_name, image_names, annotation_status
10871087
)
10881088
if response.errors:
1089-
raise AppValidationException(response.errors)
1089+
raise AppException(response.errors)
10901090
logger.info("Annotations status of images changed")
10911091

10921092

@@ -1103,13 +1103,13 @@ def delete_images(project: Union[str, dict], image_names: Optional[List[str]] =
11031103
project_name, folder_name = extract_project_folder(project)
11041104

11051105
if not isinstance(image_names, list) and image_names is not None:
1106-
raise AppValidationException("Image_names should be a list of strs or None.")
1106+
raise AppException("Image_names should be a list of strs or None.")
11071107

11081108
response = controller.delete_images(
11091109
project_name=project_name, folder_name=folder_name, image_names=image_names
11101110
)
11111111
if response.errors:
1112-
raise AppValidationException(response.errors)
1112+
raise AppException(response.errors)
11131113

11141114
logger.info(
11151115
f"Images deleted in project {project_name}{'' if folder_name else '/' + folder_name}"
@@ -1360,6 +1360,12 @@ def upload_images_from_folder_to_project(
13601360
"extensions should be a list or a tuple in upload_images_from_folder_to_project"
13611361
)
13621362

1363+
if exclude_file_patterns:
1364+
exclude_file_patterns = list(exclude_file_patterns) + list(
1365+
constances.DEFAULT_FILE_EXCLUDE_PATTERNS
1366+
)
1367+
exclude_file_patterns = list(set(exclude_file_patterns))
1368+
13631369
project_folder_name = project_name + (f"/{folder_name}" if folder_name else "")
13641370

13651371
logger.info(
@@ -1394,7 +1400,7 @@ def upload_images_from_folder_to_project(
13941400
for _ in use_case.execute():
13951401
progress_bar.update(1)
13961402
return use_case.data
1397-
raise AppValidationException(use_case.response.errors)
1403+
raise AppException(use_case.response.errors)
13981404

13991405

14001406
@Trackable
@@ -1421,7 +1427,7 @@ def get_project_image_count(
14211427
with_all_subfolders=with_all_subfolders,
14221428
)
14231429
if response.errors:
1424-
raise AppValidationException(response.errors)
1430+
raise AppException(response.errors)
14251431
return response.data
14261432

14271433

@@ -1475,7 +1481,7 @@ def download_image_annotations(
14751481
destination=local_dir_path,
14761482
)
14771483
if res.errors:
1478-
raise AppValidationException(res.errors)
1484+
raise AppException(res.errors)
14791485
return res.data
14801486

14811487

@@ -1505,7 +1511,7 @@ def download_image_preannotations(
15051511
destination=local_dir_path,
15061512
)
15071513
if res.errors:
1508-
raise AppValidationException(res.errors)
1514+
raise AppException(res.errors)
15091515
return res.data
15101516

15111517

@@ -1617,7 +1623,7 @@ def prepare_export(
16171623
annotation_statuses=annotation_statuses,
16181624
)
16191625
if response.errors:
1620-
raise AppValidationException(response.errors)
1626+
raise AppException(response.errors)
16211627
return response.data
16221628

16231629

@@ -1741,7 +1747,7 @@ def upload_videos_from_folder_to_project(
17411747
for _ in use_case.execute():
17421748
progress_bar.update(1)
17431749
else:
1744-
raise AppValidationException(use_case.response.errors)
1750+
raise AppException(use_case.response.errors)
17451751

17461752
return
17471753

@@ -1812,7 +1818,7 @@ def upload_video_to_project(
18121818
for _ in use_case.execute():
18131819
progress_bar.update(1)
18141820
return use_case.data[0]
1815-
raise AppValidationException(use_case.response.errors)
1821+
raise AppException(use_case.response.errors)
18161822

18171823

18181824
@Trackable
@@ -1975,7 +1981,7 @@ def move_image(
19751981
source_project_name, source_folder_name = extract_project_folder(source_project)
19761982
project = controller.get_project_metadata(source_project_name).data
19771983
if project["project"].project_type == constances.ProjectType.VIDEO.value:
1978-
raise AppValidationException(
1984+
raise AppException(
19791985
"The function does not support projects containing videos attached with URLs"
19801986
)
19811987

@@ -2110,7 +2116,7 @@ def set_image_annotation_status(
21102116
project_name, folder_name, [image_name], annotation_status
21112117
)
21122118
if response.errors:
2113-
raise AppValidationException(response.errors)
2119+
raise AppException(response.errors)
21142120

21152121

21162122
@Trackable
@@ -2133,7 +2139,7 @@ def set_project_workflow(project: Union[str, dict], new_workflow: List[dict]):
21332139
project_name=project_name, steps=new_workflow
21342140
)
21352141
if response.errors:
2136-
raise AppValidationException(response.errors)
2142+
raise AppException(response.errors)
21372143

21382144

21392145
@Trackable
@@ -2215,7 +2221,7 @@ def download_image(
22152221
include_overlay=include_overlay,
22162222
)
22172223
if response.errors:
2218-
raise AppValidationException(response.errors)
2224+
raise AppException(response.errors)
22192225
return response.data
22202226

22212227

@@ -2241,7 +2247,7 @@ def attach_image_urls_to_project(
22412247
project_name, folder_name = extract_project_folder(project)
22422248
project = controller.get_project_metadata(project_name).data
22432249
if project["project"].project_type == constances.ProjectType.VIDEO.value:
2244-
raise AppValidationException(
2250+
raise AppException(
22452251
"The function does not support projects containing videos attached with URLs"
22462252
)
22472253

@@ -2303,7 +2309,7 @@ def attach_video_urls_to_project(
23032309
project_name, folder_name = extract_project_folder(project)
23042310
project = controller.get_project_metadata(project_name).data
23052311
if project["project"].project_type != constances.ProjectType.VIDEO.value:
2306-
raise AppValidationException("The function does not support")
2312+
raise AppException("The function does not support")
23072313

23082314
image_data = pd.read_csv(attachments, dtype=str)
23092315
image_data = image_data[~image_data["url"].isnull()]
@@ -2379,7 +2385,7 @@ def upload_annotations_from_folder_to_project(
23792385
project_name, folder_name = extract_project_folder(project)
23802386
project = controller.get_project_metadata(project_name).data
23812387
if project["project"].project_type == constances.ProjectType.VIDEO.value:
2382-
raise AppValidationException(
2388+
raise AppException(
23832389
"The function does not support projects containing videos attached with URLs"
23842390
)
23852391

@@ -2460,7 +2466,7 @@ def upload_preannotations_from_folder_to_project(
24602466
project_name, folder_name = extract_project_folder(project)
24612467
project = controller.get_project_metadata(project_name).data
24622468
if project["project"].project_type == constances.ProjectType.VIDEO.value:
2463-
raise AppValidationException(
2469+
raise AppException(
24642470
"The function does not support projects containing videos attached with URLs"
24652471
)
24662472

@@ -2552,7 +2558,7 @@ def upload_image_annotations(
25522558
verbose=verbose,
25532559
)
25542560
if response.errors:
2555-
raise AppValidationException(response.errors)
2561+
raise AppException(response.errors)
25562562

25572563

25582564
@Trackable
@@ -2783,7 +2789,7 @@ def benchmark(
27832789
show_plots=show_plots,
27842790
)
27852791
if response.errors:
2786-
raise AppValidationException(response.errors)
2792+
raise AppException(response.errors)
27872793
return response.data
27882794

27892795

@@ -2837,7 +2843,7 @@ def consensus(
28372843
show_plots=show_plots,
28382844
)
28392845
if response.errors:
2840-
raise AppValidationException(response.errors)
2846+
raise AppException(response.errors)
28412847
return response.data
28422848

28432849

@@ -2904,7 +2910,7 @@ def run_prediction(project, images_list, model):
29042910
folder_name=folder_name,
29052911
)
29062912
if response.errors:
2907-
raise Exception(response.errors)
2913+
raise AppException(response.errors)
29082914
return response.data
29092915

29102916

@@ -3305,7 +3311,7 @@ def upload_image_to_project(
33053311

33063312
project = controller.get_project_metadata(project_name).data
33073313
if project["project"].project_type == constances.ProjectType.VIDEO.value:
3308-
raise AppValidationException(
3314+
raise AppException(
33093315
"The function does not support projects containing videos attached with URLs"
33103316
)
33113317

@@ -3395,7 +3401,7 @@ def upload_images_to_project(
33953401
project_name, folder_name = extract_project_folder(project)
33963402
project = controller.get_project_metadata(project_name).data
33973403
if project["project"].project_type == constances.ProjectType.VIDEO.value:
3398-
raise AppValidationException(
3404+
raise AppException(
33993405
"The function does not support projects containing videos attached with URLs"
34003406
)
34013407

0 commit comments

Comments
 (0)