@@ -3567,3 +3567,63 @@ def delete_annotations(project: str, image_names: List[str] = None):
35673567 )
35683568 if response .errors :
35693569 raise AppException (response .errors )
3570+
3571+
3572+ @Trackable
3573+ @validate_arguments
3574+ def attach_document_urls_to_project (
3575+ project : Union [NotEmptyStr , dict ],
3576+ attachments : Union [Path , NotEmptyStr ],
3577+ annotation_status : Optional [NotEmptyStr ] = "NotStarted" ,
3578+ ):
3579+ """Link documents on external storage to SuperAnnotate.
3580+
3581+ :param project: project name or project folder path
3582+ :type project: str or dict
3583+ :param attachments: path to csv file on attachments metadata
3584+ :type attachments: Path-like (str or Path)
3585+ :param annotation_status: value to set the annotation statuses of the linked documents: NotStarted InProgress QualityCheck Returned Completed Skipped
3586+ :type annotation_status: str
3587+
3588+ :return: list of attached documents, list of not attached documents, list of skipped documents
3589+ :rtype: tuple
3590+ """
3591+ project_name , folder_name = extract_project_folder (project )
3592+
3593+ image_data = pd .read_csv (attachments , dtype = str )
3594+ image_data = image_data [~ image_data ["url" ].isnull ()]
3595+ if "name" in image_data .columns :
3596+ image_data ["name" ] = (
3597+ image_data ["name" ]
3598+ .fillna ("" )
3599+ .apply (lambda cell : cell if str (cell ).strip () else str (uuid .uuid4 ()))
3600+ )
3601+ else :
3602+ image_data ["name" ] = [str (uuid .uuid4 ()) for _ in range (len (image_data .index ))]
3603+
3604+ image_data = pd .DataFrame (image_data , columns = ["name" , "url" ])
3605+ img_names_urls = image_data .rename (columns = {"url" : "path" }).to_dict (
3606+ orient = "records"
3607+ )
3608+ list_of_not_uploaded = []
3609+ duplicate_images = []
3610+ for i in range (0 , len (img_names_urls ), 500 ):
3611+ response = controller .attach_urls (
3612+ project_name = project_name ,
3613+ folder_name = folder_name ,
3614+ files = ImageSerializer .deserialize (
3615+ img_names_urls [i : i + 500 ] # noqa: E203
3616+ ),
3617+ annotation_status = annotation_status ,
3618+ )
3619+ if response .errors :
3620+ list_of_not_uploaded .append (response .data [0 ])
3621+ duplicate_images .append (response .data [1 ])
3622+
3623+ list_of_uploaded = [
3624+ image ["name" ]
3625+ for image in img_names_urls
3626+ if image ["name" ] not in list_of_not_uploaded
3627+ ]
3628+
3629+ return list_of_uploaded , list_of_not_uploaded , duplicate_images
0 commit comments