@@ -761,51 +761,18 @@ def attach_image_urls_to_project(
761761 project , attachments , annotation_status = "NotStarted"
762762):
763763 """Link images on external storage to SuperAnnotate.
764-
764+
765765 :param project: project name or project folder path
766766 :type project: str or dict
767767 :param attachments: path to csv file on attachments metadata
768768 :type attachments: Pathlike (str or Path)
769769 :param annotation_status: value to set the annotation statuses of the linked images: NotStarted InProgress QualityCheck Returned Completed Skipped
770770 :type annotation_status: str
771771
772- :return: list of linked image names, list of failed image names, list of duplicate image names
773- :rtype: tuple
772+ :return: attached images, failed images, skipped images
773+ :rtype: (list, list, list)
774774 """
775- project , folder = get_project_and_folder_metadata (project )
776- folder_name = project ["name" ] + (f'/{ folder ["name" ]} ' if folder else "" )
777- upload_state = common .upload_state_int_to_str (project .get ("upload_state" ))
778- if upload_state == "Basic" :
779- raise SABaseException (
780- 0 ,
781- "You cannot attach URLs in this type of project. Please attach it in an external storage project"
782- )
783- annotation_status = common .annotation_status_str_to_int (annotation_status )
784- team_id , project_id = project ["team_id" ], project ["id" ]
785- image_data = pd .read_csv (attachments , dtype = str )
786- image_data = image_data [~ image_data ["url" ].isnull ()]
787- for ind , _ in image_data [image_data ["name" ].isnull ()].iterrows ():
788- name_try = str (uuid .uuid4 ())
789- image_data .at [ind , "name" ] = name_try
790- image_data = pd .DataFrame (image_data , columns = ["name" , "url" ])
791- img_names_urls = image_data .values .tolist ()
792-
793- if folder :
794- folder_id = folder ["id" ]
795- else :
796- folder_id = get_project_root_folder_id (project )
797-
798- list_of_uploaded , list_of_not_uploaded , duplicate_images = _attach_urls (
799- img_names_urls = img_names_urls ,
800- team_id = team_id ,
801- folder_id = folder_id ,
802- project_id = project_id ,
803- annotation_status = annotation_status ,
804- project = project ,
805- folder_name = folder_name
806- )
807-
808- return (list_of_uploaded , list_of_not_uploaded , duplicate_images )
775+ return attach_file_urls_to_project (project , attachments , annotation_status )
809776
810777
811778@Trackable
@@ -1993,3 +1960,79 @@ def clone_project(
19931960 metadata ["description" ] = project_description
19941961
19951962 return create_project_from_metadata (metadata )
1963+
1964+
1965+
1966+ @Trackable
1967+ def attach_video_urls_to_project (project , attachments , annotation_status = "NotStarted" ):
1968+ """Link videos on external storage to SuperAnnotate.
1969+
1970+ :param project: project name or project folder path
1971+ :type project: str or dict
1972+
1973+ :param attachments: path to csv file on attachments metadata
1974+ :type attachments: Path-like (str or Path)
1975+
1976+ :param annotation_status: value to set the annotation statuses of the linked videos: NotStarted InProgress QualityCheck Returned Completed Skipped
1977+ :type annotation_status: str
1978+
1979+ :return: attached videos, failed videos, skipped videos
1980+ :rtype: (list, list, list)
1981+ """
1982+ return attach_file_urls_to_project (project , attachments , annotation_status )
1983+
1984+
1985+ def attach_file_urls_to_project (project , attachments , annotation_status ):
1986+ """Link files on external storage to SuperAnnotate.
1987+
1988+ :param project: project name or project folder path
1989+ :type project: str or dict
1990+
1991+ :param attachments: path to csv file on attachments metadata
1992+ :type attachments: Path-like (str or Path)
1993+
1994+ :param annotation_status: value to set the annotation statuses of the linked files: NotStarted InProgress QualityCheck Returned Completed Skipped
1995+ :type annotation_status: str
1996+
1997+ :return: attached files, failed files, skipped files
1998+ :rtype: (list, list, list)
1999+ """
2000+ project , folder = get_project_and_folder_metadata (project )
2001+ folder_name = project ["name" ] + (f'/{ folder ["name" ]} ' if folder else "" )
2002+ upload_state = common .upload_state_int_to_str (project .get ("upload_state" ))
2003+ if upload_state == "Basic" :
2004+ raise SABaseException (
2005+ 0 ,
2006+ "You cannot attach URLs in this type of project. Please attach it in an external storage project"
2007+ )
2008+ annotation_status = common .annotation_status_str_to_int (annotation_status )
2009+ team_id , project_id = project ["team_id" ], project ["id" ]
2010+ df = pd .read_csv (attachments , dtype = str )
2011+ df = df [~ df ["url" ].isnull ()]
2012+
2013+ if "name" in df .columns :
2014+ df .loc [df ["name" ].isnull (), "name" ] = [
2015+ str (uuid .uuid4 ()) for _ in range (df ["name" ].isnull ().sum ())
2016+ ]
2017+ else :
2018+ df ["name" ] = [str (uuid .uuid4 ()) for _ in range (len (df .index ))]
2019+
2020+ df = pd .DataFrame (df , columns = ["name" , "url" ])
2021+ df_names_urls = df .values .tolist ()
2022+
2023+ if folder :
2024+ folder_id = folder ["id" ]
2025+ else :
2026+ folder_id = get_project_root_folder_id (project )
2027+
2028+ list_of_uploaded , list_of_not_uploaded , list_of_duplicated = _attach_urls (
2029+ file_urls = df_names_urls ,
2030+ team_id = team_id ,
2031+ folder_id = folder_id ,
2032+ project_id = project_id ,
2033+ annotation_status = annotation_status ,
2034+ project = project ,
2035+ folder_name = folder_name
2036+ )
2037+
2038+ return list_of_uploaded , list_of_not_uploaded , list_of_duplicated
0 commit comments