CoolFace
Apppublic

Dwild/ChuanhuChatGPT

sourceHugging Facegpl-3.0updated 3y agoView on Hugging Face
0likes
pdf_func.cpython-39.pyc69 linesDownload Raw Back to __pycache__
1a

2�&d��@s�ddlmZddlZddlZddlmZdd�Zdd�Zdd	�Zd3d�Z	dd
d�Z4ddd�ZdZdZ
dZdZedkr�ed�Zeed�eed�dS)���SimpleNamespaceN)�Documentcs4|j}|j|j��fdd�}|�}dd||dd�S)uuPrepare table查找边界, 要求page为原始page5    6    From https://github.com/jsvine/pdfplumber/issues/2427    cs"g}�D]}|tj�|�7}q|S)z3See https://github.com/jsvine/pdfplumber/issues/127)�8pdfplumber�utilsZ
rect_to_edges)�edges�c��cs��I/Users/treediagram/Documents/Developer/ChuanhuChatGPT/modules/pdf_func.py�curves_to_edges
sz-prepare_table_config.<locals>.curves_to_edges�explicit�9)Zvertical_strategyZhorizontal_strategy�explicit_vertical_lines�explicit_horizontal_linesZintersection_y_tolerance)�	root_page�curvesr)�	crop_page�pager
rrr	r�prepare_table_configs�rcsZt|�}t|d�dks(t|d�dkr,|Sdd�|jj|d�D���fdd�}|�|�S)	NrrrcSsg|]10}|j�qSr)�bbox)�.0�tablerrr�11<listcomp>"�z*get_text_outside_table.<locals>.<listcomp>)Ztable_settingscs$�fdd��t�fdd��D��S)z2Check if the object is in any of the table's bbox.csT�d�dd}�d�dd}|\}}}}||koR||koR||koR||kS)zMSee https://github.com/jsvine/pdfplumber/blob/stable/pdfplumber/table.py#L404�top�bottom��x0�x1r)�_bboxZv_midZh_midrrr r��objrr�obj_in_bbox%szFget_text_outside_table.<locals>.not_within_bboxes.<locals>.obj_in_bboxc3s|]}�|�VqdS)Nr)rZ__bbox)r$rr�	<genexpr>+rzDget_text_outside_table.<locals>.not_within_bboxes.<locals>.<genexpr>)�anyr"��bboxes)r#r$r�not_within_bboxes#sz1get_text_outside_table.<locals>.not_within_bboxes)r�lenr�find_tables�filter)r�tsr)rr'r�get_text_outside_tables 12r.cCs|jdddgd�d�S)NTr�)�fontname�size�object_type)Zkeep_blank_charsZy_toleranceZx_toleranceZextra_attrs)�
extract_words)rrrr�<lambda>0rr4c	Cs�g}|j\}}}}t|�D]@}tfi|��}|jdkrJ|�|j�|j}q|jdkr|j}qdd�t|�||||f��D�}|||�||||f�fS)N�ZAbstractcSsg|]}|d�qS)�textr)r�irrrr@rz/get_title_with_cropped_page.<locals>.<listcomp>)	rr3rr1�appendr6rr�within_bbox)	�13first_page�titlerrr r�wordZtitle_bottom�	user_inforrr�get_title_with_cropped_page3s1415 r>TcCstg}|D]f}|rd|jdd|jd|jfdd�}|j|jdd|j|jfdd�}|�|�|�|�q|�|�q|S)NrrT)�relative)r9�width�heightr8)�pages�16two_column�	new_pagesr�left�rightrrr�get_column_cropped_pagesDs 17rGcCsDt��j}|t�d�kr&t���d�t�|���r}t|jd�\}}}t	|g|jdd�|�}g}dd�}	d}18t19|�D]�\}}t|�}t|�D]�}
t
fi|
��}
|
jdk�r"|20dur�|	|j|
j|
j�}21nF|22jr�|23j|24jk�r|25j|26jk�r|j|27_|�|28�|	|j|
j|
j�}29|30j�|
j�q�d|31_|32j�|
j�q�qz|j|33_|�|34�|D]D}t�d	|j�d35|j|jf�dt|j����t�d�|j���qPWd�n1�s�0Yd�|�}d�|�}d
|�d|�d�}t36|�D]@\}}d�|j�|_|d|�d|j�d�d�|j�d7}�q�t���|�t|d|id�S)N�DEBUG�INFOrr/c	Sstg||d|dgd�S)NT)�name�name_top�name_bottom�record_chapter_name�37page_start�	page_stopr6r)rNrKrLrrrr4\s�zparse_pdf.<locals>.<lambda>�Fz	section: z pages:z word-count:� zArticle Title: z, Information:�38zThe zth Chapter z: r;)r6�39extra_info)�logging�	getLogger�level�getLevelName�setLevelr�openr>rBrG�	enumerater.r3rr1�page_numberrrrMrLrKrOr8rJr6�inforNr*�debug�joinr)�filenamerCrV�pdfr;r=r:rDZchaptersZcreate_chapterZcur_chapter�idxrr<r7r6Zchapterrrr�	parse_pdfQsH40"4142,64344,rba*451. Who are the authors?462. What is the process of the proposed method?473. What is the performance of the proposed method? Please note down its performance metrics.484. What are the baseline models and their performances? Please note down these baseline methods.495. What dataset did this paper use?50a51You are a researcher helper bot. You can help the user with research paper reading and summarizing. 52 53Now I am going to send you a paper. You need to read it and summarize it for me part by part. 54 55When you are reading, You need to focus on these key points:{}56a�57You are a researcher helper bot. You can help the user with research paper reading and summarizing. 58 59Now I am going to send you a paper. You need to read it and summarize it for me part by part. 60 61When you are reading, You need to focus on these key points:{},62 63And You need to generate a brief but informative title for this part.64Your return format:65- title: '...'66- summary: '...'67zXYou are a researcher helper bot. Now you need to read the summaries of a research paper.�__main__z./build/test.pdfr=r;)T)T)�typesrrrT�llama_indexrrr.r3r>rGrbZBASE_POINTSZREADING_PROMPTZREADING_PROMT_V2�SUMMARY_PROMPT�__name__�z�printrrrr�<module>s"68
69C