
    ]j>                         d dl Z d dlZd dlZd dlmZmZmZ d dlmZ d dl	m
ZmZ d dlmZ  ej                   ej"                         d Zd Zd	 Zd
 Zd Zedk(  r e        yy)    N)	ConverterFormatFormatNotSupportedError)ExportToCSV)yolococo)ExpandFullPath)levelc                    | j                  dddddt               | j                  ddd	d
t               | j                  ddddt        j                  j	                  t        j                  j                  t              d      t               | j                  ddddddj	                  d t        D              z   t        j                  t        t              t        j                         | j                  dddd       | j                  ddd d!       | j                  d"d#d$%       | j                  d&d'd d()       | j                  d*d+d!dd,-       | j                  d.d/d!d01       y )2Nz-iz--inputinputTzLDirectory or JSON file with annotations (e.g. "/<project_path>/annotations"))destrequiredhelpactionz-cz--configconfigz2Project config (e.g. "/<project_path>/config.xml"))r   r   r   z-oz--outputoutputz8Output file or directory (will be created if not exists))r   r   defaultr   z-fz--formatformatFORMATzOutput format: z, c              3   4   K   | ]  }|j                     y w)N)name).0fs     I/root/env/lib/python3.12/site-packages/label_studio_sdk/converter/main.py	<genexpr>z"get_export_args.<locals>.<genexpr>.   s     *Ba166*Bs   )r   metavarr   typechoicesr   z--csv-separatorcsv_separatorzSeparator used in CSV format,)r   r   r   z--csv-no-headercsv_no_headerz)Whether to omit header in CSV output file
store_truez--image-dir	image_dirzIn case of image outputs (COCO, VOC, ...), specifies output image directory where downloaded images will be stored. (If not specified, local image paths left untouched)r   r   z--project-dirproject_dirz#Label Studio project directory path)r   r   r   z--heartex-formatheartex_formatzdSet this flag if your annotations are in one JSON file instead of multiple JSON files from directory)r   r   r   r   z--brush-to-cocobrush_to_cocoz:If set, brush annotations will be converted to COCO format)r   r   r   )add_argumentr	   ospathjoindirname__file__r   from_stringlistJSON)parsers    r   get_export_argsr2      s   
[   A   GRWW__X6A   *B6*B!BBV  	 +	   8	   J   2	   s   I	      c                  X   t        j                         } | j                  dd      }d|_        |j	                  dd      }t        |       |j	                  dd	      }|j                  d
      }t        j                  |       t        j                  |       | j                         S )NcommandzAvailable commandsr$   Fexportz@Converter from Label Studio JSON annotations to external formats)r   importz@Converter from external formats to Label Studio JSON annotationsimport_format)r   )	argparseArgumentParseradd_subparsersr   
add_parserr2   import_yoloimport_coco
parse_args)r1   
subparsersparser_exportparser_importr8   s        r   get_all_argsrC   Z   s    $$&F&&I<P&QJJ ))O * M M" ))O * M "00o0FM=)=)r3   c                 h   t        | j                  | j                        }| j                  t        j
                  k(  r'|j                  | j                  | j                         y | j                  t        j                  k(  rO| j                   }| j                  }|j                  | j                  | j                  ||| j                          y | j                  t        j                  k(  rL| j                   }| j                  }t        | j                        j!                  | j                  ||d       y | j                  t        j"                  k(  rE| j                   }d}|j                  | j                  | j                  ||| j                          y | j                  t        j$                  k(  r4|j'                  | j                  | j                  | j                          y | j                  t        j(                  k(  r?|j+                  | j                  | j                  | j,                  | j                          y | j                  t        j.                  k(  r?|j1                  | j                  | j                  | j,                  | j                          y | j                  t        j2                  k(  r4|j5                  | j                  | j                  | j                          y | j                  t        j6                  k(  r5|j5                  | j                  | j                  | j                   d	       y | j                  t        j8                  t        j:                  fv rJ|j=                  | j                  | j                  | j                  | j,                  | j                          y | j                  t        j>                  k(  rN|j=                  | j                  | j                  t        j>                  | j,                  | j                          y tA               )
N)r%   )sepheaderis_dirF)rE   rF   index	)rG   )output_image_dirrG   T)rG   is_obb)!r   r   r%   r   r   r0   convert_to_jsonr   r   CSVr!   r   convert_to_csvr&   CSV_OLDr   to_fileTSV	CONLL2003convert_to_conll2003COCOconvert_to_cocor#   VOCconvert_to_vocYOLOconvert_to_yoloYOLO_OBBYOLO_WITH_IMAGESYOLO_OBB_WITH_IMAGESconvertBRUSH_TO_COCOr   )argscrF   rE   s       r   r6   r6   r   s3   $++4+;+;<A{{fkk!	$**dkk2	

	"'''  	JJKK*** 	 	
 
	&'''  DJJ''KKSu 	( 	
 


	"'''	JJKK*** 	 	
 
((	(	tzz4;;4CVCV?VW		#	JJKK!^^***	 	 	
 


	"	JJKK!^^***	 	 	
 
	#	$**dkkd>Q>Q:QR		'	JJ0C0C,CD 	 	
 
00&2M2MN	N			JJKKKK!^^*** 	 	
 
,,	,			JJKK  !^^*** 	 	
 &''r3   c           	         | j                   dk(  rct        j                  | j                  | j                  | j
                  | j                  | j                  | j                  | j                         y | j                   dk(  rct        j                  | j                  | j                  | j
                  | j                  | j                  | j                  | j                         y t               )Nr   )	input_dirout_fileto_name	from_nameout_typeimage_root_url	image_extr   )
input_filerc   rd   re   rf   rg   point_width)r8   r=   convert_yolo_to_lsr   r   rd   re   rf   rg   rh   r>   convert_coco_to_lsrj   r   r_   s    r   importsrn      s    V#&&jj[[LLnn]]..nn	
 
		v	%&&zz[[LLnn]]..((	
 &''r3   c                      t               } | j                  dk(  rt        |        y | j                  dk(  rt        |        y t	        d       y )Nr6   r7   z0Please, use "import" or "export" or "-h" command)rC   r5   r6   rn   printrm   s    r   mainrq      s8    >D||xt		!@Ar3   __main__)r9   loggingr)   $label_studio_sdk.converter.converterr   r   r   &label_studio_sdk.converter.exports.csvr   "label_studio_sdk.converter.importsr   r=   r   r>    label_studio_sdk.converter.utilsr	   basicConfigINFOr2   rC   r6   rn   rq   __name__ r3   r   <module>r|      si      	 
 ? W ;   ',, 'FR0F(R(4B zF r3   