Team Ai
Apppublic

huggingface/Model_Cards_Writing_Tool

sourceHugging Facemitupdated 2y agoView on Hugging Face
125likes
specific_extraction.cpython-39.pyc79 linesDownload Raw Back to __pycache__
1a

2Ye7cG�@shddlZddlZddlmZmZddlmZmZm	Z	dd�Z3e4�ZeZe�dej
�Ze�dej�Ze�dej�Ze�d	ej�Ze�d5ej�Ze�dej�Ze�dej�Ze�d
ej�Ze�dej�Ze�dej�Zejdejd�Ze�dej�Ze�dej�ZiZeee<eee<eee<dd�Zdd�Zdd�Zdd�Z dd�Z!dd�Z"d d!�Z#d"d#�Z$d$d%�Z%ee�Z&e&gk�r�e&d&�'�d&Z(e)d'�ee(d�Zne)d(�e%e�Z*e)d)�e*dZ+e*d*Z,e*d+Z-e*d,Z.e#e�Z/e)d-�e!e�Z0e)d.�e"e�Z1e)d/�e e�Z2e)d0�ee�Z3e)d1�ee�Z4e)d2�e$e�Z5e)d3�d4Z6d5Z7d6Z8d7Z9d8Z:d9Z;d:Z<d;d<�Z=e=e&d=�Z>e=e+d>�Z?e=e,d?�Z@e=e-d@�ZAe=e.dA�ZBe=e1e7�ZCe=e/e6�ZDe=e0e9�ZEe=e2e:�ZFe=e3e;�ZGe=e4e<�ZHe=e5e8�ZIiZJe?eJdB<e@eJdC<eAeJdD<eBeJdE<eDeJe6<eCeJe7<eFeJe:<eEeJe9<eGeJe;<eHeJe<<eIeJe8<dFdG�ZKeKeJ�\ZLZMeLdddk�r�e)dH�e)dI�e)edeLdd��eNeOeL�d*�D]�ZPeLePd*ZQeLePd*dZReReQd*k�r�eLePZSeLePd*ZTeeSd*eTd�ZUeU�V��r�e)dJ�e)eS�e)dK�e)eT�e)eU��q�dLdM�ZWdNdO�ZXdPdQ�ZYdRdS�ZZdTdU�Z[dVdW�Z\e]dXk�rdeY�dS)Y�N)�CardData�	ModelCard)�tag_checker�listToString�to_markdowncCstjj}|S�N)�st�
session_state�markdown_upload)�6bytes_data�r�T/Users/ezi/Desktop/HF/Prompt_writing/ModelCard_Prompt_Writing/specific_extraction.py�file_uploadsrz^---(.*?)---z7^\s*# (.*)z^\s*## (.*)z^\s*### (.*)z
^\s*#### (.*)z!^\s*([*_]{2}[^*_]+[*_]{2})([^8]*)z^\s*[-*+]\s+.*z^\s*[0-9].*z^\s*\|.*z^\s*[A-Za-z(](.*)z^[_*][^_*\s].*9?.*[^_*][_*]$)�flagsz^\s*<.*z
!\[.*\]\(.*\)cCstt�|��Sr)�list�metadata_re�finditer��section_textrrr
�get_metadata;srcCstt�|��Sr)r�image_rerrrrr
�find_images?srcCstt�|��Sr)r�tag_rerrrrr
�	find_tagsCsrcCstt�|��Sr)r�table_rerrrrr
�find_tablesGsrcCstt�|��Sr)r�enum_rerrrrr
�10find_enumsKsrcCstt�|��Sr)r�key_value_rerrrrr
�find_key_valuesPsrcCstt�|��Sr)r�list_item_rerrrrr
�11find_listsTsr!cCs(tt�|��}tt�|��}||}|Sr)r�text_item_rer�italicized_text_item_re)rZ12basic_textZ	ital_textZ	free_textrrr
�13find_textsYsr$cCsDtt�|��}tt�|��}tt�|��}tt�|��}||||fSr)r�	header_rer�subheader_re�subsubheader_re�subsubsubheader_re)Z	full_text�headers�14subheaders�
subsubheaders�subsubsubheadersrrr
�find_headersas15r-�����zMetadata extractedzNo metadata foundzHeaders extracted���zBulleted lists extractedzEnumerated lists extractedzKey values extractedzTables extractedzMarkup tags extractedzImages extractedzFree text extractedz	List itemz16Key: Valuez	Free textz	Enum itemz17Table itemz18Markup tag�ImagecCs:i}|D],}t|�����dkr|��|f||��<q|S)z�19    Creates a dictionary made out of all the spans.20    This is useful for knowing which types to fill out with what in the app.21    Also useful for checking if there are spans in the .md file that we've missed.22    r)�len�group�strip�span)�23match_list�24match_type�	span_dict�matchrrr
�create_span_dict�s25r;�Metadata�# Header�## Subheader�### Subsubheader�#### Subsubsubheaderr)r*r+r,cCs,i}|��D]}|�|�qt|�}||fSr)�values�update�sorted)Z26spans_dict�merged_spansr9�sorted_spansrrr
�get_sorted_spans�s27rFz4FYI, our spans don't start at the start of the file.zWe did not catch this start:z#Found an unparsed span in the file:z ---> cCsDddddddddd	d28ddd
dd�}|D]}||kr&||�Sq&dS)NzQGive an overview of your model, the relevant research paper, who trained it, etc.z5Give an overview of how to get started with the modelz`Provide an overview of the possible Limitations and Risks that may be associated with this modelzLDetail the potential uses, intended use and out-of-scope uses for this modelzNProvide an overview of the Training Data and Training Procedure for this modelz,Detail the Evaluation Results for this modelz�Provide an estimate for the carbon emissions: Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here.z"How to best cite the model authorszuIf relevant, include terms and calculations in this section that can help readers understand the model or model card.zAny additional informationz�This section provides another layer of transparency and accountability. Whose views is this model card representing? How many voices were included in its construction? Etc.z6Mediums to use, in order to contact the model creatorsz! Additional technical informationz Examining the model)�## Model Details�$## How to Get Started with the Model�## Limitations and Biases�## Uses�## Training�## Evaluation Results�## Environmental Impact�## Citation Information�## Glossary�## More Information�## Model Card AuthorszModel Card Contactz##  Technical Specifications�## Model Examinationr�Ztext_retrievedZ
presit_states�keyrrr
�section_map_to_help_text�s$�rUcCsDddddddddd	d29ddd
dd�}|D]}|||kr&|Sq&dS)NrGrHrIrJrKrLrMrNrOrPrQz## Model Card Contact�## Technical specificationsrR��Model_details_text�Model_how_to�Model_Limits_n_Risks�30Model_uses�Model_training�31Model_Eval�Model_carbon�32Model_cite�Glossary�	More_info�Model_card_authors�Model_card_contactZTechnical_specs�Model_examinrrSrrr
�section_map_to_persists$�recCsttd��dS)NrX)�print�33extract_itrrrr
�mainsrhcCs<i}i}i}i}d}tD�]}t|ddkrbt�|�|df||<t�|�|d|d|df}t|ddkr�t�|�|df||<|dt�|�|d|df}t|ddkr�t�|�|df||<|d|dt�|�|df}t|dd	krt�|�|df||<|d|d|dt�|�f}q||||fS)34N)NNNNr/r=rr0r1r>r?r@)rErD�index)r)r*r+r,�previous�srrr
�extract_headers"s&35 rlcCs`t�\}}}}i}i}i}i}d}|D]�}	||	ddkr<q&t||	d||	d�}36g}|37D]}|�t|d�q`z|d}
Wnd}
Yn0d�|�}|||
�dd��dd��dd��dd��d	d��d38d�<|	}q&d}|D]�}	||	ddkr�q�t||	d||	d�}39g}|40D]V}t|ddk�rH|dk�rH�qxn,t|ddk�rb�qxn|�t|d��q z|d}
Wnd}
Yn0d�|�}|||
�dd��dd��dd�<|	}q�d}|D]�}	||	ddk�r�q�t||	d||	d�}41g}|42D]N}t|ddk�s>t|dd
k�rF|dk�rF�q\n|�t|d��qd�|�}||t|	d�dd��dd��dd�<|	}�q�|D]�}	||	ddk�r��q�t||	d||	d�}43g}|44D]D}t|ddk�st|dd
k�r�qn|�t|d��q�d�|�}||t|	d�dd��dd��dd�<�q�||||fS)Nr/rz
Model Details�z45# z    z  �46z{{z}}r>r=r?z### z#### z**)rlrE�appendrD�join�replace)r)r*r+r,�headers_strings�subheaders_strings�subsubheaders_strings�subsubsubheaders_strings�first�iZ	sub_spans�lines�x�namerrr
�	stringify:s�4748 49�������5051����52�"���53�"��r{cCs�td�td�d}d}d}d}t�\}}}}t|���}	t|���}54t|���}t|���}gd�}
ddddddddddddd�}|
D]�}|	D]$}||��vr�||||||<q�|55D]$}||��vr�||||||<q�|D]<}z&||��v�r||||||<Wq�Yq�Yq�0q�|D]@}z&||��v�rN||||||<WnY�q&Yn0�q&q�|d|d|d	|d56|d|d|d
|d|d|d|d|dddd�}||d}|S)NzSpan		Type		Textz%-------------------------------------F� )�
model details�howto�limitations�uses�training�57evaluation�
environmental�citation�glossary�more information�authors�contactrmr}r~rr�r�r�r�r�r�r�r�r�rVrRrW)rfr{r�keys�lower)Ztext_to_retrieveZfound_subheaderZcurrent_subheader�58page_state�	help_textrrrsrtruZh_keysZsh_keysZssh_keysZ	sssh_keys�neededZinfo_stringsry�lrw�z�yZextracted_info�new_trrr
rg�s����rg�__main__)^�re�	streamlitr�59modelcardsrr�markdownTagExtractrrrrZ
model_card_md�compile�DOTALLr�	MULTILINEr%r&r'r(rr rrr"r#rrZsubheader_re_dictrrrrrrr!r$r-Z
metadata_listr6Zmetadata_endrfZheaders_listr)r*r+r,Z60lists_listZ61enums_listZkey_value_listZtables_listZ	tags_listZimages_listZ62texts_listZ	LIST_ITEMZ	KEY_VALUEZ	FREE_TEXTZENUM_LIST_ITEMZ63TABLE_ITEMZTAG_ITEMZ64IMAGE_ITEMr;Zmetadata_span_dictZheader_span_dictZsubheader_span_dictZsubsubheader_span_dictZsubsubsubheader_span_dictZkey_value_span_dictZlists_span_dictZenums_span_dictZtables_span_dictZtags_span_dictZimages_span_dictZtexts_span_dictZall_spans_dictrFrErD�ranger3�idxZ
last_span_endZnew_span_startZstart_nonparseZend_nonparse�textr5rUrerhrlr{rg�__name__rrrr
�<module>s��65
66676869707172737475767778hl79