
    j              
           d dl Zd dlZd dlmZ d dlmZ d dlm	Z	 d dl
mZ  ed          dedej        fd	            Z ed          	 ddedededefd            ZdS )    N)Image)convert_pdf_to_images)get_table_tokens)requires_dependenciesunstructured_inferencefilenamereturnc                 T   ddl m}m}  |             |                     d          r6t	          t          |                     d                             d          }n't          j        |                               d          }|	                    |t          |          d          S )zhelper to JUST run table transformer on the input image/pdf file. It assumes the input is
    JUST a table. This is intended to facilitate metric tracking on table structure detection ALONE
    without mixing metric of element detection modelr   )
load_agenttables_agentz.pdfRGB	dataframe)
ocr_tokensresult_format)$unstructured_inference.models.tablesr   r   endswithlistr   convertr   openrun_predictionr   )r   r   r   images       n/lsinfo/ai/hellotax_ai/base_platform/venv/lib/python3.11/site-packages/unstructured/metrics/table_structure.pyimage_or_pdf_to_dataframer   
   s    
 NMMMMMMMJLLL   4*84455a8@@GG
8$$,,U33&&*511 '       token_ratiotrue_table_filename	eval_funcc           	         ddl m} t          |                               d                              t
          j        d          }t          j        |          	                    t                                        d                              t
          j        d          }t          j        t           ||||                                                              }|                                dz  S )zsevaluate the predicted table structure vs. actual table structure by column and row as a
    number between 0 and 1r   )compare_contents_as_df )r   g      Y@)"unstructured_inference.models.evalr   r   fillnareplacenpnanpdread_csvastypestrarrayr   valuesmean)r   r   r   r   
pred_tableactual_tableresultss          r   eval_table_transformer_for_filer0      s     JIIIII*844;;B??GGPRSSJ;233::3??FFrJJRRSUSY[]^^Lh##L*	RRRYY[[\\ G <<>>E!!r   )r   )numpyr$   pandasr&   PILr   unstructured.partition.pdfr   $unstructured.partition.pdf_image.ocrr   unstructured.utilsr   r)   	DataFramer   floatr0    r   r   <module>r:      s                 < < < < < < A A A A A A 4 4 4 4 4 4 /00     10$ /00 #" """ " 	" " " 10" " "r   