CoolFace
Apppublic

cs23-namitha/Ai-Writer

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes
utils.cpython-311.pyc29 linesDownload Raw Back to __pycache__
12��ph���^�ddlZddlmZddlZddlmZddlZddlZd�Z	d�Z3d�Zd4d�Zd	�Z
dS)�N)�Document)�CountVectorizerc�*�tj|��S�N)�textstat�flesch_reading_ease��texts �@C:\Users\ardha\OneDrive\Desktop\ai_writer_pro_streamlit\utils.py�get_readabilityrs���'��-�-�-�c�D�t|�����Sr)�len�splitr	s r�get_word_countrs���t�z�z�|�|���r
c��d}|dkrQtj|��5}|jD]}||���pdz
}�	ddd��n#1swxYwYn~|dkr4t	|��}d�d�|jD����}nD|dkr>t|dd�	��5}|���}ddd��n#1swxYwY|S)5N�z.pdfz.docx�6c��g|]	}|j��7S�r	)�.0�ps  r�8<listcomp>z*extract_text_from_file.<locals>.<listcomp>s��9�9�9�Q�!�&�9�9�9r
z.txt�rzutf-8)�encoding)�9pdfplumber�open�pages�extract_textr�join�10paragraphs�read)�	file_path�extr11�pdf�page�doc�fs       r�extract_text_from_filer)sm��
�D�12�f�}�	�
�_�Y�
'�
'�	2�3��	�
2�
2����)�)�+�+�1�r�1���
2�	2�	2�	2�	2�	2�	2�	2�	2�	2�	2�	2����	2�	2�	2�	2��13
�����y�!�!���y�y�9�9�#�.�9�9�9�:�:���	����
�)�S�7�
3�
3�
3�	�q��6�6�8�8�D�	�	�	�	�	�	�	�	�	�	�	����	�	�	�	��Ks#�$A�A�A�,C
�
C�C�c�f�tdd���}|�|g��}tj|�d��������}tj|�����|���ddd�}|d|�S)N�englishi�)�14stop_words�max_featuresr)�axis�����)r�
fit_transform�np�array�sum�flatten�get_feature_names_out�argsort)r15�top_n�vec�X�	word_freq�keywordss      r�extract_keywordsr=s���16�Y�T�17B�18B�19B�C����4�&�!�!�A������A����'�'�/�/�1�1�I��x��1�1�3�3�4�4�Y�5F�5F�5H�5H���2��5N�O�H��F�U�F��r
c�z�tjd|��}g}g}t|��D]l\}}|�|�����t|��dks|t|��dz20kr|�|��g}�md}t|��D]�\}}|s�|d}d�|���D��}	|	rd|	d����d�}21nd	|dz��}22|d23|24�d�z
}|D]}|d|�d
���d�z
}���|���S)Nz
(?<=[.!?])\s+��rrc�8�g|]}t|��dk�|��S)r?)r)r�ws  rrz)format_as_study_notes.<locals>.<listcomp>3s'��I�I�I�q�c�!�f�f�q�j�I��I�I�Ir
u🧠 z	 Insightsu🧠 Topic z25 26### z27 28z- �.r)�rer�	enumerate�append�stripr�29capitalize�rstrip)�summary_text�	sentences�chunks�
current_chunk�i�sentence�output�chunk�heading_source�
heading_words�headings           r�format_as_study_notesrU#s�����)�<�8�8�I�
�F��M� ��+�+�����8����X�^�^�-�-�.�.�.��}����"�	�a�3�y�>�>�A�+=�&=�	��M�M�-�(�(�(��M��
�F��f�%�%�4�4���5��	���q���I�I�N�$8�$8�$:�$:�I�I�I�
��	*�F�m�A�.�9�9�;�;�F�F�F�G�G�)�A�a�C�)�)�G��*�W�*�*�*�*���	4�	4�H��3�8�?�?�3�/�/�3�3�3�3�F�F�	4��<�<�>�>�r
)r*)r�docxrr�sklearn.feature_extraction.textr�numpyr2rDrrr)r=rUrr
r�<module>rYs�����������������;�;�;�;�;�;�����	�	�	�	�.�.�.���������������r