
    =pjv~                        S SK r S SKrS SKrS SKrS SKJr  S SKJr  S SKJ	r	J
r
JrJrJrJr  S SKrS SKrS SKJr  SSKJr  SS	KJrJrJrJrJrJrJrJrJ r    " S
 S5      r! " S S5      r" " S S5      r#S r$ " S S5      r% " S S5      r& " S S5      r' " S S5      r( " S S5      r) " S S5      r* " S S5      r+ " S S 5      r, " S! S"5      r-g)#    N)abstractmethod)Path)AnyCallableDictListOptionalUnion)Image   )logging   )	AudioWriter	CSVWriter
HtmlWriterImageWriter
JsonWriterMarkdownWriter
TextWriterVideoWriter
XlsxWriterc                   x    \ rS rSrSrS\S\4S jr\S\	\
\4   4S j5       r\S\	\
\4   4S j5       rSS
 jrSrg	)	WordMixin)   z:
Mixin class for adding Word (.docx) export capabilities.
argskwargsc                 N    U R                   R                  U R                  5        g N)_save_funcsappendsave_to_wordselfr   r   s      a/var/www/html/pdf-tiff/venv/lib/python3.13/site-packages/paddlex/inference/common/result/mixin.py__init__WordMixin.__init__.   s     1 12    returnc                     [         ez
Convert the result to a Word-compatible format.

Returns:
    Dict[str, Any]: A dictionary containing Word-compatible blocks and image data.
NotImplementedErrorr#   s    r$   _to_wordWordMixin._to_word1   
     "!r'   c                 "    U R                  5       $ r*   )r.   r-   s    r$   wordWordMixin.word;        }}r'   Nc           	      ^   SSK JnJn  [        U R	                  5       5      n[        U5      nXR
                   S3-  nU R                  5       nU" US   U5      n	UR                  US   U	UR                  SS5      UR                  SS	5      S
9n
U
R                  UR                  5       5        g)z Save the result to a .docx file.   )WordConvertersave_imagesz.docximagesword_blocksoriginal_image_widthi  original_image_heightr   )abs_image_pathsr;   r<   N)	converterr7   r8   r   _get_input_fnstemr.   convertgetsaveas_posix)r#   	save_pathr   r   r7   r8   fn	save_file	word_datar=   docs              r$   r!   WordMixin.save_to_wordE   s    9$$$&'O	77)5 11	MMO	%i&99E##m$+!*/Es!K"+--0G"K	 $ 
 	##%&r'    r(   N)__name__
__module____qualname____firstlineno____doc__listdictr%   r   r   strr   r.   propertyr2   r!   __static_attributes__rK   r'   r$   r   r   )   se    3d 3d 3 "$sCx. " " d38n  'r'   r   c                   t    \ rS rSrS\S\4S jr\S\\	\
4   4S j5       r\S\\	\
4   4S j5       rSS	 jrS
rg)
LatexMixinX   r   r   c                 N    U R                   R                  U R                  5        g r   )r   r    save_to_latexr"   s      r$   r%   LatexMixin.__init__Y   s     2 23r'   r(   c                     [         e)z
Convert the result to a LaTeX-compatible format.

Returns:
    Dict[str, Any]: A dictionary containing LaTeX-compatible blocks and image data.
r+   r-   s    r$   	_to_latexLatexMixin._to_latex\   r0   r'   c                 "    U R                  5       $ )zProperty to access the LaTeX-compatible data.

Returns:
    Dict[str, Any]: A dictionary containing LaTeX-compatible blocks and image data.
)r^   r-   s    r$   latexLatexMixin.latexf        ~~r'   Nc                 d   SSK JnJn  [        U R	                  5       5      n[        U5      nXR
                   S3-  nU R                  5       nU" US   U5      n	UR                  US   U	S9n
[        UR                  5       SSS	9 nUR                  U
5        S
S
S
5        g
! , (       d  f       g
= f)zSave the result to a .tex file.r6   )LatexConverterr8   z.texr9   latex_blocks)r=   wzutf-8)encodingN)r>   re   r8   r   r?   r@   r^   rA   openrD   write)r#   rE   r   r   re   r8   rF   rG   
latex_datar=   ra   fs               r$   r[   LatexMixin.save_to_latexo   s    :$$$&'O	77)4 00	^^%
%j&:IF&&~&+ ' 

 )$$&g>!GGEN ?>>s   B!!
B/rK   rL   )rM   rN   rO   rP   rR   rS   r%   r   r   rT   r   r^   rU   ra   r[   rV   rK   r'   r$   rX   rX   X   s`    4d 4d 4 "4S> " "  tCH~    r'   rX   c                   J    \ rS rSrSr\S\\\4   4S j5       rS rS	S jr	Sr
g)
StrMixin   z6Mixin class for adding string conversion capabilities.r(   c                 "    U R                  5       $ )zProperty to get the string representation of the result.

Returns:
    Dict[str, str]: The string representation of the result.
)_to_strr-   s    r$   rT   StrMixin.str   s     ||~r'   c                 
    SU 0$ )a  Convert the given result data to a string representation.

Args:
    json_format (bool): If True, return a JSON formatted string. Default is False.
    indent (int): Number of spaces to indent for JSON formatting. Default is 4.
    ensure_ascii (bool): If True, ensure all characters are ASCII. Default is False.

Returns:
    Dict[str, str]: The string representation of the result.
resrK   r-   s    r$   rr   StrMixin._to_str   s     t}r'   Nc                 L    [         R                  " U R                  5       5        g)z.Print the string representation of the result.N)r   inforr   r-   s    r$   printStrMixin.print   s    T\\^$r'   rK   rL   )rM   rN   rO   rP   rQ   rU   r   rT   rr   ry   rV   rK   r'   r$   ro   ro      s0    @T#s(^  %r'   ro   c           
      x   [        U [        R                  [        R                  45      (       a  [	        U 5      $ [        U [        R
                  [        R                  45      (       a  [        U 5      $ [        U [        R                  5      (       a*  U R                  5        Vs/ s H  n[        U5      PM     sn$ [        U [        R                  5      (       a$  [        R                  " U R                  SSS95      $ [        U [         5      (       a  U R#                  5       $ [        U [$        5      (       a8  [%        U R'                  5        VVs0 s H  u  p#U[        U5      _M     snn5      $ [        U [(        [*        45      (       a  U  Vs/ s H  n[        U5      PM     sn$ U $ s  snf s  snnf s  snf )zHelper function to format data into a JSON-serializable format.

Args:
    obj: The object to be formatted.

Returns:
    Any: The formatted object.
recordsF)orientforce_ascii)
isinstancenpfloat32float64floatint32int64intndarraytolist_format_datapd	DataFramejsonloadsto_jsonr   rD   rS   itemsrR   tuple)objitemkvis        r$   r   r      s7    #

BJJ/00Sz	C"((BHH-	.	.3x	C	$	$/2zz|<|tT"|<<	C	&	&zz#++YE+JKK	C		||~	C		CIIK@KDAQQ'K@AA	C$	'	'),-AQ--
 = A-s   &F,F1
F7c                       \ rS rSrSrSS jrS\\\\\4   4   4S jr	\
S\\\\\4   4   4S j5       r  SS\S	\S
\S\S\SS4S jjr   SS\S	\S
\4S jjr SS\S	\S
\SS4S jjrSrg)	JsonMixin   z7Mixin class for adding JSON serialization capabilities.r(   Nc                 l    [        5       U l        U R                  R                  U R                  5        g r   )r   _json_writerr   r    save_to_jsonr-   s    r$   r%   JsonMixin.__init__   s&    &L 1 12r'   c                 D    S[        [        R                  " U 5      5      0$ )zConvert the object to a JSON-serializable format.

Returns:
    Dict[str, Dict[str, Any]]: A dictionary representation of the object that is JSON-serializable.
ru   )r   copydeepcopyr-   s    r$   _to_jsonJsonMixin._to_json   s     |DMM$$7899r'   c                 "    U R                  5       $ )zProperty to get the JSON representation of the result.

Returns:
    Dict[str, Dict[str, Any]]: The dict type JSON representation of the result.
)r   r-   s    r$   r   JsonMixin.json   r4   r'   rE   indentensure_asciir   r   c                    S nU R                  5       nU" U5      (       dx  [        U R                  5       5      nUR                  n	[        U5      n
U HA  nX SU S3-  nU R                  R
                  " UR                  5       X{   /UQ7UUS.UD6  MC     g	[        U5      S:  a  [        R                  " SU S35        U R                  R
                  " UU[        UR                  5       5      S      /UQ7UUS.UD6  g	)
a-  Save the JSON representation of the object to a file.

Args:
    save_path (str): The path to save the JSON file. If the save path does not end with '.json', it appends the base name and suffix of the input path.
    indent (int): The number of spaces to indent for pretty printing. Default is 4.
    ensure_ascii (bool): If False, non-ASCII characters will be included in the output. Default is False.
    *args: Additional positional arguments to pass to the underlying writer.
    **kwargs: Additional keyword arguments to pass to the underlying writer.
c                 R    [         R                  " U 5      u  pUS L=(       a    US:H  $ )Nzapplication/json	mimetypes
guess_type	file_path	mime_type_s      r$   _is_json_file-JsonMixin.save_to_json.<locals>._is_json_file   s*    $//	:LID(LY:L-LLr'   r   z.jsonr   r   r6   z`The result has multiple json files need to be saved. But the `save_path` has been specified as ``!r   N)r   r   r?   r@   r   rj   rD   lenr   warningrR   keys)r#   rE   r   r   r   r   r   	json_datarF   r@   base_save_pathkeys               r$   r   JsonMixin.save_to_json   s5   $	M MMO	Y''d((*+B77D!)_N *vQse5-AA	!!''&&(N
  "!-	  ! 9~!v  xA  wB  BD  E ##$y~~/034
  )	 r'   json_formatc                 X    U(       a   [         R                  " [        SU 05      X#S9$ SU 0$ )a  Convert the given result data to a string representation.
Args:
    data (dict): The data would be converted to str.
    json_format (bool): If True, return a JSON formatted string. Default is False.
    indent (int): Number of spaces to indent for JSON formatting. Default is 4.
    ensure_ascii (bool): If True, ensure all characters are ASCII. Default is False.
Returns:
    Dict[str, str]: The string representation of the result.
ru   r   )r   dumpsr   )r#   r   r   r   s       r$   rr   JsonMixin._to_str  s2     ::eT]+F  4= r'   c                 P    U R                  XUS9n[        R                  " U5        g)a-  Print the string representation of the result.

Args:
    json_format (bool): If True, print a JSON formatted string. Default is False.
    indent (int): Number of spaces to indent for JSON formatting. Default is 4.
    ensure_ascii (bool): If True, ensure all characters are ASCII. Default is False.
)r   r   r   N)rr   r   rx   )r#   r   r   r   str_s        r$   ry   JsonMixin.print#  s*     ||#  
 	Tr'   )r   rL   )r   F)Fr   F)rM   rN   rO   rP   rQ   r%   r   rT   r   r   rU   r   r   boolr   r   rr   ry   rV   rK   r'   r$   r   r      s    A3:$sDcN23 : d3S#X./   "	33 3 	3
 3 3 
3n ""	!! ! 	!. PU14HL	 r'   r   c                       \ rS rSrSrS\S\SS4S jr\S\\	\	4   4S j5       r
\S\\	\	4   4S	 j5       rS
\	S\S\SS4S jrSrg)Base64Mixini3  z4Mixin class for adding Base64 encoding capabilities.r   r   r(   Nc                 n    [        U0 UD6U l        U R                  R                  U R                  5        g)zInitializes the Base64Mixin.

Args:
    *args: Positional arguments to pass to the TextWriter.
    **kwargs: Keyword arguments to pass to the TextWriter.
N)r   _base64_writerr   r    save_to_base64r"   s      r$   r%   Base64Mixin.__init__6  s0     )$9&9 3 34r'   c                     [         e)zzAbstract method to convert the result to Base64.

Returns:
    Dict[str, str]: The str type Base64 representation result.
r+   r-   s    r$   
_to_base64Base64Mixin._to_base64@  
     "!r'   c                 "    U R                  5       $ )zz
Property that returns the Base64 encoded content.

Returns:
    Dict[str, str]: The base64 representation of the result.
)r   r-   s    r$   base64Base64Mixin.base64I  s       r'   rE   c                 4   U R                  5       n[        U5      R                  5       R                  S5      (       du  [	        U R                  5       5      nUR                  n[	        U5      nU H>  nXv SU S3-  nU R                  R                  " UR                  5       XH   /UQ70 UD6  M@     g[        U5      S:  a  [        R                  " SU S35        U R                  R                  " X[        UR                  5       5      S      /UQ70 UD6  g)a  Saves the Base64 encoded content to the specified path.

Args:
    save_path (str): The path to save the base64 representation result. If the save path does not end with '.b64', it appends the base name and suffix of the input path.

    *args: Additional positional arguments that will be passed to the base64 writer.
    **kwargs: Additional keyword arguments that will be passed to the base64 writer.
z.b64r   r6   zbThe result has multiple base64 files need to be saved. But the `save_path` has been specified as `r   r   N)r   rT   lowerendswithr   r?   r@   r   rj   rD   r   r   r   rR   r   )	r#   rE   r   r   r   rF   r@   r   r   s	            r$   r   Base64Mixin.save_to_base64S  s    "9~##%..88d((*+B77D!)_N*vQse4-@@	##))&&(&+8<@F  6{Qx  zC  yD  DF  G %%$v{{}"5a"89<@DJr'   )r   )rM   rN   rO   rP   rQ   r   r   r%   r   rT   r   rU   r   r   rV   rK   r'   r$   r   r   3  s    >5d 5d 5t 5 "DcN " " !S#X ! ! D D T r'   r   c            	           \ rS rSrSrSS\S\S\SS4S jjr\	S\\\
R                  4   4S	 j5       r\S\\\
R                  4   4S
 j5       rS\S\S\SS4S jrSrg)ImgMixinip  z3Mixin class for adding image handling capabilities.backendr   r   r(   Nc                 r    [        USU0UD6U l        U R                  R                  U R                  5        g)zInitializes ImgMixin.

Args:
    backend (str): The backend to use for image processing. Defaults to "pillow".
    *args: Additional positional arguments to pass to the ImageWriter.
    **kwargs: Additional keyword arguments to pass to the ImageWriter.
r   N)r   _img_writerr   r    save_to_imgr#   r   r   r   s       r$   r%   ImgMixin.__init__s  s5     'HwHH 0 01r'   c                     [         e)zzAbstract method to convert the result to an image.

Returns:
    Dict[str, Image.Image]: The image representation result.
r+   r-   s    r$   _to_imgImgMixin._to_img~  r   r'   c                 "    U R                  5       $ )zProperty to get the image representation of the result.

Returns:
    Dict[str, Image.Image]: The image representation of the result.
)r   r-   s    r$   imgImgMixin.img       ||~r'   rE   c                 2   S nU R                  5       nU" U5      (       d  [        U R                  5       5      nU" U5      (       a  UR                  OSnUR                  n[        U5      n	U H?  n
X SU
 U 3-  nU R
                  R                  " UR                  5       XZ   /UQ70 UD6  MA     g[        U5      S:  a  [        R                  " SU S35        U R
                  R                  " X[        UR                  5       5      S      /UQ70 UD6  g)	a  Saves the image representation of the result to the specified path.

Args:
    save_path (str): The path to save the image. If the save path does not end with .jpg or .png, it appends the input path's stem and suffix to the save path.
    *args: Additional positional arguments that will be passed to the image writer.
    **kwargs: Additional keyword arguments that will be passed to the image writer.
c                 j    [         R                  " U 5      u  pUS L=(       a    UR                  S5      $ )Nzimage/r   r   
startswithr   s      r$   _is_image_file,ImgMixin.save_to_img.<locals>._is_image_file  /    $//	:LID(KY-A-A(-KKr'   z.pngr   r6   z_The result has multiple img files need to be saved. But the `save_path` has been specified as `r   r   N)r   r   r?   suffixr@   r   rj   rD   r   r   r   rR   r   )r#   rE   r   r   r   r   rF   r   r@   r   r   s              r$   r   ImgMixin.save_to_img  s   	L llni((d((*+B"0"4"4RYY&F77D!)_N*vQseF8-DD	  &&y'9'9';SXWWPVW  3x!|uv  vA  AC  D ""9$sxxz2B12E.FXXQWXr'   )r   )pillow)rM   rN   rO   rP   rQ   rT   r   r   r%   r   r   r   rU   r   r   rV   rK   r'   r$   r   r   p  s    =	2 	2t 	2t 	2PT 	2 "c5;;./ " " T#u{{*+  YS Y Y Y$ Yr'   r   c            	           \ rS rSrSrSS\S\S\SS4S jjr\	S\\\
R                  4   4S	 j5       r\S\\\
R                  4   4S
 j5       rS\S\S\SS4S jrSrg)CSVMixini  z1Mixin class for adding CSV handling capabilities.r   r   r   r(   Nc                     [        USU0UD6U l        [        U S5      (       d  / U l        U R                  R	                  U R
                  5        g)zInitializes the CSVMixin.

Args:
    backend (str): The backend to use for CSV operations (default is "pandas").
    *args: Optional positional arguments to pass to the CSVWriter.
    **kwargs: Optional keyword arguments to pass to the CSVWriter.
r   r   N)r   _csv_writerhasattrr   r    save_to_csvr   s       r$   r%   CSVMixin.__init__  sJ     %tFWFvFt]++!D 0 01r'   c                 "    U R                  5       $ )zProperty to get the pandas Dataframe representation of the result.

Returns:
    Dict[str, pd.DataFrame]: The pandas.DataFrame representation of the result.
)_to_csvr-   s    r$   csvCSVMixin.csv  r   r'   c                     [         e)zAbstract method to convert the result to pandas.DataFrame.

Returns:
    Dict[str, pd.DataFrame]: The pandas.DataFrame representation result.
r+   r-   s    r$   r   CSVMixin._to_csv  r   r'   rE   c                    S nU R                  5       nU" U5      (       du  [        U R                  5       5      nUR                  n[        U5      nU H>  n	X SU	 S3-  nU R                  R
                  " UR                  5       XY   /UQ70 UD6  M@     g[        U5      S:  a  [        R                  " SU S35        U R                  R
                  " X[        UR                  5       5      S      /UQ70 UD6  g)	a  Saves the result to a CSV file.

Args:
    save_path (str): The path to save the CSV file. If the path does not end with ".csv",
        the stem of the input path attribute (self['input_path']) will be used as the filename.
    *args: Optional positional arguments to pass to the CSV writer's write method.
    **kwargs: Optional keyword arguments to pass to the CSV writer's write method.
c                 R    [         R                  " U 5      u  pUS L=(       a    US:H  $ )Nztext/csvr   r   s      r$   _is_csv_file*CSVMixin.save_to_csv.<locals>._is_csv_file  s)    $//	:LID(DY*-DDr'   r   z.csvr6   z_The result has multiple csv files need to be saved. But the `save_path` has been specified as `r   r   N)r   r   r?   r@   r   rj   rD   r   r   r   rR   r   )
r#   rE   r   r   r   r   rF   r@   r   r   s
             r$   r   CSVMixin.save_to_csv  s    	E llnI&&d((*+B77D!)_N*vQse4-@@	  &&y'9'9';SXWWPVW  3x!|uv  vA  AC  D ""9$sxxz2B12E.FXXQWXr'   )r   r   )pandas)rM   rN   rO   rP   rQ   rT   r   r   r%   rU   r   r   r   r   r   r   rV   rK   r'   r$   r   r     s    ;2 2t 2t 2PT 2 T#r||+,   "c2<</0 " "YS Y Y Y$ Yr'   r   c                       \ rS rSrSrS\S\SS4S jr\S\\	\	4   4S j5       r
\S\\	\	4   4S	 j5       rS
\	S\S\SS4S jrSrg)	HtmlMixini  z2Mixin class for adding HTML handling capabilities.r   r   r(   Nc                 n    [        U0 UD6U l        U R                  R                  U R                  5        g)z
Initializes the HTML writer and appends the save_to_html method to the save functions list.

Args:
    *args: Positional arguments passed to the HtmlWriter.
    **kwargs: Keyword arguments passed to the HtmlWriter.
N)r   _html_writerr   r    save_to_htmlr"   s      r$   r%   HtmlMixin.__init__  s0     '77 1 12r'   c                 "    U R                  5       $ )zzProperty to get the HTML representation of the result.

Returns:
    str: The str type HTML representation of the result.
)_to_htmlr-   s    r$   htmlHtmlMixin.html       }}r'   c                     [         e)zAbstract method to convert the result to str type HTML representation.

Returns:
    Dict[str, str]: The str type HTML representation result.
r+   r-   s    r$   r  HtmlMixin._to_html  r   r'   rE   c                    S nU R                  5       nU" U5      (       du  [        U R                  5       5      nUR                  n[        U5      nU H>  n	X SU	 S3-  nU R                  R
                  " UR                  5       XY   /UQ70 UD6  M@     g[        U5      S:  a  [        R                  " SU S35        U R                  R
                  " X[        UR                  5       5      S      /UQ70 UD6  g)	zSaves the HTML representation of the object to the specified path.

Args:
    save_path (str): The path to save the HTML file.
    *args: Additional positional arguments.
    **kwargs: Additional keyword arguments.
c                 R    [         R                  " U 5      u  pUS L=(       a    US:H  $ )Nz	text/htmlr   r   s      r$   _is_html_file-HtmlMixin.save_to_html.<locals>._is_html_file  s)    $//	:LID(EY+-EEr'   r   z.htmlr6   z`The result has multiple html files need to be saved. But the `save_path` has been specified as `r   r   N)r  r   r?   r@   r  rj   rD   r   r   r   rR   r   )
r#   rE   r   r   r  r  rF   r@   r   r   s
             r$   r  HtmlMixin.save_to_html  s   	F }}Y''d((*+B77D!)_N*vQse5-AA	!!''&&($)6:>D  4y1}v  xA  wB  BD  E ##TYY[ 1! 458<@Fr'   )r  )rM   rN   rO   rP   rQ   r   r   r%   rU   rT   r  r   r  r  rV   rK   r'   r$   r   r     s    <	3d 	3d 	3t 	3 d38n   "$sCx. " "c $ $ 4 r'   r   c                       \ rS rSrSrS\S\SS4S jr\S\\	\	4   4S j5       r
\S\\	\	4   4S	 j5       rS
\	S\S\SS4S jrSrg)	XlsxMixini/  z2Mixin class for adding XLSX handling capabilities.r   r   r(   Nc                 n    [        U0 UD6U l        U R                  R                  U R                  5        g)zInitializes the XLSX writer and appends the save_to_xlsx method to the save functions.

Args:
    *args: Positional arguments to be passed to the XlsxWriter constructor.
    **kwargs: Keyword arguments to be passed to the XlsxWriter constructor.
N)r   _xlsx_writerr   r    save_to_xlsxr"   s      r$   r%   XlsxMixin.__init__2  s0     '77 1 12r'   c                 "    U R                  5       $ )zProperty to get the XLSX representation of the result.

Returns:
    Dict[str, str]: The str type XLSX representation of the result.
)_to_xlsxr-   s    r$   xlsxXlsxMixin.xlsx<  r	  r'   c                     [         e)zAbstract method to convert the result to str type XLSX representation.

Returns:
    Dict[str, str]: The str type HTML representation result.
r+   r-   s    r$   r  XlsxMixin._to_xlsxE  r   r'   rE   c                    S nU R                  5       nU" U5      (       du  [        U R                  5       5      nUR                  n[        U5      nU H>  n	X SU	 S3-  nU R                  R
                  " UR                  5       XY   /UQ70 UD6  M@     g[        U5      S:  a  [        R                  " SU S35        U R                  R
                  " X[        UR                  5       5      S      /UQ70 UD6  g)	a  Saves the HTML representation to an XLSX file.

Args:
    save_path (str): The path to save the XLSX file. If the path does not end with ".xlsx",
                     the filename will be set to the stem of the input path with ".xlsx" extension.
    *args: Additional positional arguments to pass to the XLSX writer.
    **kwargs: Additional keyword arguments to pass to the XLSX writer.
c                 R    [         R                  " U 5      u  pUS L=(       a    US:H  $ )NzAapplication/vnd.openxmlformats-officedocument.spreadsheetml.sheetr   r   s      r$   _is_xlsx_file-XlsxMixin.save_to_xlsx.<locals>._is_xlsx_fileX  s3    $//	:LI% WVWr'   r   z.xlsxr6   z`The result has multiple xlsx files need to be saved. But the `save_path` has been specified as `r   r   N)r  r   r?   r@   r  rj   rD   r   r   r   rR   r   )
r#   rE   r   r   r  r  rF   r@   r   r   s
             r$   r  XlsxMixin.save_to_xlsxN  s   	 }}Y''d((*+B77D!)_N*vQse5-AA	!!''&&($)6:>D  4y1}v  xA  wB  BD  E ##TYY[ 1! 458<@Fr'   )r  )rM   rN   rO   rP   rQ   r   r   r%   rU   rT   r  r   r  r  rV   rK   r'   r$   r  r  /  s    <3d 3d 3t 3 d38n   "$sCx. " "#c #$ #$ #4 #r'   r  c            	           \ rS rSrSrSS\S\S\SS4S jjr\	S\\\
R                  4   4S	 j5       r\S\\\
R                  4   4S
 j5       rS\S\S\SS4S jrSrg)
VideoMixinit  z3Mixin class for adding Video handling capabilities.r   r   r   r(   Nc                 Z    Xl         U R                  R                  U R                  5        g)zInitializes VideoMixin.

Args:
    backend (str): The backend to use for video processing. Defaults to "opencv".
    *args: Additional positional arguments to pass to the VideoWriter.
    **kwargs: Additional keyword arguments to pass to the VideoWriter.
N)_backendr   r    save_to_videor   s       r$   r%   VideoMixin.__init__w  s#       2 23r'   c                     [         e)zvAbstract method to convert the result to a video.

Returns:
    Dict[str, np.array]: The video representation result.
r+   r-   s    r$   	_to_videoVideoMixin._to_video  r   r'   c                 "    U R                  5       $ )zProperty to get the video representation of the result.

Returns:
    Dict[str, np.array]: The video representation of the result.
)r)  r-   s    r$   videoVideoMixin.video  rc   r'   rE   c                 8   S n[        USU R                  0UD6nU R                  5       nU" U5      (       d  [        U R	                  5       5      nUR
                  nU" U5      (       a  UR                  OSn	[        U5      n
U H5  nX SU U	 3-  nUR                  " UR                  5       Xk   /UQ70 UD6  M7     g	[        U5      S:  a  [        R                  " SU S35        UR                  " X[        UR                  5       5      S      /UQ70 UD6  g	)
a  Saves the video representation of the result to the specified path.

Args:
    save_path (str): The path to save the video. If the save path does not end with .mp4 or .avi, it appends the input path's stem and suffix to the save path.
    *args: Additional positional arguments that will be passed to the video writer.
    **kwargs: Additional keyword arguments that will be passed to the video writer.
c                 j    [         R                  " U 5      u  pUS L=(       a    UR                  S5      $ )Nzvideo/r   r   s      r$   _is_video_file0VideoMixin.save_to_video.<locals>._is_video_file  r   r'   r   z.mp4r   r6   zaThe result has multiple video files need to be saved. But the `save_path` has been specified as `r   r   N)r   r%  r)  r   r?   r@   r   rj   rD   r   r   r   rR   r   )r#   rE   r   r   r0  video_writerr,  rF   r@   r   r   r   s               r$   r&  VideoMixin.save_to_video  s    	L #4J4==J6J i((d((*+B77D"0"4"4RYY&F!)_N*vQseF8-DD	""9#5#5#7UdUfU  5zA~w  yB  xC  CE  F yUZZ\0B10E*FXXQWXr'   )r%  )opencv)rM   rN   rO   rP   rQ   rT   r   r   r%   r   r   arrayr)  rU   r,  r&  rV   rK   r'   r$   r#  r#  t  s    =	4 	4t 	4t 	4PT 	4 "4RXX. " "  tCM*    Ys Y4 Y4 YD Yr'   r#  c                       \ rS rSrSrS\S\SS4S jr\S\\	\
R                  4   4S j5       r\S\\	\
R                  4   4S	 j5       rS
\	S\S\SS4S jrSrg)
AudioMixini  z3Mixin class for adding Audio handling capabilities.r   r   r(   Nc                     Xl         U R                  R                  U R                  5        [	        USU R                   0UD6U l        g)zInitializes AudioMixin.

Args:
    *args: Additional positional arguments to pass to the AudioWriter.
    **kwargs: Additional keyword arguments to pass to the AudioWriter.
r   N)r%  r   r    save_to_audior   _audio_writerr   s       r$   r%   AudioMixin.__init__  s>       2 23(PPPr'   c                     [         e)zvAbstract method to convert the result to a audio.

Returns:
    Dict[str, np.array]: The audio representation result.
r+   r-   s    r$   	_to_audioAudioMixin._to_audio  r   r'   c                 "    U R                  5       $ )zProperty to get the audio representation of the result.

Returns:
    Dict[str, np.array]: The audio representation of the result.
)r=  r-   s    r$   audioAudioMixin.audio  rc   r'   rE   c                 2   S nU R                  5       nU" U5      (       d  [        U R                  5       5      nUR                  nU" U5      (       a  UR                  OSn[        U5      n	U H?  n
X SU
 U 3-  nU R
                  R                  " UR                  5       XZ   /UQ70 UD6  MA     g[        U5      S:  a  [        R                  " SU S35        U R
                  R                  " X[        UR                  5       5      S      /UQ70 UD6  g)	a  Saves the audio representation of the result to the specified path.

Args:
    save_path (str): The path to save the audio. If the save path does not end with .mp4 or .avi, it appends the input path's stem and suffix to the save path.
    *args: Additional positional arguments that will be passed to the audio writer.
    **kwargs: Additional keyword arguments that will be passed to the audio writer.
c                 j    [         R                  " U 5      u  pUS L=(       a    UR                  S5      $ )Nzaudio/r   r   s      r$   _is_audio_file0AudioMixin.save_to_audio.<locals>._is_audio_file  r   r'   z.wavr   r6   zaThe result has multiple audio files need to be saved. But the `save_path` has been specified as `r   r   N)r=  r   r?   r@   r   r:  rj   rD   r   r   r   rR   r   )r#   rE   r   r   rD  r@  rF   r@   r   r   r   s              r$   r9  AudioMixin.save_to_audio  s%   	L  i((d((*+B77D"0"4"4RYY&F!)_N*vQseF8-DD	""((&&(%*7;?E  5zA~w  yB  xC  CE  F $$ejjl!3A!67:>BHr'   )r:  r%  )rM   rN   rO   rP   rQ   r   r   r%   r   rT   r   r5  r=  rU   r@  r9  rV   rK   r'   r$   r7  r7    s    =	Qt 	Qt 	Q 	Q "4RXX. " "  tCM*    s 4 4 D r'   r7  c                       \ rS rSrSrS/rS\S\4S jr\	 SS\
\\\\
\\4   4   4   4S jj5       r\S\
\\\\
\\4   4   4   4S	 j5       r S SS jjrS\S\S\\\4   S\\
\\\\
\\4   4   4      SS
4
S jrSrg
)MarkdownMixini  z6Mixin class for adding Markdown handling capabilities.markdown_textsr   r   c                     [        U0 UD6U l        [        U0 UD6U l        U R                  R                  U R                  5        g)a  Initializes the Markdown writer and appends the save_to_markdown method to the save functions.

Args:
    *args: Positional arguments to be passed to the MarkdownWriter constructor.
    **kwargs: Keyword arguments to be passed to the MarkdownWriter constructor.
N)r   _markdown_writerr   r   r   r    save_to_markdownr"   s      r$   r%   MarkdownMixin.__init__  sB     !/ ? ?&77 5 56r'   r(   c                     [         e)z
Convert the result to markdown format.

Args:
    pretty (Optional[bool]): whether to pretty markdown by HTML, default by True.

Returns:
    Dict[str, Union[str, Dict[str, Any]]]: A dictionary containing markdown text and image data.
r+   )r#   prettyshow_formula_numbers      r$   _to_markdownMarkdownMixin._to_markdown  s
     "!r'   c                 "    U R                  5       $ )zProperty to access the markdown data.

Returns:
    Dict[str, Union[str, Dict[str, Any]]]: A dictionary containing markdown text and image data.
)rQ  r-   s    r$   markdownMarkdownMixin.markdown  s       ""r'   Nc           
         S[         4S jnU" U5      (       dZ  [        U R                  5       5      nU" U5      (       a  UR                  OSnUR                  n	[        U5      n
X U 3-  nXl        OXl        U R                  " U R                  R                  U R                  R                  U R
                  U R                  X#S9/UQ70 UD6  g)zSave the markdown data to a file.

Args:
    save_path (Union[str, Path]): The path where the markdown file will be saved.
    *args: Additional positional arguments for saving.
    **kwargs: Additional keyword arguments for saving.
r(   c                     1 Skn[         R                  R                  [        U 5      5      u  p#UR	                  5       U;   a  g[
        R                  " [        U 5      5      u  pBUS:H  $ )zCheck if a file is a markdown file based on its extension or MIME type.

Args:
    file_path (Union[str, Path]): The path to the file.

Returns:
    bool: True if the file is a markdown file, False otherwise.
>   .md.mkd.mdown	.markdownTztext/markdown)ospathsplitextrT   r   r   r   )r   markdown_extensionsr   extr   s        r$   _is_markdown_file9MarkdownMixin.save_to_markdown.<locals>._is_markdown_file(  sX     #IWW%%c)n5FAyy{11$//I?LI//r'   rX  )rO  rP  N)r   r   r?   r   r@   rE   
_save_datarK  rj   r   rQ  )r#   rE   rO  rP  r   r   ra  rF   r   r@   r   s              r$   rL  MarkdownMixin.save_to_markdown  s    	0D 	0  !++d((*+B"3B"7"7RYYUF77D!)_N&6&)::I&N&N!!''""NNVU		

 	
 	
r'   save_mkd_funcsave_img_funcrE   datac                 l   [        U5      nUc  gUR                  5        H  u  pxXpR                  ;   a  U" UR                  5       U/UQ70 UD6  [	        U[
        5      (       d  MF  UR                  n	UR                  5        H+  u  pU(       d  M  U" X-  R                  5       U/UQ70 UD6  M-     M     g)a  Internal method to save markdown and image data.

Args:
    save_mkd_func (Callable): Function to save markdown text.
    save_img_func (Callable): Function to save image data.
    save_path (Union[str, Path]): The base path where the data will be saved.
    data (Optional[Dict[str, Union[str, Dict[str, Any]]]]): The markdown data to save.
    *args: Additional positional arguments for saving.
    **kwargs: Additional keyword arguments for saving.
N)r   r   MARKDOWN_SAVE_KEYSrD   r   rS   parent)r#   re  rf  rE   rg  r   r   r   valuer   img_pathimg_datas               r$   rc  MarkdownMixin._save_dataJ  s    & O	<**,JC---i002EKDKFK%&&!*!1!1*/++-&Hx%+6@@B$ " %	 +8 'r'   )r   rK  rE   )TFrL   )rM   rN   rO   rP   rQ   ri  rR   rS   r%   r   r   rT   r
   r   rQ  rU   rT  rL  r   r   r	   rc  rV   rK   r'   r$   rH  rH    s   @*+	7d 	7d 	7 /4"	c5d38n,--	." " #$sE#tCH~*=$>>? # # ;@+
	+
Z""  " d#	"
 tCsDcN':!;;<=" 
"r'   rH  ).r   r   r   r\  abcr   pathlibr   typingr   r   r   r   r	   r
   numpyr   r   r   PILr   utilsr   utils.ior   r   r   r   r   r   r   r   r   r   rX   ro   r   r   r   r   r   r   r  r#  r7  rH  rK   r'   r$   <module>rv     s       	   = =    
 
 
,' ,'^' 'T% %B6r rj: :z;Y ;Y|=Y =Y@> >BB BJ<Y <Y~? ?Dw wr'   